public async Task<IdentityResult> UpdateRolesAsync(ApplicationUser user, string[] newRoleIds) { var userRoles = await UserManager.GetRolesAsync(user.Id); string[] rolesToAdd = newRoleIds.Except(userRoles).ToArray<string>(); string[] rolesToRemove = userRoles.Except(newRoleIds).ToArray<string>(); var result = await UserManager.AddToRolesAsync(user.Id, rolesToAdd); if (result.Succeeded) { result = await UserManager.RemoveFromRolesAsync(user.Id, rolesToRemove); } return result; }
private async Task SignInAsync(ApplicationUser user, bool isPersistent) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie); AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, await user.GenerateUserIdentityAsync(UserManager)); }
public Task<IdentityResult> DeleteAsync(ApplicationUser item) { return UserManager.DeleteAsync(item); }
public Task<IdentityResult> AddAsync(ApplicationUser item) { return UserManager.CreateAsync(item); }
public async Task<IdentityResult> UpdateAsync(ApplicationUser item, string id) { var result = await UserManager.UpdateAsync(item); return result; }
public async Task<ActionResult> Register(RegisterViewModel model, string returnUrl) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, PreferredName = model.PreferredName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); if (WebConfigurationManager.AppSettings["DisableEmails"] != "true") { await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>"); } if (!string.IsNullOrEmpty(returnUrl)) { var signinResult = await SignInManager.PasswordSignInAsync(model.Email, model.Password, false, shouldLockout: false); switch (signinResult) { case SignInStatus.Success: return RedirectToLocal(returnUrl); } } ViewBag.Link = callbackUrl; return View("DisplayEmail"); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }