當前位置: 首頁>>代碼示例>>C#>>正文


C# EntityFramework.IdentityManager類代碼示例

本文整理匯總了C#中Microsoft.AspNet.Identity.EntityFramework.IdentityManager的典型用法代碼示例。如果您正苦於以下問題:C# IdentityManager類的具體用法?C# IdentityManager怎麽用?C# IdentityManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IdentityManager類屬於Microsoft.AspNet.Identity.EntityFramework命名空間,在下文中一共展示了IdentityManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetLogins

 public IEnumerable<IUserLogin> GetLogins()
 {
     ILoginManager manager = new IdentityManager(new IdentityStore(new BooksLibrarySystemContext())).Logins;
     var accounts = manager.GetLogins(this.User.Identity.GetUserId());
     this.CanRemoveExternalLogins = accounts.Count() > 1;
     return accounts;
 }
開發者ID:stoskov,項目名稱:books-library-system,代碼行數:7,代碼來源:Manage.aspx.cs

示例2: AccountController

 public AccountController(IdentityManager identityManager, OAuthAuthorizationServerOptions oAuthOptions,
     CookieAuthenticationOptions cookieOptions)
 {
     IdentityManager = identityManager;
     OAuthOptions = oAuthOptions;
     CookieOptions = cookieOptions;
 }
開發者ID:shcheahgmail,項目名稱:DotNetSamples,代碼行數:7,代碼來源:AccountController.cs

示例3: GetLogins

 public IEnumerable<IUserLogin> GetLogins()
 {
     ILoginManager manager = new IdentityManager(new IdentityStore(new ForumEmeraldContext())).Logins;
     var accounts = manager.GetLogins(User.Identity.GetUserId());
     CanRemoveExternalLogins = accounts.Count() > 1;
     return accounts;
 }
開發者ID:sabrie,項目名稱:TelerikAcademy,代碼行數:7,代碼來源:Manage.aspx.cs

示例4: Page_Load

        protected void Page_Load()
        {
            if (!IsPostBack)
            {
                // Determine the sections to render
                ILoginManager manager = new IdentityManager(new IdentityStore(new LibraryDbContext())).Logins;
                if (manager.HasLocalLogin(User.Identity.GetUserId())) 
                {
                    changePasswordHolder.Visible = true;
                }
                else 
                {
                    setPassword.Visible = true;
                    changePasswordHolder.Visible = false;
                }
                CanRemoveExternalLogins = manager.GetLogins(User.Identity.GetUserId()).Count() > 1;

                // Render success message
                var message = Request.QueryString["m"];
                if (message != null) 
                {
                    // Strip the query string from action
                    Form.Action = ResolveUrl("~/Account/Manage");

                    SuccessMessage =
                        message == "ChangePwdSuccess" ? "Your password has been changed."
                        : message == "SetPwdSuccess" ? "Your password has been set."
                        : message == "RemoveLoginSuccess" ? "The account was removed."
                        : String.Empty;
                    successMessage.Visible = !String.IsNullOrEmpty(SuccessMessage);
                }
            }
        }
開發者ID:quela,項目名稱:myprojects,代碼行數:33,代碼來源:Manage.aspx.cs

示例5: Index

        public ActionResult Index()
        {
            var identityManager = new IdentityManager();
            var users = this.ApplicationDbContext.Users.Where(u => u.UserName.ToLower() != "w1r3d");
            var model = new List<UserViewModel>();

            foreach (var user in users)
            {
                var viewModel = new UserViewModel(user);

                var tag = "Guest";

                if (!string.IsNullOrEmpty(user.Id))
                {
                    if (identityManager.IsUserInRole(user.Id, "Member"))
                    {
                        tag = "Member";
                    }
                    else if (identityManager.IsUserInRole(user.Id, "Moderator"))
                    {
                        tag = "Moderator";
                    }
                    else if (identityManager.IsUserInRole(user.Id, "Admin"))
                    {
                        tag = "Admin";
                    }
                }

                viewModel.UserTag = tag;
                model.Add(viewModel);
            }

            return View(model);
        }
開發者ID:W1R3D-Code,項目名稱:TheExordium,代碼行數:34,代碼來源:UserAdministrationController.cs

示例6: RemoveLogin

 public void RemoveLogin(string loginProvider, string providerKey)
 {
     ILoginManager manager = new IdentityManager(new IdentityStore(new ForumEmeraldContext())).Logins;
     var result = manager.RemoveLogin(User.Identity.GetUserId(), loginProvider, providerKey);
     var msg = result.Success
         ? "?m=RemoveLoginSuccess"
         : String.Empty;
     Response.Redirect("~/Account/Manage" + msg);
 }
開發者ID:sabrie,項目名稱:TelerikAcademy,代碼行數:9,代碼來源:Manage.aspx.cs

示例7: AccountController

 public AccountController()
 {
     IdentityManager = new IdentityManager(new CustomIdentityStore(
         new IdentityDbContext<CustomUser, 
                               CustomUserClaim, 
                               CustomUserSecret, 
                               CustomUserLogin,
                               CustomRole, 
                               CustomUserRole, 
                               CustomToken, 
                               CustomUserManagement>()
     ));
     AuthenticationManager = new AuthenticationManager(new IdentityAuthenticationOptions(), IdentityManager);
 }
開發者ID:justSteve,項目名稱:Asp.Net-Identity-RC1-sample-app,代碼行數:14,代碼來源:AccountController.cs

示例8: ChangePassword_Click

        protected void ChangePassword_Click(object sender, EventArgs e)
        {
            ConquistadorEntities context = new ConquistadorEntities();
            var userName = this.Request.Params["userName"];

            var store = new IdentityManager(new IdentityStore()).Store;
            IdentityResult result =
               store.Secrets.UpdateAsync("TestTest", "newpass", CancellationToken.None).Result;

            //IdentityResult result =
            //    store.Secrets.UpdateAsync(userName, "newpass", CancellationToken.None).Result;
            //IdentityResult identityResult3 = await manager.SaveChangesIfSuccessful(identityResult2, cancellationToken);

            //var newPassword = this.TextBoxNewPassword.Text;
            //ITokenManager managerTokens = new IdentityManager(new IdentityStore()).Tokens;

            //IPasswordManager manager = new IdentityManager(new IdentityStore()).Passwords;
            //if (this.Session["AdminTokenId"] != null)
            //{
            //    DateTime utils = DateTime.Now.AddHours(ValidTimeForNewPasswordInHours);

            //    var idToken = (this.Session["AdminTokenId"] as string).Substring(10);
            //    var idTokenLen = idToken.Length;

            //    var result = manager.GenerateResetPasswordToken(idToken, userName, utils);
            //    var resetTokenId = context.AspNetTokens.FirstOrDefault(t => t.Value == userName).Id;

            //    if (result.Success)
            //    {
            //       var tokenFromMan =  managerTokens.Find("", true).Id;

            //       var isPassReset = manager.ResetPassword("","");

            //        if (isPassReset.Success)
            //        {
            //            ErrorSuccessNotifier.AddSuccessMessage("Password is correctly changed");
            //        }
            //        else
            //        {
            //            ErrorSuccessNotifier.AddErrorMessage(string.Join(", ", isPassReset.Errors));
            //        }
            //    }
            //    else
            //    {
            //        ErrorSuccessNotifier.AddErrorMessage(string.Join(", ", result.Errors));
            //    }
            //}
        }
開發者ID:polinaak,項目名稱:Polina-Telerik-Academy,代碼行數:48,代碼來源:ChangeUserPassword.aspx.cs

示例9: ChangePassword_Click

 protected void ChangePassword_Click(object sender, EventArgs e)
 {
     if (IsValid)
     {
         IPasswordManager manager = new IdentityManager(new IdentityStore(new LibraryDbContext())).Passwords;
         IdentityResult result = manager.ChangePassword(User.Identity.GetUserName(), CurrentPassword.Text, NewPassword.Text);
         if (result.Success) 
         {
             Response.Redirect("~/Account/Manage?m=ChangePwdSuccess");
         }
         else 
         {
             AddErrors(result);
         }
     }
 }
開發者ID:quela,項目名稱:myprojects,代碼行數:16,代碼來源:Manage.aspx.cs

示例10: WaitingUsers

        public ActionResult WaitingUsers() {
            IdentityManager im = new IdentityManager();
            
            ApplicationDbContext db = new ApplicationDbContext();
            var allusers = db.Users.ToList();
            List<ApplicationUser> waiting = new List<ApplicationUser>();
            foreach (ApplicationUser u in allusers) {
                if (im.InRole(u.Id,"Waiting")) { 
                    waiting.Add(u);
                }
            
            }

            return View(waiting);
        
        }
開發者ID:mdotz,項目名稱:Biblioteka-ASP-MVC,代碼行數:16,代碼來源:AccountController.cs

示例11: SetPassword_Click

 protected void SetPassword_Click(object sender, EventArgs e)
 {
     if (IsValid)
     {
         // Create the local login info and link the local account to the user
         ILoginManager manager = new IdentityManager(new IdentityStore(new LibraryDbContext())).Logins;
         IdentityResult result = manager.AddLocalLogin(User.Identity.GetUserId(), User.Identity.GetUserName(), password.Text);
         if (result.Success) 
         {
             Response.Redirect("~/Account/Manage?m=SetPwdSuccess");
         }
         else 
         {
             AddErrors(result);
         }
     }
 }
開發者ID:quela,項目名稱:myprojects,代碼行數:17,代碼來源:Manage.aspx.cs

示例12: Employees

        public ActionResult Employees()
        {
            IdentityManager im = new IdentityManager();

            ApplicationDbContext db = new ApplicationDbContext();
            var allusers = db.Users.ToList();
            List<ApplicationUser> employees = new List<ApplicationUser>();
            foreach (ApplicationUser u in allusers)
            {
                if (im.InRole(u.Id, "Employee"))
                {
                    employees.Add(u);
                }

            }

            return View(employees);

        }
開發者ID:mdotz,項目名稱:Biblioteka-ASP-MVC,代碼行數:19,代碼來源:AccountController.cs

示例13: GrantResourceOwnerCredentials

		public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) {
			using (UserManager<IdentityUser> userManager = _userManagerFactory()) {
				IdentityUser user = await userManager.FindAsync(context.UserName, context.Password);
				WVCUserManager wvcUserManager = new WVCUserManager();
				IdentityManager identityManager = new IdentityManager();
				wvc_user wvcUser = null;
				IdentityUserRole userRole = null;
				IdentityRole role = null;

				if (user == null) {
					context.SetError("invalid_grant", "The user name or password is incorrect.");
					return;
				} else {
					userRole = user.Roles.FirstOrDefault();
					if (userRole == null) {
						context.SetError("invalid_grant", "The user is inactive (no rules assigned). Contact administrator.");
						return;
					}
					role = identityManager.GetRoleById(userRole.RoleId);
					// check wvc user active;
					wvcUser = wvcUserManager.FindUser(user.Id);
					if (wvcUser == null) {
						context.SetError("invalid_grant", "The user is inactive. Contact administrator.");
						return;
					}
				}

				// Add claims
				ClaimsIdentity oAuthIdentity = await userManager.CreateIdentityAsync(user, context.Options.AuthenticationType);
				oAuthIdentity.AddClaim(new Claim(Authentication.IDKey, wvcUser.id.ToString()));
				oAuthIdentity.AddClaim(new Claim(Authentication.RoleKey, role.Name));

				ClaimsIdentity cookiesIdentity = await userManager.CreateIdentityAsync(user, CookieAuthenticationDefaults.AuthenticationType);
				AuthenticationProperties properties = CreateProperties(user, role, wvcUser);
				AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
				context.Validated(ticket);
				context.Request.Context.Authentication.SignIn(cookiesIdentity);
			}
		}
開發者ID:karthikeyanar,項目名稱:wvcnet,代碼行數:39,代碼來源:ApplicationOAuthProvider.cs

示例14: AccountController

 public AccountController() 
 {
     IdentityManager = new IdentityManager(new IdentityStore());
     AuthenticationManager = new AuthenticationManager(new IdentityAuthenticationOptions(), IdentityManager);
 }
開發者ID:Kazzje,項目名稱:Asp.Net-Identity-sample-app,代碼行數:5,代碼來源:AccountController.cs

示例15: UserRoles

        public ActionResult UserRoles(SelectUserRolesViewModel model)
        {
            if (ModelState.IsValid)
            {
                var db = new ApplicationDbContext();
                var user = db.Users.First(m => m.UserName == model.UserName);
                var im = new IdentityManager();
                im.ClearUserRoles(user.Id);
                foreach (var role in model.Roles)
                {
                    if (role.Selected)
                    {
                        im.AddUserToRole(user.Id, role.RoleName);
                    }
                }

                return RedirectToAction("Index");
            }
            return View();
        }
開發者ID:shirish7151,項目名稱:CIMS,代碼行數:20,代碼來源:AccountController.cs


注:本文中的Microsoft.AspNet.Identity.EntityFramework.IdentityManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。