use of org.motechproject.server.web.dto.ResetViewData in project motech by motech.
the class ResetControllerTest method testResetInvalidToken.
@Test
public void testResetInvalidToken() throws Exception {
ResetViewData expected = getResetViewData(true, true, asList("server.reset.invalidToken"), getResetForm(TOKEN, PASSWORD, PASSWORD));
doThrow(new InvalidTokenException()).when(recoveryService).resetPassword(TOKEN, PASSWORD, PASSWORD);
controller.perform(post("/forgotreset").locale(Locale.ENGLISH).body(new ObjectMapper().writeValueAsBytes(getResetForm(TOKEN, PASSWORD, PASSWORD))).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().string(new ObjectMapper().writeValueAsString(expected)));
verify(recoveryService).resetPassword(TOKEN, PASSWORD, PASSWORD);
}
use of org.motechproject.server.web.dto.ResetViewData in project motech by motech.
the class ResetController method getResetViewData.
@RequestMapping(value = "/forgotresetviewdata", method = RequestMethod.GET)
@ResponseBody
public ResetViewData getResetViewData(final HttpServletRequest request) {
ResetViewData viewData = new ResetViewData();
ResetForm form = new ResetForm();
String token = request.getParameter("token");
if (recoveryService.validateToken(token)) {
form.setToken(token);
viewData.setInvalidToken(false);
} else {
viewData.setInvalidToken(true);
}
viewData.setResetForm(form);
viewData.setResetSucceed(false);
viewData.setPageLang(cookieLocaleResolver.resolveLocale(request));
return viewData;
}
use of org.motechproject.server.web.dto.ResetViewData in project motech by motech.
the class ResetController method reset.
@RequestMapping(value = "/forgotreset", method = RequestMethod.POST)
@ResponseBody
public ResetViewData reset(@RequestBody ResetForm form, final HttpServletRequest request) {
ResetViewData viewData = new ResetViewData();
viewData.setResetForm(form);
viewData.setPageLang(cookieLocaleResolver.resolveLocale(request));
viewData.setInvalidToken(false);
List<String> errors = resetFormValidator.validate(form);
if (!errors.isEmpty()) {
viewData.setResetSucceed(false);
viewData.setErrors(errors);
return viewData;
} else {
try {
recoveryService.resetPassword(form.getToken(), form.getPassword(), form.getPasswordConfirmation());
} catch (InvalidTokenException e) {
LOGGER.debug("Reset with invalid token attempted", e);
errors.add("server.reset.invalidToken");
viewData.setInvalidToken(true);
} catch (RuntimeException e) {
LOGGER.error("Error while reseting passsword", e);
errors.add("server.reset.error");
}
viewData.setResetSucceed(true);
viewData.setErrors(errors);
}
return viewData;
}
Aggregations