public async Task <IHttpActionResult> PostChangePassword(JObject form) { try { var email = string.Empty; var password = string.Empty; dynamic jsonObject = form; try { email = jsonObject.Email.Value; password = jsonObject.Password.Value; } catch { return(BadRequest("Incorrect call.")); } var user = UsersHelper.GetUserASP(email); if (user == null) { return(BadRequest("003. User dont exist.")); } var result = await UsersHelper.ChangePassword(user.Id, password); return(Ok(result)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult ChangePW([FromBody] ChangePasswordRequestModel changePasswordRequest) { var userId = HttpContext?.User?.Claims?.Where(c => c.Type == "sub").FirstOrDefault()?.Value ?? ""; var result = _usersHelper.ChangePassword(userId, changePasswordRequest.OldPassword, changePasswordRequest.NewPassword); return(AGSResponseFactory.GetAGSResponseJsonResult(result)); }
public void ChangePassword_EmptyOrNullNewPassword__ThrowException(string newPassword) { var repository = new Mock <IRepository>(); var usersHelper = new UsersHelper(repository.Object, _configuration); Assert.Throws <ArgumentNullException>(() => usersHelper.ChangePassword("abc", "abc", newPassword)); }
public void ChangePassword_WrongOldPassword_ThrowException(string id) { var repository = new Mock <IRepository>(); repository.Setup(_ => _.UsersRepository.ValidatePassword(id, _configuration["default_user_password"])).Returns(false); var usersHelper = new UsersHelper(repository.Object, _configuration); Assert.Throws <AGSException>(() => usersHelper.ChangePassword(id, _configuration["default_user_password"], _configuration["default_user_password"])); }
public void ChangePassword_ValidInput_Success(string id) { var repository = new Mock <IRepository>(); repository.Setup(_ => _.UsersRepository.ValidatePassword(id, _configuration["default_user_password"])).Returns(true); repository.Setup(_ => _.UsersRepository.ChangePassword(id, _configuration["default_user_password"])).Returns(true); var usersHelper = new UsersHelper(repository.Object, _configuration); var result = usersHelper.ChangePassword(id, _configuration["default_user_password"], _configuration["default_user_password"]); Assert.True(result); }