Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use filter in grails

Tags:

filter

grails

I have a filter that i want to filter every action except ONE that brings me to login page.
If i filter all pages with some condition then even the LOGIN page too get filtered and so it stuck in infinte loop as condition not fulfilled (User not Logged IN). session.getAttribute("CurrentEmployeeIds") it tell whether user is logged in or not


My filter here:

class LoginFilters {

    def filters = {
        all(controller:'dashboard', action:'*') {
            before = {
                if (session.getAttribute("CurrentEmployeeIds")==null) {
                    redirect(controller:"site",action:"index")
                    return false
                }
            }
            after = { Map model ->

            }
            afterView = { Exception e ->

            }
        }
    }
}

I want to filter in such a way that it don't filter controller:"site",action:"index" this url and filter everything else.
thanks in advance.

like image 904
Sachin Verma Avatar asked Sep 25 '13 13:09

Sachin Verma


1 Answers

You can invert filter rule, like:

def filters = {
    allExceptIndex(controller:"site",action:"index",invert:true) {
        before = {
        }
        after = { Map model ->
        }
        afterView = { Exception e ->
        }
    }
}

See docs http://grails.org/doc/latest/guide/theWebLayer.html#filters

like image 140
Igor Artamonov Avatar answered Sep 24 '22 14:09

Igor Artamonov