use of org.motechproject.security.exception.PasswordValidatorException in project motech by motech.
the class MotechUserServiceTest method shouldValidatePasswordOnEdit.
@Test(expected = PasswordValidatorException.class)
public void shouldValidatePasswordOnEdit() {
UserDto userDto = new UserDto();
userDto.setPassword("wrong");
userDto.setUserName("user");
when(motechUsersDao.findByUserName("user")).thenReturn(user);
doThrow(new PasswordValidatorException("error")).when(validator).validate("wrong");
motechUserService.updateUserDetailsWithPassword(userDto);
}
use of org.motechproject.security.exception.PasswordValidatorException in project motech by motech.
the class ResetController method changePassword.
@RequestMapping(value = "/changepassword", method = RequestMethod.POST)
@ResponseBody
public ChangePasswordViewData changePassword(@RequestBody ChangePasswordForm form) {
ChangePasswordViewData viewData = new ChangePasswordViewData(form);
ChangePasswordFormValidator validator = new ChangePasswordFormValidator();
List<String> errors = validator.validate(form);
if (!errors.isEmpty()) {
viewData.setErrors(errors);
} else {
try {
MotechUserProfile profile = motechUserService.changeExpiredPassword(form.getUsername(), form.getOldPassword(), form.getPassword());
if (profile != null) {
viewData.setChangeSucceded(true);
} else {
viewData.getErrors().add("server.reset.wrongPassword");
}
} catch (PasswordValidatorException e) {
viewData.getErrors().add(e.getMessage());
} catch (LockedException e) {
viewData.setUserBlocked(true);
}
}
viewData.getChangePasswordForm().resetPasswordsAndUserName();
return viewData;
}
Aggregations