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);
}
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;
}
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;
}
Aggregations