From 7cac4e155ceadf5d9ac5410b4a0d90fa23d019a8 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Thu, 22 Dec 2016 16:24:46 +0100 Subject: [PATCH] Moved email stuff to zutil and moved transoced to its own package --- WebContent/WEB-INF/web.xml | 2 +- Zallery.iml | 3 +- build.xml | 14 +- src/zall/Zallery.java | 7 +- src/zall/ZalleryAjax.java | 42 +- src/zall/ZalleryTranscoder.java | 364 ------------------ src/zall/action/RegisterAction.java | 3 +- src/zall/action/user/ModifyUserAction.java | 11 +- .../action/user/ModifyUserStatusAction.java | 4 +- .../user/SendVerificationEmailAction.java | 4 +- src/zall/action/user/VerifyEmailAction.java | 11 +- src/zall/bean/User.java | 7 - src/zall/bean/Video.java | 2 +- src/zall/transcoder/FrameGrabListener.java | 57 +++ src/zall/transcoder/MyVideoListener.java | 32 ++ src/zall/transcoder/ProgressListener.java | 45 +++ .../transcoder/VideoTranscoderListener.java | 76 ++++ src/zall/transcoder/ZalleryTranscoder.java | 199 ++++++++++ src/zall/util/Email.java | 97 ----- src/zall/util/ZalleryEmail.java | 75 ++++ 20 files changed, 518 insertions(+), 537 deletions(-) mode change 100644 => 100755 Zallery.iml mode change 100644 => 100755 src/zall/ZalleryAjax.java delete mode 100644 src/zall/ZalleryTranscoder.java mode change 100644 => 100755 src/zall/action/RegisterAction.java mode change 100644 => 100755 src/zall/action/user/ModifyUserAction.java mode change 100644 => 100755 src/zall/action/user/ModifyUserStatusAction.java mode change 100644 => 100755 src/zall/action/user/SendVerificationEmailAction.java mode change 100644 => 100755 src/zall/action/user/VerifyEmailAction.java mode change 100644 => 100755 src/zall/bean/User.java mode change 100644 => 100755 src/zall/bean/Video.java create mode 100755 src/zall/transcoder/FrameGrabListener.java create mode 100755 src/zall/transcoder/MyVideoListener.java create mode 100755 src/zall/transcoder/ProgressListener.java create mode 100755 src/zall/transcoder/VideoTranscoderListener.java create mode 100755 src/zall/transcoder/ZalleryTranscoder.java delete mode 100644 src/zall/util/Email.java create mode 100755 src/zall/util/ZalleryEmail.java diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml index 6a58f89..8f873ca 100755 --- a/WebContent/WEB-INF/web.xml +++ b/WebContent/WEB-INF/web.xml @@ -61,7 +61,7 @@ transcoder - zall.ZalleryTranscoder + zall.transcoder.ZalleryTranscoder 1 diff --git a/Zallery.iml b/Zallery.iml old mode 100644 new mode 100755 index 3bc42bd..5cdd1f3 --- a/Zallery.iml +++ b/Zallery.iml @@ -11,8 +11,7 @@ - - + diff --git a/build.xml b/build.xml index 3ffe6d7..61c7da9 100755 --- a/build.xml +++ b/build.xml @@ -23,10 +23,10 @@ - + - + @@ -40,7 +40,7 @@ - + @@ -56,10 +56,10 @@ - - - - + + + + diff --git a/src/zall/Zallery.java b/src/zall/Zallery.java index 5667864..cf252a4 100755 --- a/src/zall/Zallery.java +++ b/src/zall/Zallery.java @@ -22,7 +22,8 @@ import zall.bean.Folder; import zall.bean.Image; import zall.bean.Media; import zall.bean.User; -import zall.util.Email; +import zall.util.ZalleryEmail; +import zutil.net.smtp.Email; import zall.util.msg.UserMessage; import zall.util.msg.UserMessage.MessageType; import zutil.db.DBConnection; @@ -54,7 +55,7 @@ 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 += "/"; - Email.setServer( (String)context.lookup("java:comp/env/SMTP_HOST") ); + ZalleryEmail.setSMTPHost( (String)context.lookup("java:comp/env/SMTP_HOST") ); DATA_PATH = (String)context.lookup("java:comp/env/DATA_PATH"); LogUtil.setLevel("zall", Level.FINEST); @@ -93,7 +94,7 @@ public class Zallery extends HttpServlet{ if( action.equalsIgnoreCase("verfemail") ){ User verfuser = User.load(db, Long.parseLong(request.getParameter("id"))); if( verfuser.verifyEmail(request.getParameter("hash")) ){ - ZalleryAjax.sendEmailNewUserToAdmin(verfuser, db); + 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."); diff --git a/src/zall/ZalleryAjax.java b/src/zall/ZalleryAjax.java old mode 100644 new mode 100755 index c0b7470..07208ba --- a/src/zall/ZalleryAjax.java +++ b/src/zall/ZalleryAjax.java @@ -19,8 +19,8 @@ import zall.action.*; import zall.action.media.*; import zall.action.user.*; import zall.bean.*; -import zall.util.Email; -import zall.util.Email.ContentType; +import zutil.net.smtp.Email; +import zutil.net.smtp.Email.ContentType; import zall.util.msg.UserMessage; import zall.util.msg.UserMessage.MessageType; import zutil.db.DBConnection; @@ -57,7 +57,7 @@ public class ZalleryAjax extends HttpServlet{ protected void registerAction(ZalleryAction action){ if(actions == null) - actions = new HashMap(); + actions = new HashMap<>(); actions.put(action.getActionId().toLowerCase(), action); } @@ -76,7 +76,7 @@ public class ZalleryAjax extends HttpServlet{ /** * @param out is the PrintStream that will be used, no output will be generated if it is null */ - public void doGet(HttpServletRequest request, HttpServletResponse response, PrintWriter out) throws ServletException{ + private void doGet(HttpServletRequest request, HttpServletResponse response, PrintWriter out) throws ServletException{ DBConnection db = null; try { String actionStr = request.getParameter("action").toLowerCase(); @@ -126,38 +126,4 @@ public class ZalleryAjax extends HttpServlet{ if(db != null) db.close(); } } - - - public static void sendEmailVerification(User user) throws IOException{ - // Email - Email smtpEmail = new Email("admin@koc.se", user.getEmail()); - smtpEmail.setNiceFrom("Koc.se Admin"); - smtpEmail.setSubject("Registration at "+Zallery.getWebsiteName()); - smtpEmail.setContentType(ContentType.HTML); - smtpEmail.setMessage("You receive this message because you have requested an account" + - "
at "+Zallery.getWebsiteName()+". Please click the link to verify your email address: " + - "

"+Zallery.getWebsiteURL()+"?action=verfemail&id="+user.getId()+"&hash="+user.getEmailVerificationHash()+"" + - "

You will have to wait for an admin to activate your account after you have verified your email."); - smtpEmail.send(); - } - - public static void sendEmailNewUserToAdmin(User newuser, DBConnection db) throws SQLException, IOException{ - // Email the admin about new user - Email email = new Email("admin@koc.se", "admin@koc.se"); - email.setNiceFrom("Koc.se Admin"); - email.setSubject("New user activation request at "+Zallery.getWebsiteName()); - email.setContentType(ContentType.HTML); - email.setMessage("A new user has registered for an account at " + - ""+Zallery.getWebsiteName()+":" + - "

Email: " + newuser.getEmail() + "" + - "
Name: " + newuser.getName() + "" + - "
Facebook: "+newuser.getFacebookUid()+""); - List admins = User.loadSuperUsers(db); - for(User admin : admins){ - if( admin.isEmailVerified() ){ - email.setTo( admin.getEmail() ); - email.send(); - } - } - } } diff --git a/src/zall/ZalleryTranscoder.java b/src/zall/ZalleryTranscoder.java deleted file mode 100644 index 3a036b4..0000000 --- a/src/zall/ZalleryTranscoder.java +++ /dev/null @@ -1,364 +0,0 @@ -package zall; - -import java.io.File; -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; -import java.util.Queue; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.imageio.ImageIO; -import javax.servlet.ServletConfig; -import javax.servlet.http.HttpServlet; - -import com.xuggle.mediatool.IMediaReader; -import com.xuggle.mediatool.IMediaWriter; -import com.xuggle.mediatool.MediaToolAdapter; -import com.xuggle.mediatool.ToolFactory; -import com.xuggle.mediatool.event.AudioSamplesEvent; -import com.xuggle.mediatool.event.IAddStreamEvent; -import com.xuggle.mediatool.event.IAudioSamplesEvent; -import com.xuggle.mediatool.event.IVideoPictureEvent; -import com.xuggle.mediatool.event.VideoPictureEvent; -import com.xuggle.xuggler.IAudioResampler; -import com.xuggle.xuggler.IAudioSamples; -import com.xuggle.xuggler.ICodec; -import com.xuggle.xuggler.IStreamCoder; -import com.xuggle.xuggler.IVideoPicture; -import com.xuggle.xuggler.IVideoResampler; -import com.xuggle.xuggler.video.ConverterFactory; -import com.xuggle.xuggler.video.IConverter; - -import zall.bean.Media.Size; -import zall.bean.Video; -import zutil.StringUtil; -import zutil.db.DBConnection; -import zutil.log.LogUtil; - - -public class ZalleryTranscoder extends HttpServlet{ - private static final Logger logger = LogUtil.getLogger(); - private static final long serialVersionUID = 1L; - - // Media Queue - private static Queue

"+Zallery.getWebsiteURL()+"?action=verfemail&id="+user.getId()+"&hash="+user.getEmailVerificationHash()+"" + + "

You will have to wait for an admin to activate your account after you have verified your email."); + + SMTPClient smtp = new SMTPClient(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.setTo(user.getEmail()); + email.setSubject("Account activation at " + 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. " + + "" + Zallery.getWebsiteURL() + ""); + + SMTPClient smtp = new SMTPClient(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.setContentType(Email.ContentType.HTML); + email.setMessage("A new user has registered for an account at " + + ""+Zallery.getWebsiteName()+":" + + "

Email: " + user.getEmail() + "" + + "
Name: " + user.getName() + "" + ); + + SMTPClient smtp = new SMTPClient(host); + for(User admin : User.loadSuperUsers(db)){ + if( admin.isEmailVerified() ){ + email.setTo( admin.getEmail() ); + smtp.send(email); + } + } + smtp.close(); + } +}