added language file
This commit is contained in:
parent
26ab7c9dd9
commit
8d5786d458
5 changed files with 102 additions and 16 deletions
|
|
@ -17,24 +17,29 @@
|
||||||
<div class="form-bottom">
|
<div class="form-bottom">
|
||||||
<form role="form" action="" method="post" class="registration-form">
|
<form role="form" action="" method="post" class="registration-form">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="sr-only" for="form-first-name">First name</label>
|
<label class="sr-only" for="first-name">First name</label>
|
||||||
<input type="text" name="form-first-name" placeholder="First name..."
|
<input type="text" placeholder="First name..." class="form-first-name form-control"
|
||||||
class="form-first-name form-control" id="form-first-name">
|
name="first-name" id="first-name">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="sr-only" for="form-last-name">Last name</label>
|
<label class="sr-only" for="last-name">Last name</label>
|
||||||
<input type="text" name="form-last-name" placeholder="Last name..."
|
<input type="text" placeholder="Last name..." class="form-last-name form-control"
|
||||||
class="form-last-name form-control" id="form-last-name">
|
name="last-name" id="last-name">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="sr-only" for="form-email">Email</label>
|
<label class="sr-only" for="email">Email</label>
|
||||||
<input type="text" name="form-email" placeholder="Email..." class="form-email form-control"
|
<input type="text" placeholder="Email..." class="form-email form-control"
|
||||||
id="form-email">
|
name="email" id="email">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="sr-only" for="form-about-yourself">About yourself</label>
|
<label class="sr-only" for="password">About yourself</label>
|
||||||
<textarea name="form-about-yourself" placeholder="About yourself..."
|
<textarea placeholder="About yourself..." class="form-about-yourself form-control"
|
||||||
class="form-about-yourself form-control" id="form-about-yourself"></textarea>
|
name="password" id="password"></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="sr-only" for="password">About yourself</label>
|
||||||
|
<textarea placeholder="About yourself..." class="form-about-yourself form-control"
|
||||||
|
name="password-re" id="password-re"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn">Sign me up!</button>
|
<button type="submit" class="btn">Sign me up!</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,9 @@ public interface ZalleryConstant {
|
||||||
|
|
||||||
String SESSION_KEY_USER = "zal_user";
|
String SESSION_KEY_USER = "zal_user";
|
||||||
String SESSION_KEY_AUTH_HASH = "zal_session_hash";
|
String SESSION_KEY_AUTH_HASH = "zal_session_hash";
|
||||||
|
|
||||||
|
/** Language Key Constants **/
|
||||||
|
|
||||||
|
String LANG_BASENAME = "zallery_lang";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ public class AuthenticationFilter implements Filter {
|
||||||
User user = null;
|
User user = null;
|
||||||
|
|
||||||
// continue the request via the filter pipeline if it is login page or it is a valid User
|
// continue the request via the filter pipeline if it is login page or it is a valid User
|
||||||
if (requestURI.equals(LOGIN_URI) || AuthenticationManager.valid(user)) {
|
if (requestURI.equals(LOGIN_URI) || AuthenticationManager.valid(user, (HttpServletRequest) request)) {
|
||||||
chain.doFilter(request, response);
|
chain.doFilter(request, response);
|
||||||
} else {
|
} else {
|
||||||
// do not continue the filter pipeline but respond back to client
|
// do not continue the filter pipeline but respond back to client
|
||||||
|
|
|
||||||
4
src/zall/lang/zallery_lang_en.properties
Executable file
4
src/zall/lang/zallery_lang_en.properties
Executable file
|
|
@ -0,0 +1,4 @@
|
||||||
|
error.email_exsists=An account with that email already exists!
|
||||||
|
error.first_name_missing="Please provide a valid First Name!"
|
||||||
|
info.verification_email_sent="A verification email has been sent, please click the link to continue."
|
||||||
|
info.account_created="Your account has successfully been created."
|
||||||
|
|
@ -1,21 +1,93 @@
|
||||||
package zall.servlet;
|
package zall.servlet;
|
||||||
|
|
||||||
import javax.servlet.RequestDispatcher;
|
import zall.bean.User;
|
||||||
|
import zall.util.DbHttpServlet;
|
||||||
|
import zall.util.ZalleryEmail;
|
||||||
|
import zall.util.msg.UserMessage;
|
||||||
|
import zall.util.msg.UserMessage.MessageType;
|
||||||
|
import zutil.db.DBConnection;
|
||||||
|
import zutil.log.LogUtil;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.annotation.WebServlet;
|
import javax.servlet.annotation.WebServlet;
|
||||||
import javax.servlet.http.HttpServlet;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.PropertyResourceBundle;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static zall.ZalleryConstant.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@WebServlet(urlPatterns = "/register")
|
@WebServlet(urlPatterns = "/register")
|
||||||
public class RegisterServlet extends HttpServlet {
|
public class RegisterServlet extends DbHttpServlet {
|
||||||
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
|
|
||||||
private static final String JSP_FILE = "register.jsp";
|
private static final String JSP_FILE = "register.jsp";
|
||||||
|
|
||||||
|
private static final String INPUT_ID_FIRST_NAME = "first-name";
|
||||||
|
private static final String INPUT_ID_LAST_NAME = "last-name";
|
||||||
|
private static final String INPUT_ID_EMAIL = "email";
|
||||||
|
private static final String INPUT_ID_PASSWORD = "password";
|
||||||
|
private static final String INPUT_ID_PASSWORD_REPEATE = "password-re";
|
||||||
|
|
||||||
|
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
getServletContext().getRequestDispatcher("/"+JSP_FILE).include(req, resp);
|
getServletContext().getRequestDispatcher("/"+JSP_FILE).include(req, resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp, DBConnection db) throws ServletException, IOException, SQLException {
|
||||||
|
UserMessage msgHandler = UserMessage.getUserMessage(req.getSession());
|
||||||
|
ResourceBundle lang = PropertyResourceBundle.getBundle(LANG_BASENAME, Locale.getDefault());
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check inputs
|
||||||
|
*/
|
||||||
|
|
||||||
|
String firstName = (String)req.getAttribute(INPUT_ID_FIRST_NAME);
|
||||||
|
String lastName = (String)req.getAttribute(INPUT_ID_LAST_NAME);
|
||||||
|
String email = (String)req.getAttribute(INPUT_ID_EMAIL);
|
||||||
|
String password = (String)req.getAttribute(INPUT_ID_PASSWORD);
|
||||||
|
String passwordRe = (String)req.getAttribute(INPUT_ID_PASSWORD_REPEATE);
|
||||||
|
|
||||||
|
if (firstName == null)
|
||||||
|
msgHandler.add(MessageType.ERROR, lang.getString("error.first_name_missing"));
|
||||||
|
if (lastName == null)
|
||||||
|
msgHandler.add(MessageType.ERROR, lang.getString("error.last_name_missing"));
|
||||||
|
if (email == null)
|
||||||
|
msgHandler.add(MessageType.ERROR, lang.getString("error.email_missing"));
|
||||||
|
if (password == null)
|
||||||
|
msgHandler.add(MessageType.ERROR, lang.getString("error.password_missing"));
|
||||||
|
if (passwordRe == null)
|
||||||
|
msgHandler.add(MessageType.ERROR, lang.getString("error.password_missing"));
|
||||||
|
else if (passwordRe.equals(password))
|
||||||
|
msgHandler.add(MessageType.ERROR, lang.getString("error.password_not_matching"));
|
||||||
|
|
||||||
|
if(User.load(db, (String)req.getAttribute(INPUT_ID_EMAIL)) != null){
|
||||||
|
msgHandler.add(MessageType.ERROR, lang.getString("error.email_exsists"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create new user
|
||||||
|
*/
|
||||||
|
|
||||||
|
User user = new User();
|
||||||
|
user.setName(firstName + " " + lastName);
|
||||||
|
user.setEmail(email);
|
||||||
|
user.setPassword(password);
|
||||||
|
user.save(db);
|
||||||
|
ZalleryEmail.sendVerificationEmail( user );
|
||||||
|
req.getSession().setAttribute("user", user);
|
||||||
|
logger.info("Registered new user: "+user.getName()+".");
|
||||||
|
msgHandler.add(MessageType.INFO,
|
||||||
|
lang.getString("info.account_created") + lang.getString("info.verification_email_sent"));
|
||||||
|
|
||||||
|
getServletContext().getRequestDispatcher("/"+JSP_FILE).include(req, resp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue