Created
October 16, 2012 02:04
-
-
Save sergiomichels/3896881 to your computer and use it in GitHub Desktop.
Command Object for control of password change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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