1 64 package com.jcorporate.expresso.services.validation; 65 66 import com.jcorporate.expresso.core.controller.Controller; 67 import com.jcorporate.expresso.core.controller.ControllerException; 68 import com.jcorporate.expresso.core.controller.ControllerRequest; 69 import com.jcorporate.expresso.core.controller.ControllerResponse; 70 import com.jcorporate.expresso.core.controller.NonHandleableException; 71 import com.jcorporate.expresso.core.controller.Transition; 72 import com.jcorporate.expresso.core.db.DBException; 73 import com.jcorporate.expresso.core.i18n.Messages; 74 import com.jcorporate.expresso.core.misc.StringUtil; 75 import com.jcorporate.expresso.core.security.User; 76 import com.jcorporate.expresso.services.dbobj.Setup; 77 78 import java.util.Hashtable ; 79 import java.util.Vector ; 80 81 82 90 public class LoginEmailValidator implements ValidationHandler { 91 95 public LoginEmailValidator() { 96 super(); 97 } 98 99 114 public void notify(Hashtable params, String URL) 115 throws AuthValidationException { 116 String dbName = (String ) params.get("db"); 119 120 String loginName = (String ) params.get("UserName"); 122 123 try { 124 User myUser = new User(); 126 myUser.setDataContext(dbName); 127 myUser.setLoginName(loginName); 128 129 if (!myUser.find()) { 130 throw new AuthValidationException("User with login \"" + 131 loginName + "\" not found"); 132 } 133 134 Vector addresses = new Vector (0); 136 addresses.add(myUser.getEmail()); 137 138 Object [] args = { 139 loginName, URL, Setup.getValue(dbName, "CompanyName"), 140 Setup.getValue(dbName, "HomePageURL") 141 }; 142 143 ValidationEntry.notifyByEmail(dbName, 145 Setup.getValue(dbName, "MAILFrom"), addresses, 146 getString("loginReqSubject"), getString("loginReqEM1", args)); 147 } catch (DBException dbe) { 148 throw new AuthValidationException("DB error accessing user \"" + 149 loginName + "\"", dbe); 150 } 151 } 152 153 172 public ControllerResponse validated(Hashtable params, 173 ControllerRequest request, ControllerResponse response, Controller ctlr) 174 throws ControllerException, NonHandleableException { 175 String dbname = (String ) params.get("db"); 178 179 String loginName = (String ) params.get("UserName"); 181 182 String registrationController = (String ) params.get("RegistrationController"); 183 String loginController = (String ) params.get("LoginController"); 184 185 StringUtil.assertNotBlank(registrationController, 186 "Error - Email Validator needed registration controller parameter"); 187 188 StringUtil.assertNotBlank(loginController, 189 "Error - Email Validator needed login controller parameter"); 190 191 Transition t = new Transition(); 192 t.setControllerObject(registrationController); 193 t.setState("emailValidate"); 194 t.setName("emailValidate"); 195 t.addParam("db", dbname); 196 t.addParam("UserName", loginName); 197 t.addParam("LoginController", loginController); 198 t.addParam("RegistrationController", registrationController); 199 200 t.redirectTransition(request, response); 202 203 return response; 204 } 205 206 213 protected String getString(String stringCode) { 214 Object [] args = {}; 215 216 return Messages.getString("com.jcorporate.expresso.core.ExpressoSchema", 217 stringCode, args); 218 } 219 220 221 231 protected String getString(String stringCode, Object [] args) { 232 return Messages.getString("com.jcorporate.expresso.core.ExpressoSchema", 233 stringCode, args); 234 } 235 236 } 237 | Popular Tags |