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

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

Refactor bootstrap data generation to new CreateDataService?.
Tweak security annotations so that ROLE_AppAdmin gives access to all areas.
Rework DataSource? to allow building of prod and dev WARs.
Include MySQL jdbc connector which is GNU GPL'd and used in the prod WAR.

File size: 3.8 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class AppCoreController extends BaseController {
4
5    def authenticateService
6    def createDataService
7
8    def index = { redirect(action:start,params:params) }
9
10    // the delete, save and update actions only accept POST requests
11    //def allowedMethods = [delete:'POST', save:'POST', update:'POST']
12
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    */
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)
24        redirect(action:start)
25    }
26
27    def start = {
28    }
29
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."
42                    redirect(action:start)
43                }
44                else {
45                    render(view:'changeSessionTimeout',model:[personInstance:personInstance])
46                }
47        }
48    }
49
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 ]       
57        } 
58
59        if (request.method == 'POST') {
60            def personInstance = Person.get(authenticateService.userDomain().id)
61
62            if(params.confirmPass == params.pass) {
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."
69                    redirect(action:start)
70                }
71                else {
72                    render(view:'changePassword',model:[personInstance:personInstance])
73                }
74            }
75            else {
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.
79                render(view:'changePassword',model:[personInstance:personInstance])
80            }
81
82        }
83    }
84
85    @Secured(['ROLE_Manager','ROLE_AppAdmin'])
86    def manager = {
87    }
88
89    @Secured(['ROLE_AppAdmin'])
90    def appAdmin = {
91    }
92
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
105}
Note: See TracBrowser for help on using the repository browser.