Package com.porterhead.rest.user.domain

Examples of com.porterhead.rest.user.domain.VerificationToken


        User user = ensureUserIsLoaded(userId);
        return sendEmailVerificationToken(user);
    }

    private VerificationToken sendEmailVerificationToken(User user) {
        VerificationToken token = new VerificationToken(user, VerificationToken.VerificationTokenType.emailVerification,
                config.getEmailVerificationTokenExpiryTimeInMinutes());
        user.addVerificationToken(token);
        userRepository.save(user);
        emailServicesGateway.sendVerificationToken(new EmailServiceTokenModel(user, token, getConfig().getHostNameUrl()));
        return token;
View Full Code Here


    }

    @Transactional
    public VerificationToken sendEmailRegistrationToken(String userId) {
        User user = ensureUserIsLoaded(userId);
        VerificationToken token = new VerificationToken(user,
                VerificationToken.VerificationTokenType.emailRegistration,
                config.getEmailRegistrationTokenExpiryTimeInMinutes());
        user.addVerificationToken(token);
        userRepository.save(user);
        emailServicesGateway.sendVerificationToken(new EmailServiceTokenModel(user,
View Full Code Here

     * @return  a token or null if user not found
     */
    @Transactional
    public VerificationToken sendLostPasswordToken(LostPasswordRequest lostPasswordRequest) {
        validate(lostPasswordRequest);
        VerificationToken token = null;
        User user = userRepository.findByEmailAddress(lostPasswordRequest.getEmailAddress());
        if (user != null) {
            token = user.getActiveLostPasswordToken();
            if (token == null) {
                token = new VerificationToken(user, VerificationToken.VerificationTokenType.lostPassword,
                        config.getLostPasswordTokenExpiryTimeInMinutes());
                user.addVerificationToken(token);
                userRepository.save(user);
            }
            emailServicesGateway.sendVerificationToken(new EmailServiceTokenModel(user, token, getConfig().getHostNameUrl()));
View Full Code Here

        return token;
    }

    @Transactional
    public VerificationToken verify(String base64EncodedToken) {
        VerificationToken token = loadToken(base64EncodedToken);
        if (token.isVerified() || token.getUser().isVerified()) {
            throw new AlreadyVerifiedException();
        }
        token.setVerified(true);
        token.getUser().setVerified(true);
        userRepository.save(token.getUser());
        return token;
    }
View Full Code Here

        }
        if (user.isVerified()) {
            throw new AlreadyVerifiedException();
        }
        //if token still active resend that
        VerificationToken token = user.getActiveEmailVerificationToken();
        if (token == null) {
            token = sendEmailVerificationToken(user);
        } else {
            emailServicesGateway.sendVerificationToken(new EmailServiceTokenModel(user, token, getConfig().getHostNameUrl()));
        }
View Full Code Here

    @Transactional
    public VerificationToken resetPassword(String base64EncodedToken, PasswordRequest passwordRequest) {
        Assert.notNull(base64EncodedToken);
        validate(passwordRequest);
        VerificationToken token = loadToken(base64EncodedToken);
        if (token.isVerified()) {
            throw new AlreadyVerifiedException();
        }
        token.setVerified(true);
        User user = token.getUser();
        try {
            user.setHashedPassword(user.hashPassword(passwordRequest.getPassword()));
        } catch (Exception e) {
            throw new AuthenticationException();
        }
View Full Code Here

    }

    private VerificationToken loadToken(String base64EncodedToken) {
        Assert.notNull(base64EncodedToken);
        String rawToken = new String(Base64.decodeBase64(base64EncodedToken));
        VerificationToken token = tokenRepository.findByToken(rawToken);
        if (token == null) {
            throw new TokenNotFoundException();
        }
        if (token.hasExpired()) {
            throw new TokenHasExpiredException();
        }
        return token;
    }
View Full Code Here

                .build());
    }

    @Test
    public void verify() {
        VerificationToken token = new VerificationToken(new User(), VerificationToken.VerificationTokenType.emailVerification, 120);
        when(verificationTokenService.verify("123")).thenReturn(token);
        ClientResponse response = super.resource().path("verify/tokens/" + UUID.randomUUID())
                .accept(APPLICATION_JSON).post(ClientResponse.class);
        assertThat(response.getStatus(), is(200));
    }
View Full Code Here

        assertThat(response.getStatus(), is(200));
    }

    @Test
    public void generateEmailToken() {
        VerificationToken token = new VerificationToken(new User(), VerificationToken.VerificationTokenType.emailVerification, 120);
        when(verificationTokenService.generateEmailVerificationToken("test@example.com")).thenReturn(token);
        ClientResponse response = super.resource().path("verify/tokens").entity(new EmailVerificationRequest("test@example.com"), APPLICATION_JSON)
                .accept(APPLICATION_JSON).post(ClientResponse.class);
        assertThat(response.getStatus(), is(200));
    }
View Full Code Here

    @Test
    public void sendLostPasswordToken() {
        User user = generateTestUser();
        when(userRepository.findByEmailAddress(user.getEmailAddress())).thenReturn(user);
        VerificationToken token = verificationTokenService.sendLostPasswordToken(new LostPasswordRequest(user.getEmailAddress()));
        assertThat(user.getVerificationTokens().size(), is(1));
        assertThat(user.getActiveLostPasswordToken(), is(token));
        assertThat(token, is(not(Matchers.<Object>nullValue())));
        assertThat(tokens.size(), is(1));
        String sentToken = tokens.get(0);
        assertThat(sentToken, is(not(nullValue())));
        assertThat(sentToken, is(token.getToken()));
        assertThat(token.getTokenType(), is(VerificationToken.VerificationTokenType.lostPassword));

    }
View Full Code Here

TOP

Related Classes of com.porterhead.rest.user.domain.VerificationToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.