Search in sources :

Example 16 with VerificationToken

use of org.craftercms.profile.api.VerificationToken in project profile by craftercms.

the class VerificationServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(permissionEvaluator.isAllowed(anyString(), anyString())).thenReturn(true);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            VerificationToken token = (VerificationToken) invocation.getArguments()[0];
            token.setId(TOKEN_ID);
            return token;
        }
    }).when(tokenRepository).insert(any(VerificationToken.class));
    when(tokenRepository.findByStringId(TOKEN_ID)).thenReturn(getToken());
    when(emailFactory.getEmail(FROM, TO, null, null, SUBJECT, TEMPLATE_NAME, VERIFICATION_TEMPLATE_ARGS, true)).thenReturn(email);
    verificationService = new VerificationServiceImpl();
    verificationService.setPermissionEvaluator(permissionEvaluator);
    verificationService.setTokenRepository(tokenRepository);
    verificationService.setEmailFactory(emailFactory);
    verificationService.setTokenMaxAge(TOKEN_MAX_AGE);
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) VerificationToken(org.craftercms.profile.api.VerificationToken) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Before(org.junit.Before)

Example 17 with VerificationToken

use of org.craftercms.profile.api.VerificationToken in project profile by craftercms.

the class ProfileServiceImpl method changePassword.

@Override
public Profile changePassword(String resetTokenId, final String newPassword, final String... attributesToReturn) throws ProfileException {
    VerificationToken token = verificationService.getToken(resetTokenId);
    if (token == null) {
        throw new NoSuchVerificationTokenException(resetTokenId);
    }
    Profile profile = updateProfile(token.getProfileId(), profileUpdater -> profileUpdater.setPassword(CryptoUtils.hashPassword(newPassword)), attributesToReturn);
    verificationService.deleteToken(resetTokenId);
    logger.debug(LOG_KEY_PASSWORD_CHANGED, profile.getId().toString());
    return profile;
}
Also used : NoSuchVerificationTokenException(org.craftercms.profile.exceptions.NoSuchVerificationTokenException) VerificationToken(org.craftercms.profile.api.VerificationToken) Profile(org.craftercms.profile.api.Profile)

Example 18 with VerificationToken

use of org.craftercms.profile.api.VerificationToken in project profile by craftercms.

the class ProfileServiceImpl method resetPassword.

@Override
public Profile resetPassword(String profileId, String resetPasswordUrl, String... attributesToReturn) throws ProfileException {
    Profile profile = getNonNullProfile(profileId, attributesToReturn);
    VerificationToken token = verificationService.createToken(profile);
    verificationService.sendEmail(token, profile, resetPasswordUrl, resetPwdEmailFromAddress, resetPwdEmailSubject, resetPwdEmailTemplateName);
    return profile;
}
Also used : VerificationToken(org.craftercms.profile.api.VerificationToken) Profile(org.craftercms.profile.api.Profile)

Aggregations

VerificationToken (org.craftercms.profile.api.VerificationToken)18 Profile (org.craftercms.profile.api.Profile)12 Test (org.junit.Test)10 Date (java.util.Date)4 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)3 MongoDataException (org.craftercms.commons.mongo.MongoDataException)2 AttributeDefinition (org.craftercms.profile.api.AttributeDefinition)2 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)2 NoSuchVerificationTokenException (org.craftercms.profile.exceptions.NoSuchVerificationTokenException)2 Before (org.junit.Before)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 ObjectId (org.bson.types.ObjectId)1 DuplicateKeyException (org.craftercms.commons.mongo.DuplicateKeyException)1 Tenant (org.craftercms.profile.api.Tenant)1 InvalidEmailAddressException (org.craftercms.profile.exceptions.InvalidEmailAddressException)1 ProfileExistsException (org.craftercms.profile.exceptions.ProfileExistsException)1