1 64 package com.jcorporate.expresso.services.validation; 65 66 import com.jcorporate.expresso.core.ExpressoSchema; 67 import com.jcorporate.expresso.core.controller.Controller; 68 import com.jcorporate.expresso.core.controller.ControllerException; 69 import com.jcorporate.expresso.core.controller.ControllerRequest; 70 import com.jcorporate.expresso.core.controller.ControllerResponse; 71 import com.jcorporate.expresso.core.controller.NonHandleableException; 72 import com.jcorporate.expresso.core.controller.Transition; 73 import com.jcorporate.expresso.core.db.DBException; 74 import com.jcorporate.expresso.core.i18n.Messages; 75 import com.jcorporate.expresso.core.misc.StringUtil; 76 import com.jcorporate.expresso.core.security.User; 77 import com.jcorporate.expresso.services.dbobj.Setup; 78 79 import java.util.Hashtable ; 80 import java.util.Vector ; 81 82 83 90 public class ChangePasswordValidator implements ValidationHandler { 91 92 96 public ChangePasswordValidator() { 97 super(); 98 } 99 100 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 Vector addresses = new Vector (0); 123 124 try { 125 User myUser = new User(); 127 myUser.setDataContext(dbName); 128 myUser.setLoginName(loginName); 129 130 if (!myUser.find()) { 131 throw new AuthValidationException("User with login \"" + 132 loginName + "\" not found"); 133 } 134 135 addresses.add(myUser.getEmail()); 136 137 Object [] args = { 138 URL, Setup.getValue(dbName, "CompanyName"), 139 Setup.getValue(dbName, "HomePageURL") 140 }; 141 142 String schema = (String ) params.get("schema"); 144 if (schema == null) { 145 schema = ExpressoSchema.class.getName(); 146 } 147 148 ValidationEntry.notifyByEmail(dbName, 150 Setup.getValue(dbName, "MAILFrom"), 151 addresses, 152 Messages.getString(schema, "passwdRequestedSubject"), 153 Messages.getString(schema, "passwdRequested", args)); 154 } catch (DBException dbe) { 155 throw new AuthValidationException("DB error accessing user \"" + 156 loginName + "\"", dbe); 157 } 158 } 159 160 177 public ControllerResponse validated(Hashtable params, 178 ControllerRequest request, ControllerResponse response, Controller ctlr) 179 throws ControllerException, NonHandleableException { 180 String dbname = (String ) params.get("db"); 183 184 String loginName = (String ) params.get("UserName"); 186 String loginController = (String ) params.get("LoginController"); 187 188 StringUtil.assertNotBlank(loginController, 189 "Error - Change Password validator needed login controller parameter"); 190 191 Transition t = new Transition(); 192 t.setControllerObject(loginController); 193 t.setState("emailValidate"); 194 t.setName("emailValidate"); 195 t.addParam("db", dbname); 196 t.addParam("UserName", loginName); 197 t.addParam("LoginController", loginController); 198 199 t.redirectTransition(request, response); 201 202 return response; 203 } 204 205 } 206 | Popular Tags |