Restrict specific page in grails webapplication

58 views Asked by At

I have a small website in grails which has two pages. First is start and second page is details pages. URL's for this pages are http://somecomp.com/start and http://somecomp.com/details.

Now my first page which is start page has a tag which takes end user to details page.

I want to basically ensure that all my end user first comes on start page and then navigates to details pages. I want to restrict user if he directly opens http://somecomp.com/details.

Can this be done in grails and grrovy in some quick way. Any pointers will help.

Thanks JK

2

There are 2 answers

0
Alidad On

An easy approach could be to use a filter to intercept your request before details page and then check for some sort of flag maybe in session to see if start page was visited first.

Set that flag in your index or first action of your start page.

StartController

def index(){
   session.startVisited = new Date()
} 

.

class StartPageFilters {
    def filters = {
        startCheck(controller: '*', action: '*') {
            before = {
                if (!session.startVisited ) {
                    redirect(action: '....')
                    return false
                }
            }
        }
    }
}
1
ABC On

For the required scenario the genuine way to achieve the goal is to use Grails Webflow plugin link. For working example you can refer this git repository.