public IActionResult ChangePassword(UserRequestChangePasswordViewModel user)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                return(Ok(service.ChangePassword(user)));
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 2
0
        public bool ChangePassword(UserRequestChangePasswordViewModel user)
        {
            ValidationService.ValidEmail(user.Email);
            ValidationService.ValidPassword(user.Password, user.PasswordConfirm);

            User _user = repository.GetByEmailAndCode(user.Email, user.Code);

            if (_user == null)
            {
                throw new ApiException("Email/Code not found", HttpStatusCode.NotFound);
            }

            _user.Code     = string.Empty;
            _user.Password = UtilsService.EncryptPassword(user.Password);
            repository.Update(_user);

            emailSender.SendEmailAsync(new EmailViewModel(new string[] { _user.Email }, "Change Password - Template", "PASSWORD-CHANGED"), new string[] { _user.Name });

            return(true);
        }