当前位置: 首页>>代码示例>>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;未经允许,请勿转载。