source: trunk/grails-app/controllers/AppCoreController.groovy @ 150

Last change on this file since 150 was 150, checked in by gav, 15 years ago

Add params.message to Person create and edit views.
Code format to 4 spaces, no tabs.

File size: 3.8 KB
RevLine 
[59]1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class AppCoreController extends BaseController {
4
[71]5    def authenticateService
[149]6    def createDataService
[71]7
[139]8    def index = { redirect(action:start,params:params) }
[59]9
10    // the delete, save and update actions only accept POST requests
11    //def allowedMethods = [delete:'POST', save:'POST', update:'POST']
12
[139]13    /**
14    * This is where we arrive after login.
15    *  Attach the welcome flash message and redirect to where ever we want the user to start.
16    * e.g. redirect(controller:"taskDetailed", action:"search")
17    */
[127]18    def welcome = {
19        def personInstance = Person.get(authenticateService.userDomain().id)
20        flash.message = "Welcome, ${personInstance.firstName} ${personInstance.lastName}."
21
22        def sess = getSession()
23        sess.setMaxInactiveInterval(personInstance.sessionTimeout)
[139]24        redirect(action:start)
[127]25    }
26
[139]27    def start = {
[59]28    }
29
[127]30    def changeSessionTimeout = {
31        if (request.method == 'GET') {
32            def personInstance = Person.get(authenticateService.userDomain().id)
33            return [ personInstance : personInstance ]       
34        }
35        if (request.method == 'POST') {
36            def personInstance = Person.get(authenticateService.userDomain().id)
37                personInstance.properties = params
38                if (!personInstance.hasErrors() && personInstance.save()) {
39                    def sess = getSession()
40                    sess.setMaxInactiveInterval(personInstance.sessionTimeout)
41                    flash.message = "Session timeout changed."
[139]42                    redirect(action:start)
[127]43                }
44                else {
45                    render(view:'changeSessionTimeout',model:[personInstance:personInstance])
46                }
47        }
[149]48    }
[127]49
[73]50    def changePassword = {
51        //def principal = authenticateService.principal()
52        //println principal.getAuthorities()
53
54        if (request.method == 'GET') {
55            def personInstance = Person.get(authenticateService.userDomain().id)
56            return [ personInstance : personInstance ]       
[150]57        }
[73]58
59        if (request.method == 'POST') {
60            def personInstance = Person.get(authenticateService.userDomain().id)
61
[99]62            if(params.confirmPass == params.pass) {
[98]63                personInstance.pass = params.pass
64                personInstance.password = authenticateService.encodePassword(personInstance.pass)
65
66                if (!personInstance.hasErrors() && personInstance.save()) {
67                    //userCache.removeUserFromCache(personInstance.loginName)
68                    flash.message = "Password changed successfully."
[139]69                    redirect(action:start)
[98]70                }
71                else {
72                    render(view:'changePassword',model:[personInstance:personInstance])
73                }
[73]74            }
75            else {
[99]76                personInstance.errors.reject('person.pass.doesNotMatch',            // Error code, see grails-app/i18n/message.properties
77                                                                ['pass', 'class Person'].toArray(),      // Groovy ListArray cast to Object[]
78                                                                 '[NothingUseMessageProperites]')  // Default mapping string.
[73]79                render(view:'changePassword',model:[personInstance:personInstance])
[98]80            }
[149]81
82        }
[73]83    }
84
[149]85    @Secured(['ROLE_Manager','ROLE_AppAdmin'])
[91]86    def manager = {
87    }
[73]88
[149]89    @Secured(['ROLE_AppAdmin'])
[106]90    def appAdmin = {
[59]91    }
92
[149]93    @Secured(['ROLE_AppAdmin'])
94    def createBaseData = {
95        createDataService.createBaseData()
96        redirect(action:appAdmin)
97    }
98
99    @Secured(['ROLE_AppAdmin'])
100    def createDemoData = {
101        createDataService.createDemoData()
102        redirect(action:appAdmin)
103    }
104
[59]105}
Note: See TracBrowser for help on using the repository browser.