19 package org.turro.contacts.zul.register;
21 import java.util.List;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import org.apache.commons.mail.EmailException;
25 import org.turro.action.MailSenders;
26 import org.turro.auth.Authentication;
27 import org.turro.contacts.SignUp;
28 import org.turro.contacts.db.ContactsPU;
29 import org.turro.elephant.TemplateControl;
30 import org.turro.elephant.context.ElephantContext;
31 import org.turro.elephant.impl.util.StringParser;
32 import org.turro.elephant.util.Messages;
33 import org.turro.i18n.I_;
34 import org.turro.jpa.Dao;
35 import org.turro.plugin.contacts.IContact;
36 import org.zkoss.zk.ui.event.Event;
37 import org.zkoss.zk.ui.select.annotation.Listen;
38 import org.zkoss.zk.ui.select.annotation.Wire;
39 import org.zkoss.zk.ui.util.Clients;
40 import org.zkoss.zul.Textbox;
52 private Textbox email;
55 private Textbox comment;
59 @Listen(
"onClick = #register")
70 Clients.showNotification(
I_.
format(
"Confirmation e-mail has been sent to %s", sue.
getEmail()));
72 }
else if(existEmail(su.
getEmail())) {
77 Clients.showNotification(
I_.
format(
"Confirmation e-mail has been sent to %s", su.
getEmail()));
80 Clients.showNotification(
"No valid values");
84 private static boolean existEmail(String email) {
86 List l = dao.getResultList(
87 "select c from Connector c where c.value = ?",
88 new Object[] { email }
91 l = dao.getResultList(
92 "select c from SignUp c where c.email = ? and confirmed = TRUE",
93 new Object[] { email }
99 private boolean existPending(String email) {
100 Dao dao =
new ContactsPU();
101 List l = dao.getResultList(
102 "select c from SignUp c where c.email = ? and confirmed = FALSE",
103 new Object[] { email }
106 sue = (SignUp) l.iterator().next();
111 private boolean sendEmail(SignUp signUp) {
113 IContact contact = Authentication.getIContact();
114 if(contact ==
null || !contact.isValid()) {
117 MailSenders.getPool()
118 .addUser(signUp.getName(), signUp.getEmail())
119 .put(
"signUp", signUp)
120 .put(
"contact", contact)
121 .put(
"motive", I_.format(
"%s would like you to signup in %s", contact.getName(), ElephantContext.getSiteName()))
122 .put(
"comment", StringParser.toHTML(signUp.getComment()))
123 .sendTemplate(
"sign-tellsomeone",
124 I_.format(
"%s would like you to signup in %s", contact.getName(), ElephantContext.getSiteName()));
125 sendMailToAdmin(signUp, contact);
127 }
catch (EmailException ex) {
128 Logger.getLogger(TellSomeoneControl.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
133 private static void sendMailToAdmin(SignUp signUp, IContact contact) {
134 MailSenders.getPool()
136 .send(
"User wants friend to register",
137 contact.getName() +
" -> " + signUp.getName() +
141 signUp.getComment());
static Messages confirmProcess()
Messages add(String word)
static String format(String msg, Object... arguments)
static String get(String msg)