public async Task <IActionResult> ChangePassword([FromBody]
                                                         ChangePasswordFormModel userForm)
        {
            var users = await _usersService.ChangePasswordAsync(HttpContext.GetUser(), userForm);

            return(Ok(GetRequestResult(users)));
        }
コード例 #2
0
 public ActionResult ChangePassword(ChangePasswordFormModel form)
 {
     if (ModelState.IsValid)
     {
         EFMVCUser efmvcUser = HttpContext.User.GetEFMVCUser();
         var       command   = new ChangePasswordCommand
         {
             UserId      = efmvcUser.UserId,
             OldPassword = form.OldPassword,
             NewPassword = form.NewPassword
         };
         IEnumerable <ValidationResult> errors = commandBus.Validate(command);
         ModelState.AddModelErrors(errors);
         if (ModelState.IsValid)
         {
             var result = commandBus.Submit(command);
             if (result.Success)
             {
                 return(RedirectToAction("ChangePasswordSuccess"));
             }
             else
             {
                 ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
             }
         }
     }
     // If we got this far, something failed, redisplay form
     return(View(form));
 }
コード例 #3
0
ファイル: AccountController.cs プロジェクト: zszqwe/FNHMVC
        public ActionResult ChangePassword(ChangePasswordFormModel form)
        {
            if (ModelState.IsValid)
            {
                var user    = HttpContext.User;
                var command = new ChangePasswordCommand
                {
                    UserId      = int.Parse(user.Identity.GetUserId()),
                    OldPassword = form.OldPassword,
                    NewPassword = form.NewPassword
                };
                IEnumerable <ValidationResult> errors = commandBus.Validate(command);
                ModelState.AddModelErrors(errors);
                if (ModelState.IsValid)
                {
                    var result = commandBus.Submit(command);
                    if (result.Success)
                    {
                        return(RedirectToAction("ChangePasswordSuccess"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
                    }
                }
            }

            return(View(form));
        }
コード例 #4
0
ファイル: UserController.cs プロジェクト: ruscal/myMoodServer
        public virtual ActionResult ChangeMyPassword(ChangePasswordFormModel model)
        {
            if (ModelState.IsValid)
            {
                var errors = User.Identity.UserInfo.ValidateNewPassword(model.NewPassword);

                if (errors.Any())
                {
                    ModelState.Add(errors);
                }
                else
                {
                    try
                    {
                        if (User.Identity.UserInfo.PasswordEquals(model.CurrentPassword))
                        {
                            User.Identity.UserInfo.SetPassword(model.NewPassword);

                            db.SaveChanges();
                        }
                        else
                        {
                            ModelState.AddModelError("CurrentPassword", "The value you entered does not match your current password");
                        }
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }
                }
            }

            if (Request.IsAjaxRequest())
            {
                return(ModelState.IsValid ?
                       Json(new { success = true }) :
                       Json(new { success = false, formWithErrorMessages = this.RenderPartialViewToString(MVC.User.Views.ChangePassword, model) }));
            }
            else
            {
                return(ModelState.IsValid ?
                       RedirectToRoute("Home").WithFlashMessage("Your password has been updated") as ActionResult :
                       View(MVC.User.Views.ChangeMyPassword, model) as ActionResult);
            }
        }
コード例 #5
0
        public async Task <bool> ChangePasswordAsync(User user, ChangePasswordFormModel userForm)
        {
            try
            {
                var userEdt = await _context.Users.FirstOrDefaultAsync(c => c.Id == userForm.UserId && c.Password == _securityService.GetSha256Hash(userForm.CurrentPassword));

                if (userEdt == null)
                {
                    throw new ExperienceManagementGlobalException(UsersServiceErrors.UserNotFoundError);
                }
                userEdt.Password = _securityService.GetSha256Hash(userForm.NewPassword);
                _context.Users.Update(userEdt);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                throw new ExperienceManagementGlobalException(UsersServiceErrors.ChangePasswordError, ex);
            }
        }
コード例 #6
0
        public async Task <IActionResult> ChangePassword([FromRoute] string membershipId, [FromRoute] string id, [FromBody] ChangePasswordFormModel model)
        {
            var utilizer = this.GetUtilizer();

            await this.userService.ChangePasswordAsync(utilizer, membershipId, id, model.Password);

            return(this.Ok());
        }
コード例 #7
0
 public async Task <ActionResult> ChangePassword(ChangePasswordFormModel input)
 => await this.Handle(
     async() => await this.identity.ChangePassword(this.mapper.Map <ChangePasswordInputModel>(input)),
     success : RedirectToAction(nameof(HomeController.Index), "Home"),
     failure : View("../Home/Index", input));