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

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

Logins now route through a welcome action to allow flash message and user environment setup. Session timeout now user configurable and defaults to 12 hours. Work on Planned Maintenance.

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