Exemple #1
0
        public IActionResult ChangePassword(ObjChangePassword model)
        {
            if (model.NewPassword != model.NewPasswordConfirm)
            {
                return(RedirectToActionError("ChangePassword", "Пароли не совпадают"));
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var result = _userService.ChangePassword(model);

            if (result.Success)
            {
                return(RedirectToActionOk("Details", "Users", new { id = result.Id }, "Пароль изменен"));
            }

            return(RedirectToActionError("ChangePassword", result.ErrorMessage));
        }
Exemple #2
0
        public ServiceResult ChangePassword(ObjChangePassword model)
        {
            try
            {
                var user = _userRepository.Get(model.Id);
                if (user == null)
                {
                    return(ServiceResult.ErrorResult("Сотрудник не найден"));
                }
                user.PassHash = HelperMd5.CalculateMD5Hash(model.NewPassword);
                _userRepository.Update(user);
                _userRepository.SaveChanges();

                return(ServiceResult.SuccessResult(user.Id));
            }
            catch (Exception ex)
            {
                //_logger.LogError("Error with edit password for user id = {0} / message: {1}", model.Id, ex.Message);
                return(ServiceResult.ErrorResult("Ошибка при сохранении пароля"));
            }
        }