1 20 21 package com.methodhead.reg; 22 23 import java.io.Serializable ; 24 import javax.servlet.http.HttpServletRequest ; 25 26 import org.apache.struts.action.ActionMapping; 27 import org.apache.struts.action.ActionErrors; 28 import org.apache.struts.action.ActionError; 29 import org.apache.struts.validator.DynaValidatorForm; 30 import com.methodhead.aikp.AikpForm; 31 import com.methodhead.auth.AuthUtil; 32 import java.util.List ; 33 import java.util.ArrayList ; 34 import java.util.Iterator ; 35 import org.apache.struts.Globals; 36 import org.apache.struts.util.LabelValueBean; 37 import org.apache.struts.util.MessageResources; 38 import com.methodhead.sitecontext.SiteContext; 39 import com.methodhead.util.StrutsUtil; 40 import com.methodhead.util.OperationContext; 41 import org.apache.commons.lang.StringUtils; 42 43 public class UserForm 44 extends 45 AikpForm 46 implements 47 Serializable { 48 49 public ActionErrors doValidate( 50 ActionMapping mapping, 51 HttpServletRequest request, 52 ActionErrors errors ) { 53 54 if ( !errors.isEmpty() ) 55 return errors; 56 57 if ( "saveNew".equals( get( "action" ) ) ) { 58 59 if ( StringUtils.isBlank( ( String )get( "password" ) ) ) { 60 errors.add( "password", new ActionError( "reg.user.missingpassword" ) ); 61 return errors; 62 } 63 64 if ( !get( "verifypassword" ).equals( get( "password" ) ) ) { 65 errors.add( 66 "verifypassword", new ActionError( "reg.user.verifypasswordmismatch" ) ); 67 return errors; 68 } 69 70 User user = new User(); 71 if ( user.loadForLogin( ( String )get( "email" ) ) ) { 72 errors.add( 73 "email", new ActionError( "reg.user.userExists" ) ); 74 return errors; 75 } 76 } 77 78 else if ( "save".equals( get( "action" ) ) ) { 79 80 if ( !StringUtils.isBlank( ( String )get( "password" ) ) ) { 81 82 if ( !get( "verifypassword" ).equals( get( "password" ) ) ) { 83 errors.add( 84 "verifypassword", new ActionError( "reg.user.verifypasswordmismatch" ) ); 85 return errors; 86 } 87 } 88 89 User user = new User(); 90 if ( user.loadForLogin( ( String )get( "email" ) ) ) { 91 if ( user.getInt( "id" ) != Integer.parseInt( ( String )get( "id" ) ) ) { 92 errors.add( 93 "email", new ActionError( "reg.user.userExists" ) ); 94 return errors; 95 } 96 } 97 } 98 99 return errors; 100 } 101 } 102 | Popular Tags |