19 package org.turro.contacts.zul.register;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import org.turro.string.Strings;
26 import org.apache.commons.mail.EmailException;
27 import org.turro.action.IRegisterCallback;
28 import org.turro.annotation.ElephantPlugin;
29 import org.turro.auth.Authentication;
30 import org.turro.collections.KeyValueMap;
31 import org.turro.contacts.SignUp;
32 import org.turro.contacts.db.ContactsPU;
33 import org.turro.elephant.context.Application;
34 import org.turro.elephant.context.ElephantContext;
35 import org.turro.elephant.context.IConstructor;
36 import org.turro.elephant.direct.AbstractDirectEntityCtrl;
37 import org.turro.elephant.direct.DirectContent;
38 import org.turro.i18n.I_;
39 import org.turro.jpa.Dao;
40 import org.turro.mail.sender.MailPool;
41 import org.turro.marker.ElephantMarker;
47 @ElephantPlugin(label=
"signup-ctrl")
48 @DirectContent(identifier=
"signup-action")
52 super(
"widgets/auth",
"user");
59 marker.
put(
"type",
"sign-up");
60 marker.
put(
"actionLink", createFormAction());
72 String type = map.get(
"type");
73 if(
"sign-up".equals(type)) {
74 processSignUp(constructor, map);
80 throw new UnsupportedOperationException(
"Not supported yet.");
83 private void processSignUp(
IConstructor constructor, KeyValueMap map) {
93 }
else if(existEmail(su.
getEmail())) {
104 private boolean isValidMap(KeyValueMap map) {
105 return !Strings.isBlank(map.get(
"name")) && !Strings.isBlank(map.get(
"email"));
108 private SignUp existPending(String email) {
109 Dao dao =
new ContactsPU();
110 List l = dao.getResultList(
111 "select c from SignUp c where c.email = ? and confirmed = FALSE",
112 new Object[] { email }
114 return !l.isEmpty() ? (SignUp) l.get(0) :
null;
117 private static boolean existEmail(String email) {
118 Dao dao =
new ContactsPU();
119 List l = dao.getResultList(
120 "select c from Connector c where c.value = ?",
121 new Object[] { email }
124 l = dao.getResultList(
125 "select c from SignUp c where c.email = ? and confirmed = TRUE",
126 new Object[] { email }
132 private void sendEmail(SignUp signUp) {
135 .addUser(signUp.getName(), signUp.getEmail())
136 .put(
"signUp", signUp)
137 .sendTemplate(
"sign-pending", I_.get(
"Email pending to confirm") +
" : " + ElephantContext.getSiteName());
138 IRegisterCallback regcall = (IRegisterCallback) Application.getApplication().getConstructor()
139 .getSessionAttribute(IRegisterCallback.REGISTER_CALLBACK_KEY);
140 if(regcall !=
null) {
141 regcall.onRegister(signUp.getEmail());
143 }
catch (EmailException ex) {
144 Logger.getLogger(SignUpCtrl.class.getName()).log(Level.SEVERE,
null, ex);
148 private String keepValues(KeyValueMap map) {
149 HashMap<String, String> keep =
new HashMap<>();
150 for(String key : map.keySet()) {
151 if(key.startsWith(
"su_")) {
152 keep.put(key, map.get(key));
155 return keep.isEmpty() ? null : KeyValueMap.format(keep);
static boolean sendReminder(IConstructor constructor, String name, String email)
Object put(Object key, Object value)