@Test public void testInvalidEmail() throws UserNotFoundException { doThrow(new UserNotFoundException()).when(recoveryService).passwordRecoveryRequest(EMAIL); when(cookieLocaleResolver.resolveLocale(request)).thenReturn(Locale.ENGLISH); when(motechSettings.getLoginMode()).thenReturn(LoginMode.REPOSITORY); assertEquals("security.forgot.noSuchUser", controller.forgotPost(EMAIL)); verify(recoveryService).passwordRecoveryRequest(EMAIL); }
@RequestMapping(value = "/forgot", method = RequestMethod.POST) @ResponseBody public String forgotPost(@RequestBody String email) { LoginMode loginMode = settingsFacade.getPlatformSettings().getLoginMode(); if (loginMode.isRepository()) { try { recoveryService.passwordRecoveryRequest(email); } catch (UserNotFoundException e) { LOGGER.warn("Request for a nonexistent email", e); return "security.forgot.noSuchUser"; } catch (RuntimeException e) { LOGGER.error("Error processing recovery", e); return "security.forgot.errorSending"; } } else { try { recoveryService.oneTimeTokenOpenId(email); } catch (UserNotFoundException e) { LOGGER.warn("Request for a nonexistent email", e); return "security.forgot.noSuchUser"; } catch (NonAdminUserException e) { LOGGER.warn("Request for a nonexistent email", e); return "security.forgot.nonAdminUser"; } catch (RuntimeException e) { LOGGER.error("Error processing recovery", e); return "security.forgot.errorSending"; } } return null; }
ForgotController { @RequestMapping(value = "/forgot", method = RequestMethod.POST) @ResponseBody public String forgotPost(@RequestBody String email) { LoginMode loginMode = settingsFacade.getPlatformSettings().getLoginMode(); if (loginMode.isRepository()) { try { recoveryService.passwordRecoveryRequest(email); } catch (UserNotFoundException e) { LOGGER.warn("Request for a nonexistent email", e); return "security.forgot.noSuchUser"; } catch (RuntimeException e) { LOGGER.error("Error processing recovery", e); return "security.forgot.errorSending"; } } else { try { recoveryService.oneTimeTokenOpenId(email); } catch (UserNotFoundException e) { LOGGER.warn("Request for a nonexistent email", e); return "security.forgot.noSuchUser"; } catch (NonAdminUserException e) { LOGGER.warn("Request for a nonexistent email", e); return "security.forgot.nonAdminUser"; } catch (RuntimeException e) { LOGGER.error("Error processing recovery", e); return "security.forgot.errorSending"; } } return null; } }
ForgotController { @RequestMapping(value = "/forgot", method = RequestMethod.POST) @ResponseBody public String forgotPost(@RequestBody String email) { LoginMode loginMode = settingsFacade.getPlatformSettings().getLoginMode(); if (loginMode.isRepository()) { try { recoveryService.passwordRecoveryRequest(email); } catch (UserNotFoundException e) { LOGGER.warn("Request for a nonexistent email", e); return "security.forgot.noSuchUser"; } catch (RuntimeException e) { LOGGER.error("Error processing recovery", e); return "security.forgot.errorSending"; } } else { try { recoveryService.oneTimeTokenOpenId(email); } catch (UserNotFoundException e) { LOGGER.warn("Request for a nonexistent email", e); return "security.forgot.noSuchUser"; } catch (NonAdminUserException e) { LOGGER.warn("Request for a nonexistent email", e); return "security.forgot.nonAdminUser"; } catch (RuntimeException e) { LOGGER.error("Error processing recovery", e); return "security.forgot.errorSending"; } } return null; }  }
ForgotController { @RequestMapping(value = "/forgot", method = RequestMethod.POST) @ResponseBody public String forgotPost(@RequestBody String email) { LoginMode loginMode = settingsFacade.getPlatformSettings().getLoginMode(); if (loginMode.isRepository()) { try { recoveryService.passwordRecoveryRequest(email); } catch (UserNotFoundException e) { LOGGER.warn("Request for a nonexistent email", e); return "security.forgot.noSuchUser"; } catch (RuntimeException e) { LOGGER.error("Error processing recovery", e); return "security.forgot.errorSending"; } } else { try { recoveryService.oneTimeTokenOpenId(email); } catch (UserNotFoundException e) { LOGGER.warn("Request for a nonexistent email", e); return "security.forgot.noSuchUser"; } catch (NonAdminUserException e) { LOGGER.warn("Request for a nonexistent email", e); return "security.forgot.nonAdminUser"; } catch (RuntimeException e) { LOGGER.error("Error processing recovery", e); return "security.forgot.errorSending"; } } return null; }  @RequestMapping(value = "/forgot", method = RequestMethod.GET) ModelAndView login(final HttpServletRequest request); @RequestMapping(value = "/forgotviewdata", method = RequestMethod.GET) @ResponseBody ForgotViewData getForgotViewData(final HttpServletRequest request); @RequestMapping(value = "/forgot", method = RequestMethod.POST) @ResponseBody String forgotPost(@RequestBody String email); }
ForgotController { @RequestMapping(value = "/forgot", method = RequestMethod.POST) @ResponseBody public String forgotPost(@RequestBody String email) { LoginMode loginMode = settingsFacade.getPlatformSettings().getLoginMode(); if (loginMode.isRepository()) { try { recoveryService.passwordRecoveryRequest(email); } catch (UserNotFoundException e) { LOGGER.warn("Request for a nonexistent email", e); return "security.forgot.noSuchUser"; } catch (RuntimeException e) { LOGGER.error("Error processing recovery", e); return "security.forgot.errorSending"; } } else { try { recoveryService.oneTimeTokenOpenId(email); } catch (UserNotFoundException e) { LOGGER.warn("Request for a nonexistent email", e); return "security.forgot.noSuchUser"; } catch (NonAdminUserException e) { LOGGER.warn("Request for a nonexistent email", e); return "security.forgot.nonAdminUser"; } catch (RuntimeException e) { LOGGER.error("Error processing recovery", e); return "security.forgot.errorSending"; } } return null; }  @RequestMapping(value = "/forgot", method = RequestMethod.GET) ModelAndView login(final HttpServletRequest request); @RequestMapping(value = "/forgotviewdata", method = RequestMethod.GET) @ResponseBody ForgotViewData getForgotViewData(final HttpServletRequest request); @RequestMapping(value = "/forgot", method = RequestMethod.POST) @ResponseBody String forgotPost(@RequestBody String email);  }