Add email and username check
This commit is contained in:
parent
c713a7770f
commit
a6ea227980
|
@ -45,8 +45,6 @@ public class RegisterServlet extends HttpServlet {
|
|||
response.setContentType("text/html");
|
||||
PrintWriter printWriter = response.getWriter();
|
||||
|
||||
logger.info("Mphkaaa!!!");
|
||||
|
||||
String firstName = request.getParameter("first_name");
|
||||
String lastName = request.getParameter("last_name");
|
||||
String organization = request.getParameter("organization");
|
||||
|
@ -75,36 +73,52 @@ public class RegisterServlet extends HttpServlet {
|
|||
//
|
||||
// } else {
|
||||
|
||||
ldapActions.createUser(username, email, firstName, lastName, organization/*, password*/);
|
||||
logger.info("User successfully created");
|
||||
if (!ldapActions.usernameExists(username) && !ldapActions.emailExists(email)) {
|
||||
ldapActions.createUser(username, email, firstName, lastName, organization/*, password*/);
|
||||
logger.info("User successfully created");
|
||||
|
||||
UUID verificationCode = UUID.randomUUID();
|
||||
Date creationDate = new Date();
|
||||
UUID verificationCode = UUID.randomUUID();
|
||||
Date creationDate = new Date();
|
||||
|
||||
Timestamp timestamp = new Timestamp(creationDate.getTime());
|
||||
Timestamp timestamp = new Timestamp(creationDate.getTime());
|
||||
|
||||
if (!verificationActions.verificationEntryExists(username)) {
|
||||
verificationActions.addVerificationEntry(username, verificationCode.toString(), timestamp);
|
||||
if (!verificationActions.verificationEntryExists(username)) {
|
||||
verificationActions.addVerificationEntry(username, verificationCode.toString(), timestamp);
|
||||
|
||||
} else {
|
||||
verificationActions.updateVerificationEntry(username, verificationCode.toString(), timestamp);
|
||||
}
|
||||
} else {
|
||||
verificationActions.updateVerificationEntry(username, verificationCode.toString(), timestamp);
|
||||
}
|
||||
|
||||
String verificationCodeMsg = "Hello " + username + ",\n" +
|
||||
"\n" +
|
||||
"A request has been made to verify your email and activate your OpenAIRE account. To activate your\n" +
|
||||
"account, you will need to submit your username and this activation code in order to verify that the\n" +
|
||||
"request was legitimate.\n" +
|
||||
"\n" +
|
||||
"The activation code is " + verificationCode.toString() + "\n Thank you";
|
||||
String verificationCodeMsg = "Hello " + username + ",\n" +
|
||||
"\n" +
|
||||
"A request has been made to verify your email and activate your OpenAIRE account. To activate your\n" +
|
||||
"account, you will need to submit your username and this activation code in order to verify that the\n" +
|
||||
"request was legitimate.\n" +
|
||||
"\n" +
|
||||
"The activation code is " + verificationCode.toString() + "\n Thank you";
|
||||
|
||||
String verificationCodeSubject = "Your OpenAIRE password reset request";
|
||||
String verificationCodeSubject = "Your OpenAIRE password reset request";
|
||||
|
||||
emailSender.sendEmail(email, verificationCodeSubject, verificationCodeMsg);
|
||||
emailSender.sendEmail(email, verificationCodeSubject, verificationCodeMsg);
|
||||
|
||||
|
||||
response.sendRedirect("./activate.jsp");
|
||||
response.sendRedirect("./activate.jsp");
|
||||
// }
|
||||
} else {
|
||||
|
||||
if (ldapActions.usernameExists(username)) {
|
||||
request.getSession().setAttribute("username_message", "Username already exists! Choose another one.");
|
||||
logger.info("Username already exists");
|
||||
}
|
||||
|
||||
if (ldapActions.emailExists(email)) {
|
||||
request.getSession().setAttribute("email_message", "There is another user with this email.");
|
||||
logger.info("There is another user with this email");
|
||||
}
|
||||
|
||||
response.sendRedirect("./register.jsp");
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("LDAP error in creating user", e);
|
||||
|
|
|
@ -72,15 +72,15 @@
|
|||
<span class="msg_username_min_lenght uk-text-danger uk-text-small uk-float-left" style="display:none">Minimum username length 5 characters.</span>
|
||||
<span class="msg_username_max_lenght uk-text-danger uk-text-small uk-float-left" style="display:none">Maximum username lenght 150 characters.</span>
|
||||
<span class="msg_username_error uk-text-danger uk-text-small uk-float-left" style="display:none">Please enter your username.</span>
|
||||
<%--<span id="username_server_error" class="uk-text-danger uk-text-small uk-float-left">${username_message}</span>--%>
|
||||
<%--<c:remove var="username_message" scope="session" />--%>
|
||||
<span id="username_server_error" class="uk-text-danger uk-text-small uk-float-left">${username_message}</span>
|
||||
<c:remove var="username_message" scope="session" />
|
||||
<input id="username" name="username" type="text" placeholder="Username (*)" class="form-control"></div>
|
||||
<div class="form-group">
|
||||
<span class="msg_email_error uk-text-danger uk-text-small uk-float-left" style="display:none">Please enter your email.</span>
|
||||
<span class="msg_email_validation_error uk-text-danger uk-text-small uk-float-left" style="display:none">Please enter a valid email.</span>
|
||||
<span class="msg_email_conf_error uk-text-danger uk-text-small uk-float-left" style="display:none">These emails don't match.</span>
|
||||
<%--<span id="email_server_error" class="uk-text-danger uk-text-small uk-float-left">${email_message}</span>--%>
|
||||
<%--<c:remove var="email_message" scope="session" />--%>
|
||||
<span id="email_server_error" class="uk-text-danger uk-text-small uk-float-left">${email_message}</span>
|
||||
<c:remove var="email_message" scope="session" />
|
||||
<input id="email" name="email" type="text" placeholder="Email (*)" class="form-control"></div>
|
||||
<div class="form-group">
|
||||
<input id="email_conf" name="email_conf" type="text" placeholder="Confirm email (*)" class="form-control"></div>
|
||||
|
@ -189,14 +189,14 @@
|
|||
$("#username").focusin(function () {
|
||||
$(this).removeClass('aai-form-danger');
|
||||
$(".msg_username_error").fadeOut();
|
||||
// $(".username_server_error").fadeOut();
|
||||
$("#username_server_error").fadeOut();
|
||||
});
|
||||
|
||||
$("#email").focusin(function () {
|
||||
$(this).removeClass('aai-form-danger');
|
||||
$(".msg_email_error").fadeOut();
|
||||
$(".msg_email_validation_error").fadeOut();
|
||||
// $(".email_server_error").fadeOut();
|
||||
$("#email_server_error").fadeOut();
|
||||
});
|
||||
|
||||
$("#email_conf").focusin(function () {
|
||||
|
|
Loading…
Reference in New Issue