private static Task<bool> VerifyClientIdAsync(ApplicationUserManager manager, ApplicationUser user, CookieValidateIdentityContext context) { string clientId = context.Identity.FindFirstValue("AspNet.Identity.ClientId"); if (!string.IsNullOrEmpty(clientId) && user.Clients.Any(c => c.Id.ToString() == clientId)) { user.CurrentClientId = clientId; return Task.FromResult(true); } return Task.FromResult(false); }
private static async Task<bool> VerifySecurityStampAsync(ApplicationUserManager manager, ApplicationUser user, CookieValidateIdentityContext context) { string stamp = context.Identity.FindFirstValue("AspNet.Identity.SecurityStamp"); return (stamp == await manager.GetSecurityStampAsync(context.Identity.GetUserId())); }
public async Task<ActionResult> Create(RegisterViewModel userViewModel, params string[] selectedRoles) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = userViewModel.Email, Email = userViewModel.Email }; var adminresult = await UserManager.CreateAsync(user, userViewModel.Password); //Add User to the selected Roles if (adminresult.Succeeded) { if (selectedRoles != null) { var result = await UserManager.AddToRolesAsync(user.Id, selectedRoles); if (!result.Succeeded) { ModelState.AddModelError("", result.Errors.First()); ViewBag.RoleId = new SelectList(await RoleManager.Roles.ToListAsync(), "Name", "Name"); return View(); } } } else { ModelState.AddModelError("", adminresult.Errors.First()); ViewBag.RoleId = new SelectList(RoleManager.Roles, "Name", "Name"); return View(); } return RedirectToAction("Index"); } ViewBag.RoleId = new SelectList(RoleManager.Roles, "Name", "Name"); return View(); }