use of com.nixmash.blog.jpa.model.UserToken in project nixmash-blog by mintster.
the class UserPasswordControllerTests method resetPasswordFromEmail.
@Test
@WithAnonymousUser
public void resetPasswordFromEmail() throws Exception {
UserToken userToken = userService.createUserToken(erwin);
RequestBuilder request = post("/users/resetpassword").param("userId", "-400").param("verificationToken", userToken.getToken()).param("password", "password").param("repeatedPassword", "password").with(csrf());
mvc.perform(request).andExpect(model().attribute("feedbackMessage", containsString("login")));
}
use of com.nixmash.blog.jpa.model.UserToken in project nixmash-blog by mintster.
the class UserResetPasswordTests method expiredTimeTest.
// region Token Expiration tests
@Test
public void expiredTimeTest() {
UserToken userToken = userService.createUserToken(jeremy);
assertTrue(isValidToken(jeremy.getId(), userToken.getToken()));
}
use of com.nixmash.blog.jpa.model.UserToken in project nixmash-blog by mintster.
the class UserResetPasswordTests method createUserToken_RetrievesUser.
@Test
public void createUserToken_RetrievesUser() {
UserToken userToken = userService.createUserToken(erwin);
Optional<UserToken> found = userService.getUserToken(userToken.getToken());
if (found.isPresent())
assertEquals(found.get().getUser(), erwin);
}
use of com.nixmash.blog.jpa.model.UserToken in project nixmash-blog by mintster.
the class UserResetPasswordTests method existingUserTokensAreUpdated.
@Test
public void existingUserTokensAreUpdated() {
UserToken userToken = userService.createUserToken(erwin);
String token = userToken.getToken();
userToken = userService.createUserToken(erwin);
String newToken = userToken.getToken();
assertNotEquals(token, newToken);
assertFalse(userService.getUserToken(token).isPresent());
assertTrue(userService.getUserToken(newToken).isPresent());
}
use of com.nixmash.blog.jpa.model.UserToken in project nixmash-blog by mintster.
the class UserPasswordController method sendForgotEmail.
@RequestMapping(value = "/users/forgotpassword", method = POST)
public String sendForgotEmail(@Valid ForgotEmailDTO forgotEmailDTO, BindingResult result, Model model) {
if (result.hasErrors()) {
return USER_FORGOTPASSWORD_VIEW;
} else {
Optional<User> user = userService.getByEmail(forgotEmailDTO.getEmail());
if (!user.isPresent()) {
result.reject("global.error.email.does.not.exist");
} else {
model.addAttribute(FLASH_MESSAGE_KEY_FEEDBACK, webUI.getMessage(FEEDBACK_PASSWORD_EMAIL_SENT));
model.addAttribute("forgotEmailDTO", new ForgotEmailDTO());
UserToken userToken = userService.createUserToken(user.get());
fmMailService.sendResetPasswordMail(user.get(), userToken.getToken());
}
}
return USER_FORGOTPASSWORD_VIEW;
}
Aggregations