public async Task <IActionResult> AddPassword() { var user = await Usermanager.GetUserAsync(User); var userHasPassword = await Usermanager.HasPasswordAsync(user); if (userHasPassword) { return(RedirectToAction("ChangePassword")); } return(View()); }
public async Task <IActionResult> ChangePassword(ChangePasswordViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser(); if (User.IsInRole("Super Admin")) { user = await Usermanager.FindByIdAsync(model.Id); } else { user = await Usermanager.GetUserAsync(User); } if (user == null) { return(RedirectToAction("Login")); } // ChangePasswordAsync changes the user password var result = await Usermanager.ChangePasswordAsync(user, model.CurrentPassword, model.NewPassword); // The new password did not meet the complexity rules or // the current password is incorrect. Add these errors to // the ModelState and rerender ChangePassword view if (!result.Succeeded) { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } return(View()); } // Upon successfully changing the password refresh sign-in cookie if (!User.IsInRole("Super Admin")) { await Signinmanager.RefreshSignInAsync(user); } return(View("ChangePasswordConfirmation")); } return(View(model)); }
public async Task <IActionResult> Register() { if (Signinmanager.IsSignedIn(User)) { if (User.IsInRole("Super Admin") || User.IsInRole("Admin")) { return(RedirectToAction("AddEmployee", "Administration")); } else if (User.IsInRole("Employee")) { if (!User.HasClaim(claim => claim.Type == "Create User" && claim.Value == "true")) { return(Forbid()); //return RedirectToAction("~/Administration/AccessDenied.cshtml"); } else { ViewBag.cities = util.getCities(); ViewBag.Stores = util.GetAllStores(); var LoginUser = await Usermanager.GetUserAsync(User); RegisterViewModel r = new RegisterViewModel(); if (LoginUser.store_id != null) { r.store_id = LoginUser.store_id; } return(View(r)); } } else { return(RedirectToAction("Login", "Account")); } } ViewBag.cities = util.getCities(); ViewBag.Stores = util.GetAllStores(); return(View()); }
public async Task <IActionResult> ChangePassword(string id) { var user = new ApplicationUser(); if (id != null) { if (User.IsInRole("Super Admin")) { user = await Usermanager.FindByIdAsync(id); if (user == null) { ViewBag.ErrorMessage = $"The User ID {id} is invalid"; return(View("NotFound")); } } else { return(Forbid()); } } else { user = await Usermanager.GetUserAsync(User); } var userHasPassword = await Usermanager.HasPasswordAsync(user); if (!userHasPassword) { return(RedirectToAction("AddPassword")); } ChangePasswordViewModel c = new ChangePasswordViewModel() { Id = user.Id }; return(View()); }
public async Task <IActionResult> AddPassword(AddPasswordViewModel model) { if (ModelState.IsValid) { var user = await Usermanager.GetUserAsync(User); var result = await Usermanager.AddPasswordAsync(user, model.NewPassword); if (!result.Succeeded) { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } return(View()); } await Signinmanager.RefreshSignInAsync(user); return(View("AddPasswordConfirmation")); } return(View(model)); }