Esempio n. 1
0
        public DatabaseOperationResult ChangePassword(ChangePasswordViewModel model)
        {
            var result = new DatabaseOperationResult();
            if (string.IsNullOrWhiteSpace(model.NewPassword))
            {
                result.AddError("Password is not provided");
                return result;
            }

            var user = _unitOfWork.UserRepository.FindById(_sessionWrapper.UserId);
            if (user == null)
            {
                result.AddError("User not found");
                return result;
            }

            string oldPassword = _webHelper.EncryptToMd5(model.OldPassword);
            bool oldPasswordIsValid = oldPassword == user.Password;
            if (!oldPasswordIsValid)
                result.AddError("Old password doesn't match.");

            if (oldPasswordIsValid)
            {
                user.Password = _webHelper.EncryptToMd5(model.NewPassword);
                _unitOfWork.UserRepository.Update(user);
                _unitOfWork.Save();
            }
            return result;
        }
Esempio n. 2
0
 public ActionResult ChangePassword(ChangePasswordViewModel model)
 {
     if (ModelState.IsValid)
     {
         var result = _userService.ChangePassword(model);
         if (result.Success)
         {
             ViewBag.Message = "Your password changed successfuly.";
             return View();
         }
         foreach (var error in result.Errors)
             ModelState.AddModelError("", error);
     }
     return View(model);
 }