multiauth icon indicating copy to clipboard operation
multiauth copied to clipboard

Filters

Open oroalej opened this issue 12 years ago • 4 comments

hello, How can i apply filters to multiple auth? i have one login page that authenticate 3 type of users; driver, operator and officer.

i tried making each one of them a filter like this

Route::filter('auth.Officer', function(){
    if (Auth::Officer()->guest()){
        return Redirect::guest(URL::route('account-GetLogIn'));     
    }
});

but when i try to this in my Route

Route::group(array('before' => 'auth.Officer|auth.Driver|auth.Operator'), function(){
}   

this is my Auth Configuration

'multi' => array(
        'Officer' => array(
            'driver' => 'eloquent',
            'model' => 'ApprehendingOfficers',
            'table' => 'apprehendingofficer'
        ),
        'Operator' => array(
            'driver' => 'eloquent',
            'model' => 'Operation',
            'table' => 'operator'
        ),
        'Driver' => array(
            'driver' => 'eloquent',
            'model' => 'Drivers',
            'table' => 'driver'
        )
    ),

the browser says Redirect loop, can you guys help me resolve this problem. Thank you!!

oroalej avatar Jun 22 '14 15:06 oroalej

Mmm this is more an implementation issue than a "MultiAuth" issue, read laravel documentation in regard how to use the "Laravel Filters", please reffer to the Laravel Documentation "http://laravel.com/docs/routing#route-filters".

I will give you a hint: your telling your filter, to go first on Officer, or, Driver, or Operator, or none, or repat to see whom it is logged in, in your filter you shoult handle the redirect or the session kill, or.... whatever that the auth logic layer should do

mikkezavala avatar Jun 22 '14 15:06 mikkezavala

Do i need to make separate login page for every user?I'm just new in laravel, sorry.

oroalej avatar Jun 22 '14 16:06 oroalej

A separate login page would be ideal, this package is designed for situations where your users are so fundamentally different, that they likely share little or no functionality, but still need access to the same data/same system.

ollieread avatar Jun 23 '14 10:06 ollieread

I found a solution i used the code of soupdiver to make things possible :dancer: public function getAuthenticatedTypes() { $authenticated = array();

    foreach($this->providers as $name => $provider) {
        if($provider->check()) $authenticated[] = $name;
    }

    return $authenticated;
}

Thank you @ollieread and @mikkezavala

oroalej avatar Jun 23 '14 10:06 oroalej