Add email and username check

This commit is contained in:
Sofia Baltzi 2017-10-26 13:10:30 +00:00
parent c713a7770f
commit a6ea227980
2 changed files with 42 additions and 28 deletions

View File

@ -45,8 +45,6 @@ public class RegisterServlet extends HttpServlet {
response.setContentType("text/html"); response.setContentType("text/html");
PrintWriter printWriter = response.getWriter(); PrintWriter printWriter = response.getWriter();
logger.info("Mphkaaa!!!");
String firstName = request.getParameter("first_name"); String firstName = request.getParameter("first_name");
String lastName = request.getParameter("last_name"); String lastName = request.getParameter("last_name");
String organization = request.getParameter("organization"); String organization = request.getParameter("organization");
@ -75,36 +73,52 @@ public class RegisterServlet extends HttpServlet {
// //
// } else { // } else {
ldapActions.createUser(username, email, firstName, lastName, organization/*, password*/); if (!ldapActions.usernameExists(username) && !ldapActions.emailExists(email)) {
logger.info("User successfully created"); ldapActions.createUser(username, email, firstName, lastName, organization/*, password*/);
logger.info("User successfully created");
UUID verificationCode = UUID.randomUUID(); UUID verificationCode = UUID.randomUUID();
Date creationDate = new Date(); Date creationDate = new Date();
Timestamp timestamp = new Timestamp(creationDate.getTime()); Timestamp timestamp = new Timestamp(creationDate.getTime());
if (!verificationActions.verificationEntryExists(username)) { if (!verificationActions.verificationEntryExists(username)) {
verificationActions.addVerificationEntry(username, verificationCode.toString(), timestamp); verificationActions.addVerificationEntry(username, verificationCode.toString(), timestamp);
} else { } else {
verificationActions.updateVerificationEntry(username, verificationCode.toString(), timestamp); verificationActions.updateVerificationEntry(username, verificationCode.toString(), timestamp);
} }
String verificationCodeMsg = "Hello " + username + ",\n" + String verificationCodeMsg = "Hello " + username + ",\n" +
"\n" + "\n" +
"A request has been made to verify your email and activate your OpenAIRE account. To activate your\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" + "account, you will need to submit your username and this activation code in order to verify that the\n" +
"request was legitimate.\n" + "request was legitimate.\n" +
"\n" + "\n" +
"The activation code is " + verificationCode.toString() + "\n Thank you"; "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) { } catch (Exception e) {
logger.error("LDAP error in creating user", e); logger.error("LDAP error in creating user", e);

View File

@ -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_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_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 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>--%> <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" />--%> <c:remove var="username_message" scope="session" />
<input id="username" name="username" type="text" placeholder="Username (*)" class="form-control"></div> <input id="username" name="username" type="text" placeholder="Username (*)" class="form-control"></div>
<div class="form-group"> <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_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_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 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>--%> <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" />--%> <c:remove var="email_message" scope="session" />
<input id="email" name="email" type="text" placeholder="Email (*)" class="form-control"></div> <input id="email" name="email" type="text" placeholder="Email (*)" class="form-control"></div>
<div class="form-group"> <div class="form-group">
<input id="email_conf" name="email_conf" type="text" placeholder="Confirm email (*)" class="form-control"></div> <input id="email_conf" name="email_conf" type="text" placeholder="Confirm email (*)" class="form-control"></div>
@ -189,14 +189,14 @@
$("#username").focusin(function () { $("#username").focusin(function () {
$(this).removeClass('aai-form-danger'); $(this).removeClass('aai-form-danger');
$(".msg_username_error").fadeOut(); $(".msg_username_error").fadeOut();
// $(".username_server_error").fadeOut(); $("#username_server_error").fadeOut();
}); });
$("#email").focusin(function () { $("#email").focusin(function () {
$(this).removeClass('aai-form-danger'); $(this).removeClass('aai-form-danger');
$(".msg_email_error").fadeOut(); $(".msg_email_error").fadeOut();
$(".msg_email_validation_error").fadeOut(); $(".msg_email_validation_error").fadeOut();
// $(".email_server_error").fadeOut(); $("#email_server_error").fadeOut();
}); });
$("#email_conf").focusin(function () { $("#email_conf").focusin(function () {