-
<cffunction name="invokeMethod" hint="I am a Method Intercepter. I Users.<br />If a validaiton fails I return a Struct of the errors in the request scope." access="public" returntype="any">
-
<cfargument name="methodInvocation" type="coldspring.aop.MethodInvocation" required="false" />
-
<!--- get the values from the coldSpring framework. THIS IS IMPORTANT --->
-
<cfset var args = arguments.methodInvocation.getArguments() />
-
<cfset var errors = StructNew() />
-
<!---
-
UserValidation, this would be more complicated and
-
probally check what type of request is comming in
-
and perform Validation is several ways.
-
--->
-
<!--- check that they supplied a name --->
-
<cfif not isDefined("args.name") OR trim(len(user.name)) LT 1>
-
<cfset StructInsert(errors, "badName", "Please provide a valid name.") />
-
</cfif>
-
<!--- check the email --->
-
<cfif not isDefined("args.email") OR trim(len(user.name)) LT 1>
-
<cfset StructInsert(errors, "badEmail", "Pleae provide a valid email address.") />
-
</cfif>
-
<!--- retrun a struct if there was an error. :( --->
-
<cfif StructCount(errors) GT 0>
-
<cfset request.errors = StructInsert(errors, "errors", 1) />
-
<cfelse>
-
<!--- OR IF WE WERE SUCESSFULL GO AHEAD AND DO IT! --->
-
<!--- OR IF WE WERE SUCESSFULL GO AHEAD AND DO IT! --->
-
<!--- OR IF WE WERE SUCESSFULL GO AHEAD AND DO IT! --->
-
<!--- Use the awsome proceed() method call --->
-
<cfset sucess = arguments.methodInvocation.proceed() />
-
</cfif><cfreturn request.errors />
-
</cffunction>