Skip to content

Instantly share code, notes, and snippets.

@sergiomichels
Created October 16, 2012 02:04
Show Gist options
  • Save sergiomichels/3896881 to your computer and use it in GitHub Desktop.
Save sergiomichels/3896881 to your computer and use it in GitHub Desktop.
Command Object for control of password change
package com.wordpress.sergiosmind.command
import grails.validation.Validateable;
import groovy.transform.ToString;
@Validateable
@ToString
class PasswordChangeCommand {
//dependency injection for SpringSecurityService
def springSecurityService
String username
String actualPassword
String newPassword
String repNewPassword
static constraints = {
actualPassword(nullable: false, blank: false, validator: {String password, obj ->
String enc = obj.springSecurityService.encodePassword(password)
String encPasswordUser = obj.springSecurityService.currentUser.password
//check if the actual password informed is not equals as the current user password
if( enc != encPasswordUser ) {
return 'PasswordChangeCommand.actualPasswordMismatch' //key of the i18 message
} else {
return true
}
})
newPassword(nullable: false, blank: false)
repNewPassword(nullable: false, blank: false, validator: {String repNewPassword, obj ->
String newPassword = obj.properties['newPassword']
if( !(newPassword == repNewPassword) ) {
return 'PasswordChangeCommand.newPasswordMismatch' //key of the i18 message
} else {
return true
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment