[59] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
| 2 | |
---|
| 3 | class AppCoreController extends BaseController { |
---|
| 4 | |
---|
[71] | 5 | def authenticateService |
---|
| 6 | |
---|
[59] | 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 | |
---|
[127] | 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 | |
---|
[59] | 21 | def home = { |
---|
| 22 | } |
---|
| 23 | |
---|
[71] | 24 | def options = { |
---|
| 25 | } |
---|
| 26 | |
---|
[134] | 27 | def acknowledgements = { |
---|
| 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.sessionTimeout = params.sessionTimeout.toInteger() |
---|
| 38 | personInstance.properties = params |
---|
| 39 | if (!personInstance.hasErrors() && personInstance.save()) { |
---|
| 40 | def sess = getSession() |
---|
| 41 | sess.setMaxInactiveInterval(personInstance.sessionTimeout) |
---|
| 42 | flash.message = "Session timeout changed." |
---|
| 43 | redirect(action:options) |
---|
| 44 | } |
---|
| 45 | else { |
---|
| 46 | render(view:'changeSessionTimeout',model:[personInstance:personInstance]) |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | |
---|
[73] | 51 | def changePassword = { |
---|
| 52 | //def principal = authenticateService.principal() |
---|
| 53 | //println principal.getAuthorities() |
---|
| 54 | |
---|
| 55 | if (request.method == 'GET') { |
---|
| 56 | def personInstance = Person.get(authenticateService.userDomain().id) |
---|
| 57 | return [ personInstance : personInstance ] |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | if (request.method == 'POST') { |
---|
| 61 | def personInstance = Person.get(authenticateService.userDomain().id) |
---|
| 62 | |
---|
[99] | 63 | if(params.confirmPass == params.pass) { |
---|
[98] | 64 | personInstance.pass = params.pass |
---|
| 65 | personInstance.password = authenticateService.encodePassword(personInstance.pass) |
---|
| 66 | |
---|
| 67 | if (!personInstance.hasErrors() && personInstance.save()) { |
---|
| 68 | //userCache.removeUserFromCache(personInstance.loginName) |
---|
| 69 | flash.message = "Password changed successfully." |
---|
| 70 | redirect(action:options) |
---|
| 71 | } |
---|
| 72 | else { |
---|
| 73 | render(view:'changePassword',model:[personInstance:personInstance]) |
---|
| 74 | } |
---|
[73] | 75 | } |
---|
| 76 | else { |
---|
[99] | 77 | personInstance.errors.reject('person.pass.doesNotMatch', // Error code, see grails-app/i18n/message.properties |
---|
| 78 | ['pass', 'class Person'].toArray(), // Groovy ListArray cast to Object[] |
---|
| 79 | '[NothingUseMessageProperites]') // Default mapping string. |
---|
[73] | 80 | render(view:'changePassword',model:[personInstance:personInstance]) |
---|
[98] | 81 | } |
---|
| 82 | |
---|
[73] | 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
[91] | 86 | @Secured(['ROLE_Manager']) |
---|
| 87 | def manager = { |
---|
| 88 | } |
---|
[73] | 89 | |
---|
[71] | 90 | @Secured(['ROLE_AppAdmin']) |
---|
[106] | 91 | def appAdmin = { |
---|
[59] | 92 | } |
---|
| 93 | |
---|
| 94 | } |
---|