1. <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">
  2. <cfargument name="methodInvocation" type="coldspring.aop.MethodInvocation" required="false" />
  3. <!--- get the values from the coldSpring framework. THIS IS IMPORTANT --->
  4. <cfset var args = arguments.methodInvocation.getArguments() />
  5. <cfset var errors = StructNew() />
  6. <!---
  7. UserValidation, this would be more complicated and
  8. probally check what type of request is comming in
  9. and perform Validation is several ways.
  10. --->
  11. <!--- check that they supplied a name --->
  12. <cfif not isDefined("args.name") OR trim(len(user.name)) LT 1>
  13. <cfset StructInsert(errors, "badName", "Please provide a valid name.") />
  14. </cfif>
  15. <!--- check the email --->
  16. <cfif not isDefined("args.email") OR trim(len(user.name)) LT 1>
  17. <cfset StructInsert(errors, "badEmail", "Pleae provide a valid email address.") />
  18. </cfif>
  19. <!--- retrun a struct if there was an error. :( --->
  20. <cfif StructCount(errors) GT 0>
  21. <cfset request.errors = StructInsert(errors, "errors", 1) />
  22. <cfelse>
  23. <!--- OR IF WE WERE SUCESSFULL GO AHEAD AND DO IT! --->
  24. <!--- OR IF WE WERE SUCESSFULL GO AHEAD AND DO IT! --->
  25. <!--- OR IF WE WERE SUCESSFULL GO AHEAD AND DO IT! --->
  26. <!--- Use the awsome proceed() method call --->
  27. <cfset sucess = arguments.methodInvocation.proceed() />
  28. </cfif><cfreturn request.errors />
  29. </cffunction>