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