Revision 49683
Added by Sofia Baltzi over 6 years ago
RegisterServlet.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.openaire.usermanagement; |
2 | 2 |
|
3 |
import eu.dnetlib.openaire.user.utils.EmailSender; |
|
3 | 4 |
import eu.dnetlib.openaire.user.utils.LDAPActions; |
4 | 5 |
import eu.dnetlib.openaire.user.utils.VerificationActions; |
5 | 6 |
import org.apache.log4j.Logger; |
... | ... | |
13 | 14 |
import javax.servlet.http.HttpServletResponse; |
14 | 15 |
import java.io.IOException; |
15 | 16 |
import java.io.PrintWriter; |
17 |
import java.sql.Timestamp; |
|
18 |
import java.util.Date; |
|
19 |
import java.util.UUID; |
|
16 | 20 |
|
17 | 21 |
/** |
18 | 22 |
* Created by sofia on 20/10/2017. |
... | ... | |
29 | 33 |
private VerificationActions verificationActions; |
30 | 34 |
|
31 | 35 |
@Autowired |
36 |
private EmailSender emailSender; |
|
37 |
|
|
38 |
@Autowired |
|
32 | 39 |
private LDAPActions ldapActions; |
33 | 40 |
|
34 | 41 |
private Logger logger = Logger.getLogger(RegisterServlet.class); |
... | ... | |
55 | 62 |
if (firstName != null && lastName != null && username != null && |
56 | 63 |
email.equals(confirmEmail) /*&& password.equals(confirmPassword)*/ ) { |
57 | 64 |
try { |
58 |
ldapActions.createUser(username, email, firstName, lastName, organization/*, password*/); |
|
59 |
logger.info("User successfully created"); |
|
65 |
|
|
66 |
// if (ldapActions.usernameExists(username)) { |
|
67 |
// request.getSession().setAttribute("username_message", "Username already exists! Choose another one."); |
|
68 |
// logger.info("Username already exists"); |
|
69 |
// response.sendRedirect("./register.jsp"); |
|
70 |
// |
|
71 |
// } else if (ldapActions.emailExists(email)) { |
|
72 |
// request.getSession().setAttribute("email_message", "There is another user with this email."); |
|
73 |
// logger.info("There is another user with this email"); |
|
74 |
// response.sendRedirect("./register.jsp"); |
|
75 |
// |
|
76 |
// } else { |
|
77 |
|
|
78 |
ldapActions.createUser(username, email, firstName, lastName, organization/*, password*/); |
|
79 |
logger.info("User successfully created"); |
|
80 |
|
|
81 |
UUID verificationCode = UUID.randomUUID(); |
|
82 |
Date creationDate = new Date(); |
|
83 |
|
|
84 |
Timestamp timestamp = new Timestamp(creationDate.getTime()); |
|
85 |
|
|
86 |
if (!verificationActions.verificationEntryExists(username)) { |
|
87 |
verificationActions.addVerificationEntry(username, verificationCode.toString(), timestamp); |
|
88 |
|
|
89 |
} else { |
|
90 |
verificationActions.updateVerificationEntry(username, verificationCode.toString(), timestamp); |
|
91 |
} |
|
92 |
|
|
93 |
String verificationCodeMsg = "Hello " + username + ",\n" + |
|
94 |
"\n" + |
|
95 |
"A request has been made to verify your email and activate your OpenAIRE account. To activate your\n" + |
|
96 |
"account, you will need to submit your username and this activation code in order to verify that the\n" + |
|
97 |
"request was legitimate.\n" + |
|
98 |
"\n" + |
|
99 |
"The activation code is " + verificationCode.toString() + "\n Thank you"; |
|
100 |
|
|
101 |
String verificationCodeSubject = "Your OpenAIRE password reset request"; |
|
102 |
|
|
103 |
emailSender.sendEmail(email, verificationCodeSubject, verificationCodeMsg); |
|
104 |
|
|
105 |
|
|
106 |
response.sendRedirect("./activate.jsp"); |
|
107 |
// } |
|
108 |
|
|
60 | 109 |
} catch (Exception e) { |
61 | 110 |
logger.error("LDAP error in creating user", e); |
62 | 111 |
response.sendRedirect("./error.jsp"); |
63 | 112 |
} |
64 | 113 |
} |
65 |
response.sendRedirect("./activate.jsp"); |
|
66 | 114 |
printWriter.close(); |
67 | 115 |
|
68 | 116 |
} |
Also available in: Unified diff
Add emailSender at register