19 package org.turro.contacts.zul.register;
22 import java.io.IOException;
23 import java.io.UnsupportedEncodingException;
24 import java.util.HashMap;
25 import java.util.List;
28 import java.util.logging.Level;
29 import java.util.logging.Logger;
30 import org.amic.util.file.FileUtil;
31 import org.turro.string.Strings;
32 import org.apache.commons.mail.EmailException;
33 import org.turro.action.Actions;
34 import org.turro.action.IRegisterCallback;
35 import org.turro.action.MailSenders;
36 import org.turro.action.PushSenders;
37 import org.turro.collections.KeyValueMap;
38 import org.turro.contacts.Connector;
39 import org.turro.contacts.Contact;
40 import org.turro.contacts.SignUp;
41 import org.turro.contacts.db.ContactsPU;
42 import org.turro.contacts.form.ContactWrapper;
43 import org.turro.contacts.profile.ProfileContext;
44 import org.turro.elephant.TemplateControl;
45 import org.turro.elephant.context.Application;
46 import org.turro.elephant.context.ElephantContext;
47 import org.turro.elephant.context.IConstructor;
48 import org.turro.elephant.security.IUser;
49 import org.turro.elephant.util.Messages;
50 import org.turro.elephant.web.tags.SessionTags;
51 import org.turro.i18n.I_;
52 import org.turro.jpa.Dao;
53 import org.turro.mail.sender.MailPool;
54 import org.turro.marker.ElephantMarker;
55 import org.turro.security.SecurityGroup;
56 import org.turro.security.SocialGroups;
57 import org.turro.zkoss.dialog.SelectionDialog;
58 import org.turro.zkoss.layout.TabbedContent;
59 import org.zkoss.zk.ui.event.Event;
60 import org.zkoss.zk.ui.select.annotation.Listen;
61 import org.zkoss.zk.ui.select.annotation.Wire;
62 import org.zkoss.zk.ui.util.Clients;
63 import org.zkoss.zul.Checkbox;
64 import org.zkoss.zul.Hlayout;
65 import org.zkoss.zul.Textbox;
77 private Textbox email;
80 private Checkbox student;
82 @Wire(
"#professional")
83 private Checkbox professional;
86 private Textbox comment;
89 private Checkbox accepted;
92 private Hlayout termsrow;
94 @Listen(
"onCheck = #accepted")
96 if(termsBox !=
null) {
97 if(accepted.isChecked()) {
105 @Listen(
"onClick = #register")
118 Clients.showNotification(
I_.
format(
"Confirmation e-mail has been sent to %s", sue.
getEmail()));
119 }
catch (EmailException ex) {
123 }
else if(existEmail(su.
getEmail())) {
127 if(termsrow.isVisible() && accepted !=
null && !accepted.isChecked()) {
128 Clients.showNotification(
I_.
get(
"Read and accepted") +
"?");
133 Clients.showNotification(
I_.
format(
"Confirmation e-mail has been sent to %s", su.
getEmail()));
134 }
catch (EmailException ex) {
140 Clients.showNotification(
"No valid values");
148 if(termsBox !=
null) {
149 accepted.setDisabled(
false);
155 private static boolean existEmail(String email) {
157 List l = dao.getResultList(
158 "select c from Connector c where c.value = ?",
159 new Object[] { email }
162 l = dao.getResultList(
163 "select c from SignUp c where c.email = ? and confirmed = TRUE",
164 new Object[] { email }
170 private boolean existPending(String email) {
171 Dao dao =
new ContactsPU();
172 List l = dao.getResultList(
173 "select c from SignUp c where c.email = ? and confirmed = FALSE",
174 new Object[] { email }
177 sue = (SignUp) l.iterator().next();
182 private boolean sendEmail(SignUp signUp)
throws EmailException {
184 .addUser(signUp.getName(), signUp.getEmail())
185 .put(
"signUp", signUp)
186 .sendTemplate(
"sign-pending", I_.get(
"Email pending to confirm") +
" : " + ElephantContext.getSiteName());
187 IRegisterCallback regcall = (IRegisterCallback) Application.getApplication().getConstructor()
188 .getSessionAttribute(IRegisterCallback.REGISTER_CALLBACK_KEY);
189 if(regcall !=
null) {
190 regcall.onRegister(signUp.getEmail());
196 if(!Strings.isBlank(
id)) {
206 sendWelcomeMailToUser(su);
217 if(signUp !=
null && signUp.isConfirmed()) {
218 em.
put(
"signUp", signUp);
221 }
catch (Exception ex) {
224 em.
process(
"signup",
"confirmed");
226 em.
process(
"signup",
"failed");
231 if(!existEmail(signUp.getEmail())) {
233 contact.
setName(signUp.getName());
242 KeyValueMap kvm = signUp.getValues();
243 for(String key : kvm.keySet()) {
244 if(!Strings.isBlank(key) && !Strings.isBlank(kvm.get(key))) {
252 }
catch(Exception ex) {}
261 private static void sendMailToAdmin(
SignUp signUp) {
269 private static void sendWelcomeMailToUser(
SignUp signUp)
throws UnsupportedEncodingException, EmailException {
270 Map args =
new HashMap();
271 args.put(
"signUp", signUp);
274 }
catch (Exception ex) {
275 Logger.getLogger(RegisterControl.class.getName()).log(Level.SEVERE,
ElephantContext.
logMsg(
null), ex);
280 .sendTemplate(
"sign-welcome", I_.get(
"Welcome") +
" : " + ElephantContext.getSiteName());
283 private void createTermsOfUse() {
284 File dir =
new File(ElephantContext.getRealPath(
"/_internal/terms"));
286 for(File f : dir.listFiles((File dir1, String name1) -> name1.endsWith(
".txt"))) {
292 private TabbedContent termsBox;
294 private void createTab(File f) {
295 if(termsBox ==
null) {
296 termsBox =
new TabbedContent();
297 termsBox.setVflex(
"true");
298 termsBox.setStyle(
"width:100%");
299 termsrow.setVisible(
true);
301 Textbox text =
new Textbox();
302 text.setReadonly(
true);
303 text.setMultiline(
true);
304 text.setVflex(
"true");
305 text.setHflex(
"true");
307 text.setValue(FileUtil.getContent(f, ElephantContext.getEncoding()));
308 termsBox.addContent(FileUtil.getBaseName(f), text);
309 }
catch (IOException ex) {
310 Logger.getLogger(RegisterControl.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
314 private String keepValues() {
315 HashMap<String, String> keep =
new HashMap<>();
316 if(professional.isVisible() && professional.isChecked()) {
317 keep.put(
"su_professional",
"true");
319 if(student.isVisible() && student.isChecked()) {
320 keep.put(
"su_student",
"true");
322 String webTags = SessionTags.get().path();
323 if(!Strings.isBlank(webTags)) {
324 keep.put(
"webTags", webTags);
326 return keep.isEmpty() ? null : KeyValueMap.format(keep);
static String createAction(String email, String redir)
static String createRightNowAction(String values)
static IMailSender getPool()
static IPushSender getPool()
static boolean hasCompanies()
static boolean hasCenters()
abstract void sendRedirect(String uri)
static Application getApplication()
static String getSiteSyndicate()
static String getServerUrl(String scheme)
static String getRootWebPath()
static String logMsg(String msg)
static Messages confirmProcess()
Messages add(String word)
static String format(String msg, Object... arguments)
static String get(String msg)
void setFull(String full)
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
static void syndicate(List< Contact > contacts, Set< String > socialGroupIds, Dao dao)
static void showComponent(Page page, String title, Component component, String width, String height, final Command command)
static final String CONNECTOR_EMAIL