mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
recover password (wip)
This commit is contained in:
@@ -44,4 +44,19 @@ public class UserDAO extends GenericDAO<User> {
|
||||
return user;
|
||||
}
|
||||
|
||||
public User findByEmail(String email) {
|
||||
CriteriaQuery<User> query = builder.createQuery(getType());
|
||||
Root<User> root = query.from(getType());
|
||||
query.where(builder.equal(root.get(User_.email), email));
|
||||
TypedQuery<User> q = em.createQuery(query);
|
||||
|
||||
User user = null;
|
||||
try {
|
||||
user = q.getSingleResult();
|
||||
} catch (NoResultException e) {
|
||||
user = null;
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,6 +43,12 @@ public class User extends AbstractModel {
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date lastLogin;
|
||||
|
||||
@Column(length = 40)
|
||||
private String recoverPasswordToken;
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date recoverPasswordTokenDate;
|
||||
|
||||
@OneToMany(mappedBy = "user", cascade = CascadeType.PERSIST)
|
||||
private Set<UserRole> roles = Sets.newHashSet();
|
||||
|
||||
@@ -110,4 +116,20 @@ public class User extends AbstractModel {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
public String getRecoverPasswordToken() {
|
||||
return recoverPasswordToken;
|
||||
}
|
||||
|
||||
public void setRecoverPasswordToken(String recoverPasswordToken) {
|
||||
this.recoverPasswordToken = recoverPasswordToken;
|
||||
}
|
||||
|
||||
public Date getRecoverPasswordTokenDate() {
|
||||
return recoverPasswordTokenDate;
|
||||
}
|
||||
|
||||
public void setRecoverPasswordTokenDate(Date recoverPasswordTokenDate) {
|
||||
this.recoverPasswordTokenDate = recoverPasswordTokenDate;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,8 +20,10 @@ import com.google.api.client.util.Lists;
|
||||
|
||||
@Stateless
|
||||
public class FeedSubscriptionService {
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@ApplicationException
|
||||
public class FeedSubscriptionException extends RuntimeException {
|
||||
public static class FeedSubscriptionException extends RuntimeException {
|
||||
public FeedSubscriptionException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
@@ -51,10 +53,10 @@ public class FeedSubscriptionService {
|
||||
final String pubUrl = applicationSettingsService.get().getPublicUrl();
|
||||
if (pubUrl == null) {
|
||||
throw new FeedSubscriptionException(
|
||||
"Public URL of this CommaFeed is unset");
|
||||
"Public URL of this CommaFeed is unset");
|
||||
}
|
||||
if (url.startsWith(pubUrl)) {
|
||||
throw new RuntimeException(
|
||||
throw new FeedSubscriptionException(
|
||||
"Could not subscribe to a feed from this CommaFeed instance");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.commafeed.backend.services;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.mail.Authenticator;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.PasswordAuthentication;
|
||||
import javax.mail.Session;
|
||||
@@ -10,35 +12,47 @@ import javax.mail.Transport;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.commafeed.backend.model.ApplicationSettings;
|
||||
import com.commafeed.backend.model.User;
|
||||
|
||||
public class MailService {
|
||||
@SuppressWarnings("serial")
|
||||
public class MailService implements Serializable {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(MailService.class);
|
||||
|
||||
@Inject
|
||||
ApplicationSettingsService applicationSettingsService;
|
||||
|
||||
public void sendMail(User user, String subject, String content) throws Exception {
|
||||
public void sendMail(User user, String subject, String content)
|
||||
throws Exception {
|
||||
|
||||
ApplicationSettings settings = applicationSettingsService.get();
|
||||
|
||||
|
||||
final String username = settings.getSmtpUserName();
|
||||
final String password = settings.getSmtpPassword();
|
||||
|
||||
|
||||
log.info(username);
|
||||
log.info(password);
|
||||
log.info("" + settings.isSmtpTls());
|
||||
log.info(settings.getSmtpHost());
|
||||
log.info("" + settings.getSmtpPort());
|
||||
|
||||
String dest = user.getEmail();
|
||||
|
||||
Properties props = new Properties();
|
||||
props.put("mail.smtp.auth", "true");
|
||||
props.put("mail.smtp.starttls.enable", settings.isSmtpTls());
|
||||
props.put("mail.smtp.starttls.enable", "" + settings.isSmtpTls());
|
||||
props.put("mail.smtp.host", settings.getSmtpHost());
|
||||
props.put("mail.smtp.port", settings.getSmtpPort());
|
||||
props.put("mail.smtp.port", "" + settings.getSmtpPort());
|
||||
|
||||
Session session = Session.getInstance(props,
|
||||
new javax.mail.Authenticator() {
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
Session session = Session.getInstance(props, new Authenticator() {
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
|
||||
Message message = new MimeMessage(session);
|
||||
message.setFrom(new InternetAddress(username, "CommaFeed"));
|
||||
|
||||
@@ -2,10 +2,13 @@ package com.commafeed.backend.services;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import com.commafeed.backend.dao.FeedCategoryDAO;
|
||||
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||
@@ -94,4 +97,10 @@ public class UserService {
|
||||
userRoleDAO.delete(userRoleDAO.findAll(user));
|
||||
userDAO.delete(user);
|
||||
}
|
||||
|
||||
public String generateApiKey(User user) {
|
||||
byte[] key = encryptionService.getEncryptedPassword(UUID.randomUUID()
|
||||
.toString(), user.getSalt());
|
||||
return DigestUtils.sha1Hex(key);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user