I'm with Matt on this. In fact I just wrote this up last night. Consider
it a variation on a theme...
<cffunction name="changePassword" access="public" output="false"
returntype="any">
<cfset var user = getCurrentUser().clone()>
<cfset var result = getTransientFactory().create("ServiceResult")>
<cfset var errors = StructNew()>
<cfif hash(arguments.currentPassword) is user.getPassword()>
<cfset
result.setErrors(user.populate(argumentCollection=arguments))>
<cfif (result.getSuccess())>
<cfset result.setErrors(user.validate("changePassword"))>
<cfif (result.getSuccess())>
<cfset user = getUserGateway().save(user)>
</cfif>
</cfif>
<cfelse>
<cfset errors['badCredentials'] = "Password invalid.">
<cfset result.setErrors(errors)>
</cfif>
<cfset result.setResult(user)>
<cfreturn result>
</cffunction>
On Mon, Oct 20, 2008 at 9:45 AM, Matt Quackenbush <[EMAIL PROTECTED]>wrote:
> In my humble opinion, the User absolutely **should** know how to validate
> itself, including validating a new password. Otherwise, exactly as you've
> suggested, you end up with a bunch of bloated structs called CFCs floating
> around your application.
>
> Like anything, there is more than one way to skin a cat, but here's a bit
> of pseudo code from my controller that shows how I handle a password change.
>
> user = getSecurityService().getSessionUser();
> if ( user.isPassword( event.getValue("currentPassword") ) {
> clone = user.clone();
> clone.setPassword( event.getValue("password") );
> clone.setConfirmPassword( event.getValue("confirmPassword") );
>
> if ( clone.validate( context: "change password" ) {
> clone.save();
> } else {
> // send them back to the form with validation error message(s)
> }
> }
>
> HTH
>
> On Mon, Oct 20, 2008 at 10:26 AM, Alan Livie <[EMAIL PROTECTED]> wrote:
>
>> I keep falling into the 'anemic domain model' trap and for once I want
>> this User to be a genius :-) I have too many simple beans with dumb getters
>> and setters and service methods with all the good stuff.
>> It must end!
>>
>> As far as my User goes, it can be in an invalid state until the save()
>> method calls validate() before persisting the data if validation passes. So
>> the User can have an invalid email address until validate() is called.
>>
>> Alan
>>
>
>
> >
>
--
Paul Marcotte
Fancy Bread - in the heart or in the head?
http://www.fancybread.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CFCDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cfcdev?hl=en
-~----------~----~----~----~------~----~------~--~---