[59] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
| 2 | |
---|
| 3 | class AppCoreController extends BaseController { |
---|
| 4 | |
---|
[185] | 5 | def personService |
---|
[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 = { |
---|
[216] | 19 | def personInstance = personService.currentUser |
---|
[127] | 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') { |
---|
[216] | 32 | def personInstance = personService.currentUser |
---|
[127] | 33 | return [ personInstance : personInstance ] |
---|
| 34 | } |
---|
| 35 | if (request.method == 'POST') { |
---|
[216] | 36 | def personInstance = personService.currentUser |
---|
[127] | 37 | personInstance.properties = params |
---|
[178] | 38 | if (!personInstance.hasErrors() && personInstance.save(flush: true)) { |
---|
[127] | 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') { |
---|
[216] | 55 | def personInstance = personService.currentUser |
---|
[73] | 56 | return [ personInstance : personInstance ] |
---|
[150] | 57 | } |
---|
[73] | 58 | |
---|
| 59 | if (request.method == 'POST') { |
---|
[216] | 60 | def personInstance = personService.currentUser |
---|
[73] | 61 | |
---|
[99] | 62 | if(params.confirmPass == params.pass) { |
---|
[98] | 63 | personInstance.pass = params.pass |
---|
| 64 | personInstance.password = authenticateService.encodePassword(personInstance.pass) |
---|
| 65 | |
---|
[178] | 66 | if (!personInstance.hasErrors() && personInstance.save(flush: true)) { |
---|
[98] | 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 | } |
---|