Mercurial Hosting > nabble
comparison src/nabble/view/web/mailing_list/Subscribe.java @ 0:7ecd1a4ef557
add content
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Thu, 21 Mar 2019 19:15:52 -0600 |
| parents | |
| children | 18cf4872fd7f |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:7ecd1a4ef557 |
|---|---|
| 1 | |
| 2 package nabble.view.web.mailing_list; | |
| 3 | |
| 4 import fschmidt.util.mail.Mail; | |
| 5 import fschmidt.util.servlet.ServletUtils; | |
| 6 import nabble.model.Init; | |
| 7 import nabble.model.ListServer; | |
| 8 import nabble.model.MailingList; | |
| 9 import nabble.model.ModelHome; | |
| 10 import nabble.model.Executors; | |
| 11 import nabble.model.Node; | |
| 12 import nabble.model.User; | |
| 13 import nabble.view.lib.Jtp; | |
| 14 import nabble.view.lib.SubscribeDefaultsMail; | |
| 15 import org.slf4j.Logger; | |
| 16 import org.slf4j.LoggerFactory; | |
| 17 | |
| 18 import javax.servlet.ServletException; | |
| 19 import javax.servlet.http.HttpServlet; | |
| 20 import javax.servlet.http.HttpServletRequest; | |
| 21 import javax.servlet.http.HttpServletResponse; | |
| 22 import java.io.IOException; | |
| 23 import java.util.concurrent.TimeUnit; | |
| 24 | |
| 25 | |
| 26 public final class Subscribe extends HttpServlet { | |
| 27 | |
| 28 private static final Logger logger = LoggerFactory.getLogger(Subscribe.class); | |
| 29 | |
| 30 private final static long secondsUntilDeliveryOffMail = Init.get("secondsUntilDeliveryOffMail",20*60); // why so long? | |
| 31 | |
| 32 protected void service(HttpServletRequest request,HttpServletResponse response) | |
| 33 throws ServletException, IOException | |
| 34 { | |
| 35 User user = Jtp.getUser(request,response); | |
| 36 if (user == null) { | |
| 37 Jtp.login("You must login to be able to subscribe to a list.",request,response); | |
| 38 return; | |
| 39 } | |
| 40 Node forum = Jtp.getSiteNotNull(request).getNode(Long.parseLong(request.getParameter("forum"))); | |
| 41 MailingList mailingList = forum.getAssociatedMailingList(); | |
| 42 Mail userSubscribeMail = mailingList.subscribeMail(user); | |
| 43 ModelHome.send(userSubscribeMail); | |
| 44 logger.info("subscription request from "+user.getEmail()+" to "+mailingList.getListAddress()); | |
| 45 | |
| 46 if (mailingList.getListServer().needsDefaults() && mailingList.getListServer() != ListServer.google) { | |
| 47 String url = ServletUtils.getContextURL(request) + "/mailing_list/SubscribeDefaults.jtp?forum="+forum.getId()+"&k="+mailingList.getPassword(user); | |
| 48 final Mail mail = SubscribeDefaultsMail.newMail(user.getEmail(), mailingList, url); | |
| 49 Executors.schedule( | |
| 50 new Runnable(){public void run(){ | |
| 51 ModelHome.send(mail); | |
| 52 }}, secondsUntilDeliveryOffMail, TimeUnit.SECONDS | |
| 53 ); | |
| 54 } | |
| 55 response.sendRedirect("Subscribe2.jtp?forum="+forum.getId()); | |
| 56 } | |
| 57 } | |
| 58 |
