updated email templates
This commit is contained in:
parent
de503bd441
commit
467151abd0
14 changed files with 106 additions and 81 deletions
|
|
@ -1,31 +1,18 @@
|
|||
package zall;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import zall.bean.Folder;
|
||||
import zall.bean.Image;
|
||||
import zall.bean.Media;
|
||||
import zall.bean.User;
|
||||
import zall.manager.AuthenticationManager;
|
||||
import zall.util.ZalleryEmail;
|
||||
import zall.util.UserMessage;
|
||||
import zall.util.UserMessage.MessageType;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
|
|
@ -36,6 +23,9 @@ public class Zallery extends HttpServlet{
|
|||
|
||||
public static String WEBSITE_NAME = "Example.com";
|
||||
public static String WEBSITE_URL = "http://example.com";
|
||||
public static String WEBSITE_EMAIL = "admin@example.com";
|
||||
public static String WEBSITE_EMAIL_NICE = "Example.com Admin";
|
||||
public static String SMTP_HOST = "localhost";
|
||||
public static String ROOT_PATH = "";
|
||||
public static String DATA_PATH = "";
|
||||
|
||||
|
|
@ -60,7 +50,10 @@ public class Zallery extends HttpServlet{
|
|||
WEBSITE_URL = (String)context.lookup("java:comp/env/WEBSITE_URL");
|
||||
if( WEBSITE_URL.charAt(WEBSITE_URL.length()-1) != '/')
|
||||
WEBSITE_URL += "/";
|
||||
ZalleryEmail.setSMTPHost( (String)context.lookup("java:comp/env/SMTP_HOST") );
|
||||
|
||||
WEBSITE_EMAIL = (String)context.lookup("java:comp/env/WEBSITE_EMAIL");
|
||||
WEBSITE_EMAIL_NICE = (String)context.lookup("java:comp/env/WEBSITE_EMAIL_NICE");
|
||||
SMTP_HOST = (String)context.lookup("java:comp/env/WEBSITE_EMAIL_NICE");
|
||||
DATA_PATH = (String)context.lookup("java:comp/env/DATA_PATH");
|
||||
|
||||
LogUtil.setLevel("zall", Level.FINEST);
|
||||
|
|
|
|||
|
|
@ -24,9 +24,7 @@ public abstract class ZalleryServlet extends HttpServlet {
|
|||
public final void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
|
||||
DBConnection db = null;
|
||||
try {
|
||||
include("header.jsp", request, response);
|
||||
doGet(request, response, db = Zallery.getDB());
|
||||
include("footer.jsp", request, response);
|
||||
} catch (ServletException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
|
|
@ -42,9 +40,7 @@ public abstract class ZalleryServlet extends HttpServlet {
|
|||
public final void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
|
||||
DBConnection db = null;
|
||||
try {
|
||||
include("header.jsp", request, response);
|
||||
doPost(request, response, db = Zallery.getDB());
|
||||
include("footer.jsp", request, response);
|
||||
} catch (ServletException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -8,10 +8,9 @@ import javax.servlet.annotation.WebFilter;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* This filter will check if user is valid if not will redirect to /login page
|
||||
* This filter will check if user is isValid if not will redirect to /login page
|
||||
*/
|
||||
@WebFilter(urlPatterns = "/")
|
||||
public class AuthenticationFilter implements Filter {
|
||||
|
|
@ -26,8 +25,8 @@ public class AuthenticationFilter implements Filter {
|
|||
String requestURI = ((HttpServletRequest) request).getRequestURI();
|
||||
User user = null;
|
||||
|
||||
// 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, (HttpServletRequest) request)) {
|
||||
// continue the request via the filter pipeline if it is login page or it is a isValid User
|
||||
if (requestURI.equals(LOGIN_URI) || AuthenticationManager.isValid(user, (HttpServletRequest) request)) {
|
||||
chain.doFilter(request, response);
|
||||
} else {
|
||||
// do not continue the filter pipeline but respond back to client
|
||||
|
|
|
|||
|
|
@ -17,3 +17,11 @@ error.not.found.email=Please provide a valid email!
|
|||
error.not.found.password=Please provide a valid password!
|
||||
error.incorrect.password.matching=Provided passwords do not match!
|
||||
error.email_exists=An account with that email already exists!
|
||||
email.activation.title=Account activation at
|
||||
email.activation.body=Your account has now been activated. You can now login and use the site.
|
||||
email.activation.request.title=New user activation request at
|
||||
email.activation.request.body=A new user has registered for an account at
|
||||
email.registration.title=Registration at
|
||||
email.registration.body1=You receive this message because you have requested an account at
|
||||
email.registration.body2=Please click the link below to verify your email address:
|
||||
email.registration.body3=You will have to wait for an admin to activate your account after you have verified your email.
|
||||
|
|
@ -55,9 +55,9 @@ public class AuthenticationManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return true if the user has a valid authentication session
|
||||
* @return true if the user has a isValid authentication session
|
||||
*/
|
||||
public static boolean valid(User user, HttpServletRequest request) {
|
||||
public static boolean isValid(User user, HttpServletRequest request) {
|
||||
if(user == null)
|
||||
return false;
|
||||
if(!user.isEnabled())
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import java.util.logging.Logger;
|
|||
public class GalleryServlet extends ZalleryServlet {
|
||||
private static Logger logger = LogUtil.getLogger();
|
||||
|
||||
public static final String JSP_FILE = "gallery.jsp";
|
||||
public static final String JSP_FILE = "page_gallery.jsp";
|
||||
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response, DBConnection db) throws SQLException, IOException, ServletException {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import java.util.logging.Logger;
|
|||
public class LoginServlet extends ZalleryServlet {
|
||||
private static Logger logger = LogUtil.getLogger();
|
||||
|
||||
private static final String JSP_FILE = "register.jsp";
|
||||
private static final String JSP_FILE = "page_login.jsp";
|
||||
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response, DBConnection db) throws ServletException, IOException {
|
||||
|
|
@ -44,5 +44,7 @@ public class LoginServlet extends ZalleryServlet {
|
|||
else {
|
||||
msgs.add(UserMessage.MessageType.ERROR, lang.getString("error.incorrect.user_or_pass"));
|
||||
}
|
||||
|
||||
doGet(request, response, db);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import java.util.logging.Logger;
|
|||
public class MediaServlet extends ZalleryServlet {
|
||||
private static Logger logger = LogUtil.getLogger();
|
||||
|
||||
private static final String JSP_FILE = "media.jsp";
|
||||
private static final String JSP_FILE = "page_media.jsp";
|
||||
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response, DBConnection db) throws ServletException, SQLException, IOException {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import java.util.logging.Logger;
|
|||
public class ProfileServlet extends ZalleryServlet {
|
||||
private static Logger logger = LogUtil.getLogger();
|
||||
|
||||
private static final String JSP_FILE = "profile.jsp";
|
||||
private static final String JSP_FILE = "page_profile.jsp";
|
||||
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response, DBConnection db) throws ServletException, IOException, SQLException {
|
||||
|
|
@ -42,7 +42,7 @@ public class ProfileServlet extends ZalleryServlet {
|
|||
}
|
||||
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response, DBConnection db) throws SQLException, IOException {
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response, DBConnection db) throws SQLException, IOException, ServletException {
|
||||
doGet(request, response, db);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ package zall.page;
|
|||
|
||||
import zall.ZalleryServlet;
|
||||
import zall.bean.User;
|
||||
import zall.util.UserMessage.MessageType;
|
||||
import zall.util.ZalleryEmail;
|
||||
import zall.util.UserMessage;
|
||||
import zutil.ObjectUtil;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
|
|
@ -18,7 +20,7 @@ import java.util.logging.Logger;
|
|||
public class RegisterServlet extends ZalleryServlet {
|
||||
private static Logger logger = LogUtil.getLogger();
|
||||
|
||||
private static final String JSP_FILE = "register.jsp";
|
||||
private static final String JSP_FILE = "page_register.jsp";
|
||||
|
||||
private static final String INPUT_ID_FIRST_NAME = "first-name";
|
||||
private static final String INPUT_ID_LAST_NAME = "last-name";
|
||||
|
|
@ -27,7 +29,26 @@ public class RegisterServlet extends ZalleryServlet {
|
|||
private static final String INPUT_ID_PASSWORD_REPEATE = "password-re";
|
||||
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response, DBConnection db) throws ServletException, IOException {
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response, DBConnection db) throws ServletException, IOException, SQLException {
|
||||
UserMessage msgs = UserMessage.getUserMessage(request.getSession());
|
||||
|
||||
// Verify email address
|
||||
String verifyEmailHash = request.getParameter("verifyemail");
|
||||
if(!ObjectUtil.isEmpty(verifyEmailHash)){
|
||||
User verfUser = User.load(db, Long.parseLong(request.getParameter("id")));
|
||||
if (verfUser != null) {
|
||||
if( verfUser.verifyEmail(request.getParameter("hash")) ){
|
||||
ZalleryEmail.sendNewUserRegistrationToAdmin(verfUser, db);
|
||||
verfUser.save(db);
|
||||
msgs.add(MessageType.INFO, "Your email has been successfully verified.");
|
||||
msgs.add(MessageType.WARNING, "The account is waiting account activation by an admin.");
|
||||
}
|
||||
else
|
||||
msgs.add(MessageType.ERROR, "Email verification failed!");
|
||||
}
|
||||
else msgs.add(MessageType.ERROR, "Invalid user id: "+request.getParameter("id"));
|
||||
}
|
||||
|
||||
include(JSP_FILE, request, response);
|
||||
}
|
||||
|
||||
|
|
@ -46,20 +67,20 @@ public class RegisterServlet extends ZalleryServlet {
|
|||
String passwordRe = (String)request.getAttribute(INPUT_ID_PASSWORD_REPEATE);
|
||||
|
||||
if (firstName == null)
|
||||
msgs.add(UserMessage.MessageType.ERROR, lang.getString("error.not.found.first.name"));
|
||||
msgs.add(MessageType.ERROR, lang.getString("error.not.found.first.name"));
|
||||
if (lastName == null)
|
||||
msgs.add(UserMessage.MessageType.ERROR, lang.getString("error.not.found.last.name"));
|
||||
msgs.add(MessageType.ERROR, lang.getString("error.not.found.last.name"));
|
||||
if (email == null)
|
||||
msgs.add(UserMessage.MessageType.ERROR, lang.getString("error.not.found.email"));
|
||||
msgs.add(MessageType.ERROR, lang.getString("error.not.found.email"));
|
||||
if (password == null)
|
||||
msgs.add(UserMessage.MessageType.ERROR, lang.getString("error.not.found.password"));
|
||||
msgs.add(MessageType.ERROR, lang.getString("error.not.found.password"));
|
||||
if (passwordRe == null)
|
||||
msgs.add(UserMessage.MessageType.ERROR, lang.getString("error.not.found.password"));
|
||||
msgs.add(MessageType.ERROR, lang.getString("error.not.found.password"));
|
||||
else if (passwordRe.equals(password))
|
||||
msgs.add(UserMessage.MessageType.ERROR, lang.getString("error.incorrect.password.matching"));
|
||||
msgs.add(MessageType.ERROR, lang.getString("error.incorrect.password.matching"));
|
||||
|
||||
if(User.load(db, (String)request.getAttribute(INPUT_ID_EMAIL)) != null){
|
||||
msgs.add(UserMessage.MessageType.ERROR, lang.getString("error.email_exists"));
|
||||
msgs.add(MessageType.ERROR, lang.getString("error.email_exists"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -75,9 +96,9 @@ public class RegisterServlet extends ZalleryServlet {
|
|||
ZalleryEmail.sendVerificationEmail( user );
|
||||
request.getSession().setAttribute("user", user);
|
||||
logger.info("Registered new user: "+user.getName()+".");
|
||||
msgs.add(UserMessage.MessageType.INFO,
|
||||
msgs.add(MessageType.INFO,
|
||||
lang.getString("info.created.account") + " " + lang.getString("info.sent.email.verification"));
|
||||
|
||||
include(JSP_FILE, request, response);
|
||||
forward("/login", request, response);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import java.util.logging.Logger;
|
|||
public class SlideshowServlet extends ZalleryServlet {
|
||||
private static Logger logger = LogUtil.getLogger();
|
||||
|
||||
private static final String JSP_FILE = "slideshow.jsp";
|
||||
private static final String JSP_FILE = "page_slideshow.jsp";
|
||||
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response, DBConnection db) throws ServletException, SQLException, IOException {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import java.util.logging.Logger;
|
|||
public class UserListServlet extends ZalleryServlet {
|
||||
private static Logger logger = LogUtil.getLogger();
|
||||
|
||||
private static final String JSP_FILE = "users.jsp";
|
||||
private static final String JSP_FILE = "page_users.jsp";
|
||||
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response, DBConnection db) throws ServletException, SQLException, IOException {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import java.util.logging.Logger;
|
|||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
|
||||
import com.xuggle.mediatool.IMediaReader;
|
||||
|
|
@ -37,7 +38,7 @@ import zutil.StringUtil;
|
|||
import zutil.db.DBConnection;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
|
||||
@WebServlet(value = "/transcoder", loadOnStartup = 1)
|
||||
public class ZalleryTranscoder extends HttpServlet{
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
@ -48,11 +49,11 @@ public class ZalleryTranscoder extends HttpServlet{
|
|||
|
||||
public void init( ServletConfig config ){
|
||||
try{
|
||||
transcodingQueue = new LinkedList<Video>();
|
||||
transcodingQueue = new LinkedList<>();
|
||||
worker = new TranscoderThread();
|
||||
worker.start();
|
||||
|
||||
// get untranscoded videos
|
||||
// get not transcoded videos
|
||||
DBConnection db = null;
|
||||
try {
|
||||
db = Zallery.getDB();
|
||||
|
|
|
|||
|
|
@ -2,67 +2,72 @@ package zall.util;
|
|||
|
||||
import zall.Zallery;
|
||||
import zall.bean.User;
|
||||
import zall.manager.AuthenticationManager;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.net.smtp.Email;
|
||||
import zutil.net.smtp.SmtpClient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Locale;
|
||||
import java.util.PropertyResourceBundle;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import static zall.ZalleryConstant.LANG_BASENAME;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ZalleryEmail {
|
||||
private static String host;
|
||||
|
||||
public static void setSMTPHost(String host){
|
||||
ZalleryEmail.host = host;
|
||||
}
|
||||
private static ResourceBundle lang = PropertyResourceBundle.getBundle(LANG_BASENAME, Locale.getDefault());
|
||||
|
||||
public static void sendVerificationEmail(User user) throws IOException {
|
||||
// Email
|
||||
Email email = new Email();
|
||||
email.setFrom("admin@koc.se", "Koc.se Admin");
|
||||
email.setTo(user.getEmail());
|
||||
email.setSubject("Registration at "+ Zallery.getWebsiteName());
|
||||
email.setContentType(Email.ContentType.HTML);
|
||||
email.setMessage("You receive this message because you have requested an account" +
|
||||
"<br>at "+Zallery.getWebsiteName()+". Please click the link to verify your email address: " +
|
||||
"<p><a href='"+Zallery.getWebsiteURL()+"?action=verfemail&id="+user.getId()+"&hash="+user.generateEmailVerificationHash()+"'>"+Zallery.getWebsiteURL()+"?action=verfemail&id="+user.getId()+"&hash="+user.generateEmailVerificationHash()+"</a>" +
|
||||
"<p> You will have to wait for an admin to activate your account after you have verified your email.");
|
||||
String verifyUrl = Zallery.getWebsiteURL() + "?verfemail=" + user.generateEmailVerificationHash() + "&id=" + user.getId();
|
||||
|
||||
SmtpClient smtp = new SmtpClient(host);
|
||||
Email email = new Email();
|
||||
email.setFrom(Zallery.WEBSITE_EMAIL, Zallery.WEBSITE_EMAIL_NICE);
|
||||
email.setTo(user.getEmail());
|
||||
email.setSubject(lang.getString("email.registration.title") + Zallery.getWebsiteName());
|
||||
email.setContentType(Email.ContentType.HTML);
|
||||
email.setMessage(
|
||||
lang.getString("email.registration.body1") + " " + Zallery.getWebsiteName() + "." +
|
||||
"<br>" + lang.getString("email.registration.body2") +
|
||||
"<p><a href='" + verifyUrl + "'>" + verifyUrl + "</a>" +
|
||||
"<p>" + lang.getString("email.registration.body3"));
|
||||
|
||||
SmtpClient smtp = new SmtpClient(Zallery.SMTP_HOST);
|
||||
smtp.send(email);
|
||||
smtp.close();
|
||||
}
|
||||
|
||||
public static void sendActivationEmail(User user) throws IOException {
|
||||
Email email = new Email();
|
||||
email.setFrom("admin@koc.se", "Koc.se Admin");
|
||||
email.setFrom(Zallery.WEBSITE_EMAIL, Zallery.WEBSITE_EMAIL_NICE);
|
||||
email.setTo(user.getEmail());
|
||||
email.setSubject("Account activation at " + Zallery.getWebsiteName());
|
||||
email.setSubject(lang.getString("email.activation.title") + " " + Zallery.getWebsiteName());
|
||||
email.setContentType(Email.ContentType.HTML);
|
||||
email.setMessage("Your account has now been activated by an admin. You can now login and use the site. " +
|
||||
"<a href='" + Zallery.getWebsiteURL() + "'>" + Zallery.getWebsiteURL() + "</a>");
|
||||
email.setMessage(
|
||||
lang.getString("email.activation.body") +
|
||||
"<br><a href='" + Zallery.getWebsiteURL() + "'>" + Zallery.getWebsiteURL() + "</a>");
|
||||
|
||||
SmtpClient smtp = new SmtpClient(host);
|
||||
SmtpClient smtp = new SmtpClient(Zallery.SMTP_HOST);
|
||||
smtp.send(email);
|
||||
smtp.close();
|
||||
}
|
||||
|
||||
public static void sendNewUserRegistrationToAdmin(User user, DBConnection db) throws SQLException, IOException {
|
||||
// Email the admin about new user
|
||||
Email email = new Email();
|
||||
email.setFrom("admin@koc.se", "Koc.se Admin");
|
||||
email.setSubject("New user activation request at "+Zallery.getWebsiteName());
|
||||
email.setFrom(Zallery.WEBSITE_EMAIL, Zallery.WEBSITE_EMAIL_NICE);
|
||||
email.setSubject(lang.getString("email.activation.request.title") + " " + Zallery.getWebsiteName());
|
||||
email.setContentType(Email.ContentType.HTML);
|
||||
email.setMessage("A new user has registered for an account at " +
|
||||
email.setMessage(
|
||||
lang.getString("email.activation.request.body") +
|
||||
" <a href='" + Zallery.getWebsiteURL() + "'>" + Zallery.getWebsiteName() + "</a>:" +
|
||||
"<p>Email: <b>" + user.getEmail() + "</b>" +
|
||||
"<br>Name: <b>" + user.getName() + "</b>"
|
||||
);
|
||||
|
||||
SmtpClient smtp = new SmtpClient(host);
|
||||
SmtpClient smtp = new SmtpClient(Zallery.SMTP_HOST);
|
||||
for (User admin : User.loadSuperUsers(db)) {
|
||||
if (admin.isEmailVerified()) {
|
||||
email.setTo(admin.getEmail());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue