| 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
|---|
| 2 | |
|---|
| 3 | class AppCoreController extends BaseController { |
|---|
| 4 | |
|---|
| 5 | def authenticateService |
|---|
| 6 | |
|---|
| 7 | def index = { redirect(action:start,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 | /** |
|---|
| 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 | */ |
|---|
| 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) |
|---|
| 23 | redirect(action:start) |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | def start = { |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 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." |
|---|
| 41 | redirect(action:start) |
|---|
| 42 | } |
|---|
| 43 | else { |
|---|
| 44 | render(view:'changeSessionTimeout',model:[personInstance:personInstance]) |
|---|
| 45 | } |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 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 | |
|---|
| 61 | if(params.confirmPass == params.pass) { |
|---|
| 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." |
|---|
| 68 | redirect(action:start) |
|---|
| 69 | } |
|---|
| 70 | else { |
|---|
| 71 | render(view:'changePassword',model:[personInstance:personInstance]) |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | else { |
|---|
| 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. |
|---|
| 78 | render(view:'changePassword',model:[personInstance:personInstance]) |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | } |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | @Secured(['ROLE_Manager']) |
|---|
| 85 | def manager = { |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | @Secured(['ROLE_AppAdmin']) |
|---|
| 89 | def appAdmin = { |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | } |
|---|