|
19 | 19 | import org.springframework.beans.factory.annotation.Autowired; |
20 | 20 | import org.springframework.context.ApplicationEventPublisher; |
21 | 21 | import org.springframework.context.MessageSource; |
22 | | -import org.springframework.http.MediaType; |
| 22 | +import org.springframework.context.NoSuchMessageException; |
23 | 23 | import org.springframework.mail.MailAuthenticationException; |
24 | 24 | import org.springframework.mail.SimpleMailMessage; |
25 | 25 | import org.springframework.mail.javamail.JavaMailSender; |
|
39 | 39 | import org.springframework.web.bind.annotation.ResponseBody; |
40 | 40 | import org.springframework.web.servlet.ModelAndView; |
41 | 41 |
|
| 42 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 43 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 44 | + |
42 | 45 | @Controller |
43 | 46 | public class RegistrationController { |
44 | 47 | private final Logger LOGGER = LoggerFactory.getLogger(getClass()); |
@@ -140,15 +143,14 @@ public String resendRegistrationToken(final HttpServletRequest request, final Mo |
140 | 143 | return "redirect:/login.html?lang=" + locale.getLanguage(); |
141 | 144 | } |
142 | 145 |
|
143 | | - @RequestMapping(value = "/user/resendRegistrationToken2", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) |
144 | | - public @ResponseBody String resendRegistrationToken2(final HttpServletRequest request, final Model model, @RequestParam("token") final String existingToken) { |
| 146 | + @RequestMapping(value = "/user/resendRegistrationToken2", method = RequestMethod.GET) |
| 147 | + public @ResponseBody String resendRegistrationToken2(final HttpServletRequest request, final Model model, @RequestParam("token") final String existingToken) throws JsonProcessingException, NoSuchMessageException { |
145 | 148 | final VerificationToken newToken = userService.generateNewVerificationToken(existingToken); |
146 | 149 | final User user = userService.getUser(newToken.getToken()); |
147 | 150 | final String appUrl = request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); |
148 | 151 | final SimpleMailMessage email = constructResetVerificationTokenEmail(appUrl, request.getLocale(), newToken, user); |
149 | | - System.out.println(email.getText()); |
150 | 152 | mailSender.send(email); |
151 | | - return messages.getMessage("message.resendToken", null, request.getLocale()); |
| 153 | + return new ObjectMapper().writeValueAsString(messages.getMessage("message.resendToken", null, request.getLocale())); |
152 | 154 | } |
153 | 155 |
|
154 | 156 | @RequestMapping(value = "/user/resetPassword", method = RequestMethod.POST) |
@@ -177,6 +179,22 @@ public String resetPassword(final HttpServletRequest request, final Model model, |
177 | 179 | return "redirect:/login.html?lang=" + request.getLocale().getLanguage(); |
178 | 180 | } |
179 | 181 |
|
| 182 | + @RequestMapping(value = "/user/resetPassword2", method = RequestMethod.POST) |
| 183 | + public @ResponseBody String resetPassword2(final HttpServletRequest request, final Model model, @RequestParam("email") final String userEmail) throws JsonProcessingException, NoSuchMessageException { |
| 184 | + final User user = userService.findUserByEmail(userEmail); |
| 185 | + if (user == null) { |
| 186 | + return new ObjectMapper().writeValueAsString(messages.getMessage("message.userNotFound", null, request.getLocale())); |
| 187 | + } |
| 188 | + |
| 189 | + final String token = UUID.randomUUID().toString(); |
| 190 | + userService.createPasswordResetTokenForUser(user, token); |
| 191 | + final String appUrl = request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); |
| 192 | + final SimpleMailMessage email = constructResetTokenEmail(appUrl, request.getLocale(), token, user); |
| 193 | + mailSender.send(email); |
| 194 | + |
| 195 | + return new ObjectMapper().writeValueAsString(messages.getMessage("message.resetPassword", null, request.getLocale())); |
| 196 | + } |
| 197 | + |
180 | 198 | @RequestMapping(value = "/user/changePassword", method = RequestMethod.GET) |
181 | 199 | public String changePassword(final HttpServletRequest request, final Model model, @RequestParam("id") final long id, @RequestParam("token") final String token) { |
182 | 200 | final Locale locale = request.getLocale(); |
|
0 commit comments