@@ -0,0 +1,1958 @@
+package de.terrestris.shogun2.service;%0A%0Aimport java.util.UUID;%0A%0Aimport org.apache.log4j.Logger;%0Aimport org.hibernate.criterion.Criterion;%0Aimport org.hibernate.criterion.Restrictions;%0Aimport org.hibernate.criterion.SimpleExpression;%0Aimport org.springframework.stereotype.Service;%0A%0Aimport de.terrestris.shogun2.model.User;%0Aimport de.terrestris.shogun2.model.token.PasswordResetToken;%0A%0A/**%0A *%0A * @author Daniel Koch%0A *%0A */%0A@Service(%22passwordResetService%22)%0Apublic class PasswordResetTokenService extends AbstractCrudService%3CPasswordResetToken%3E %7B%0A%0A%09/**%0A%09 * The Logger%0A%09 */%0A%09private static final Logger LOG =%0A%09%09%09Logger.getLogger(PasswordResetTokenService.class);%0A%0A%09/**%0A%09 *%0A%09 * @param user%0A%09 * @return%0A%09 */%0A%09public PasswordResetToken findByUser(User user) %7B%0A%0A%09%09SimpleExpression eqEmail = Restrictions.eq(%22user%22, user);%0A%09%09PasswordResetToken passwordResetToken =%0A%09%09%09%09dao.findByUniqueCriteria(eqEmail);%0A%0A%09%09return passwordResetToken;%0A%09%7D%0A%0A%09/**%0A%09 *%0A%09 * @return%0A%09 */%0A%09public PasswordResetToken findByIdAndToken(int id, String token) %7B%0A%0A%09%09Criterion criteria = Restrictions.and(%0A%09%09%09%09Restrictions.eq(%22id%22, id),%0A%09%09%09%09Restrictions.eq(%22token%22, token)%0A%09%09);%0A%0A%09%09PasswordResetToken passwordResetToken = %0A%09%09%09%09dao.findByUniqueCriteria(criteria);%0A%0A%09%09return passwordResetToken;%0A%09%7D%0A%0A%09/**%0A%09 *%0A%09 * @param user%0A%09 * @return%0A%09 */%0A%09public PasswordResetToken generateResetPasswordToken(User user) %7B%0A%0A%09%09PasswordResetToken passwordResetToken;%0A%0A%09%09String token = UUID.randomUUID().toString();%0A%0A%09%09// check if the user has an open reset request / not used token%0A%09%09passwordResetToken = findByUser(user);%0A%0A%09%09// if so, delete it%0A%09%09if (passwordResetToken != null) %7B%0A%09%09%09LOG.debug(%22User has an open request already, delete it first%22);%0A%09%09%09dao.delete(passwordResetToken);%0A%09%09%7D%0A%0A%09%09// and create a blank new one%0A%09%09passwordResetToken = new PasswordResetToken();%0A%09%09passwordResetToken.setUser(user);%0A%09%09passwordResetToken.setToken(token);%0A%0A%09%09dao.saveOrUpdate(passwordResetToken);%0A%0A%09%09return passwordResetToken;%0A%09%7D%0A%0A%7D%0A

Add PasswordResetToken service class