1 18 19 package org.apache.roller.ui.core.struts.actions; 20 21 import org.apache.commons.lang.CharSetUtils; 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.apache.struts.action.ActionError; 25 import org.apache.struts.action.ActionErrors; 26 import org.apache.struts.action.ActionMessages; 27 import org.apache.struts.actions.DispatchAction; 28 import org.apache.roller.config.RollerConfig; 29 import org.apache.roller.ui.authoring.struts.formbeans.UserFormEx; 30 31 32 35 public class UserBaseAction extends DispatchAction { 36 37 private static Log mLogger = LogFactory.getLog(UserBaseAction.class); 38 39 protected static String DEFAULT_ALLOWED_CHARS = "A-Za-z0-9"; 40 41 42 43 protected ActionMessages validate( UserFormEx form, ActionMessages errors ) { 44 45 String allowed = RollerConfig.getProperty("username.allowedChars"); 46 if(allowed == null || allowed.trim().length() == 0) { 47 allowed = DEFAULT_ALLOWED_CHARS; 48 } 49 String safe = CharSetUtils.keep(form.getUserName(), allowed); 50 51 if ( "".equals(form.getUserName().trim())) { 52 errors.add( ActionErrors.GLOBAL_ERROR, 53 new ActionError("error.add.user.missingUserName")); 54 } else if ( !safe.equals(form.getUserName()) ) { 55 errors.add( ActionErrors.GLOBAL_ERROR, 56 new ActionError("error.add.user.badUserName")); 57 } 58 59 if ( "".equals(form.getEmailAddress().trim())) { 60 errors.add( ActionErrors.GLOBAL_ERROR, 61 new ActionError("error.add.user.missingEmailAddress")); 62 } 63 return errors; 64 } 65 66 } 67 68 69 70 71 72 73 | Popular Tags |