Changeset 1138 for trunk/grails-app/controllers
- Timestamp:
- Nov 15, 2010, 1:36:42 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/authentication/UserRegistrationController.groovy
r976 r1138 18 18 class UserRegistrationController { 19 19 def springSecurityService 20 def authenticationService 20 21 21 22 /** … … 23 24 */ 24 25 def index = { 25 26 26 } 27 27 … … 51 51 email: params.email, 52 52 password: springSecurityService.encodePassword(password, params.username), 53 userConfirmed: true, adminConfirmed: true)53 userConfirmed: false, adminConfirmed: false) 54 54 55 55 // Redirect user if save fails … … 149 149 } 150 150 151 @Secured(['IS_AUTHENTICATED_REMEMBERED']) 152 def profile = { 153 [ user: authenticationService.getLoggedInUser() ] 154 } 155 156 @Secured(['IS_AUTHENTICATED_REMEMBERED']) 157 def updateProfile = { ProfileCommand command -> 158 def user = authenticationService.getLoggedInUser(); 159 command.username = user.username 160 command.oldPass = user.password 161 command.validate() 162 163 if (command.hasErrors()) { 164 render( view: 'profile', model: [user: user, command: command]); 165 return 166 } 167 168 String salt = user.username 169 RegistrationCode.withTransaction { status -> 170 user.password = springSecurityService.encodePassword(command.password, salt) 171 user.email = command.email 172 user.save() 173 } 174 175 redirect controller: 'home' 176 } 177 151 178 private String generatePassword( int length ) { 152 179 String validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-!@#%^&*()/\\;:" … … 163 190 return resultID 164 191 } 192 193 static final passwordValidator = { String password, command -> 194 if( password == "" ) { 195 return 196 } 197 198 if (command.username && command.username.equals(password)) { 199 return 'command.password.error.username' 200 } 201 202 if (password && password.length() >= 8 && password.length() <= 64 && 203 (!password.matches('^.*\\p{Alpha}.*$') || 204 !password.matches('^.*\\p{Digit}.*$') || 205 !password.matches('^.*[!@#$%^&].*$'))) { 206 return 'command.password.error.strength' 207 } 208 } 209 210 static final password2Validator = { value, command -> 211 if (command.password != command.password2) { 212 return 'command.password2.error.mismatch' 213 } 214 } 165 215 } 216 217 class ProfileCommand { 218 219 String username 220 String oldPass 221 String email 222 String password 223 String password2 224 225 static constraints = { 226 username blank: false 227 email blank: false, email: true 228 password blank: true, minSize: 8, maxSize: 64, validator: UserRegistrationController.passwordValidator 229 password2 validator: UserRegistrationController.password2Validator 230 } 231 } 232
Note: See TracChangeset
for help on using the changeset viewer.