Example #1
0
        // GET: Account/ChangePassword
        public ActionResult ChangePassword()
        {
            var model = new ChangeMyPasswordModel {
                Login = GetCurrentUser().Login
            };

            return(View(model));
        }
Example #2
0
        public ActionResult ChangePassword(ChangeMyPasswordModel model)
        {
            var user = GetCurrentUser();

            if (user.Login != model.Login)
            {
                return(Forbid());
            }

            model.Login = user.Login;

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.NewPassword.Trim().Length == 0)
            {
                return(BadRequest());
            }

            try
            {
                if (model.NewPassword != model.NewPasswordConfirm)
                {
                    ModelState.AddModelError("NewPasswordConfirm", "Les mots de passe ne correspondent pas");
                    return(View(model));
                }

                if (!user.TestPassword(model.OldPassword))
                {
                    ModelState.AddModelError("OldPassword", "Le mot de passe est erroné");
                    return(View(model));
                }

                user.SetPassword(model.NewPassword);

                _context.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                throw;
            }
        }
        public async Task <ActionResult> ChangeMyPassword(ChangeMyPasswordModel model)
        {
            if (string.IsNullOrEmpty(model.NewPassword))
            {
                return(this.JsonFailResult(Phrases.FieldShouldNotBeEmpty, "#newPassword"));
            }

            if (string.IsNullOrEmpty(model.PasswordConfirmation))
            {
                return(this.JsonFailResult(Phrases.FieldShouldNotBeEmpty, "#passwordConfirmation"));
            }

            if (model.NewPassword != model.PasswordConfirmation)
            {
                return(this.JsonFailResult(Phrases.PasswordsDoNotMatch, "#passwordConfirmation"));
            }

            var id = this.GetUserId();
            await _backOfficeUsersRepository.ChangePasswordAsync(id, model.NewPassword);

            return(this.JsonFailResult(Phrases.PasswordIsNowChanged, "#btnChangePassword"));
        }
 public ActionResult ChangeMyPassword(ChangeMyPasswordModel model)
 {
     ViewBag.Message = null;
     if (ModelState.IsValid)
     {
         var userName = User.Identity.Name;
         if (!string.IsNullOrWhiteSpace(userName))
         {
             var dal  = this.GetDAL <UsersLayer>();
             var flag = dal.ChangeMyPassword(userName, this.GetMD5(model.OldPassword), this.GetMD5(model.NewPassword));
             if (flag)
             {
                 ModelState.Clear();
                 ViewBag.Message = "Password successfully changed";
             }
             else
             {
                 ViewBag.Message = "Old Password not correct. Chnage was not successfull";
             }
         }
     }
     return(View(model));
 }
        public ActionResult ChangeMyPassword()
        {
            var model = new ChangeMyPasswordModel();

            return(View(model));
        }