Search in sources :

Example 1 with UserToken

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")));
}
Also used : RequestBuilder(org.springframework.test.web.servlet.RequestBuilder) UserToken(com.nixmash.blog.jpa.model.UserToken) WithAnonymousUser(org.springframework.security.test.context.support.WithAnonymousUser) Test(org.junit.Test)

Example 2 with UserToken

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()));
}
Also used : UserToken(com.nixmash.blog.jpa.model.UserToken) Test(org.junit.Test)

Example 3 with UserToken

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);
}
Also used : UserToken(com.nixmash.blog.jpa.model.UserToken) Test(org.junit.Test)

Example 4 with UserToken

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());
}
Also used : UserToken(com.nixmash.blog.jpa.model.UserToken) Test(org.junit.Test)

Example 5 with UserToken

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;
}
Also used : ForgotEmailDTO(com.nixmash.blog.jpa.dto.ForgotEmailDTO) CurrentUser(com.nixmash.blog.jpa.model.CurrentUser) User(com.nixmash.blog.jpa.model.User) UserToken(com.nixmash.blog.jpa.model.UserToken) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

UserToken (com.nixmash.blog.jpa.model.UserToken)5 Test (org.junit.Test)4 ForgotEmailDTO (com.nixmash.blog.jpa.dto.ForgotEmailDTO)1 CurrentUser (com.nixmash.blog.jpa.model.CurrentUser)1 User (com.nixmash.blog.jpa.model.User)1 WithAnonymousUser (org.springframework.security.test.context.support.WithAnonymousUser)1 RequestBuilder (org.springframework.test.web.servlet.RequestBuilder)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1