Ejemplo n.º 1
0
        public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            var             email = RoleName.EMAIL;
            ApplicationUser user  = await UserManager.FindByEmailAsync(email);

            string resetToken = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

            //var password = getAutoGeneratedPassword();

            IdentityResult passwordChangeResult = UserManager.ResetPassword(user.Id, resetToken, model.NewPassword);

            if (!passwordChangeResult.Succeeded)
            {
                ViewBag.Message = " Passwords must have at least one non letter or digit character.Passwords must have at least one digit('0' - '9').Passwords must have at least one uppercase('A' - 'Z').";
                return(View("ChangePassword", new ChangePasswordViewModel()));
            }
            ViewBag.Message = "Password has been changed ";
            return(View("ChangePassword", new ChangePasswordViewModel()));
        }
Ejemplo n.º 2
0
 public async Task<ActionResult> ChangePassword(ChangePasswordViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);
     if (result.Succeeded)
     {
         var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
         if (user != null)
         {
             await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
         }
         return RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess });
     }
     AddErrors(result);
     return View(model);
 }
Ejemplo n.º 3
0
 public async Task<IActionResult> ChangePassword(ChangePasswordViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var user = await GetCurrentUserAsync();
     if (user != null)
     {
         var result = await UserManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);
         if (result.Succeeded)
         {
             await SignInManager.SignInAsync(user, isPersistent: false);
             return RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess });
         }
         AddErrors(result);
         return View(model);
     }
     return RedirectToAction("Index", new { Message = ManageMessageId.Error });
 }