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,6 +73,7 @@ public class RegisterServlet extends HttpServlet {
// //
// } else { // } else {
if (!ldapActions.usernameExists(username) && !ldapActions.emailExists(email)) {
ldapActions.createUser(username, email, firstName, lastName, organization/*, password*/); ldapActions.createUser(username, email, firstName, lastName, organization/*, password*/);
logger.info("User successfully created"); logger.info("User successfully created");
@ -105,6 +104,21 @@ public class RegisterServlet extends HttpServlet {
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 () {