Ignore:
Timestamp:
Mar 14, 2009, 10:04:39 AM (15 years ago)
Author:
gav
Message:

Add changePassword under options view so that users can change their own password.
Adjust for password validation, userCache etc. Only a small bug during "edit" is left on second "update" command.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/TaskRewrite/src/grails-app/controllers/AppCoreController.groovy

    r71 r73  
    1010    //def allowedMethods = [delete:'POST', save:'POST', update:'POST']
    1111
    12 
    1312    def home = {
    1413    }
    1514
    1615    def options = {
    17         def principal = authenticateService.principal()
    18         println principal.getUsername()//get username
    19         println principal.getAuthorities()//get authorities()
    2016    }
     17
     18    def changePassword = {
     19        //def principal = authenticateService.principal()
     20        //println principal.getAuthorities()
     21
     22        if (request.method == 'GET') {
     23            def personInstance = Person.get(authenticateService.userDomain().id)
     24            return [ personInstance : personInstance ]       
     25        } 
     26
     27        if (request.method == 'POST') {
     28            def personInstance = Person.get(authenticateService.userDomain().id)
     29   
     30            personInstance.pass = params.pass
     31            personInstance.password = authenticateService.encodePassword(personInstance.pass)
     32
     33            if (!personInstance.hasErrors() && personInstance.save()) {
     34                //userCache.removeUserFromCache(personInstance.loginName)
     35                flash.message = "Password changed successfully."
     36                redirect(action:options)
     37            }
     38            else {
     39                render(view:'changePassword',model:[personInstance:personInstance])
     40            }                         
     41        } 
     42    }
     43
    2144
    2245    @Secured(['ROLE_AppAdmin'])   
Note: See TracChangeset for help on using the changeset viewer.