Moved email stuff to zutil and moved transoced to its own package

This commit is contained in:
Ziver Koc 2016-12-22 16:24:46 +01:00
parent 05048442a1
commit 7cac4e155c
20 changed files with 518 additions and 537 deletions

42
src/zall/ZalleryAjax.java Normal file → Executable file
View file

@ -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<String,ZalleryAction>();
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" +
"<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.getEmailVerificationHash()+"'>"+Zallery.getWebsiteURL()+"?action=verfemail&id="+user.getId()+"&hash="+user.getEmailVerificationHash()+"</a>" +
"<p> 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 " +
"<a href='"+Zallery.getWebsiteURL()+"'>"+Zallery.getWebsiteName()+"</a>:" +
"<p>Email: <b>" + newuser.getEmail() + "</b>" +
"<br>Name: <b>" + newuser.getName() + "</b>" +
"<br>Facebook: <a href='http://www.facebook.com/profile.php?id="+newuser.getFacebookUid()+"'>"+newuser.getFacebookUid()+"</a>");
List<User> admins = User.loadSuperUsers(db);
for(User admin : admins){
if( admin.isEmailVerified() ){
email.setTo( admin.getEmail() );
email.send();
}
}
}
}