ollieread / multiauth

Laravel multi auth
441 stars 109 forks source link

Filters #44

Closed oroalej closed 10 years ago

oroalej commented 10 years ago

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!!

mikkezavala commented 10 years ago

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

oroalej commented 10 years ago

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

ollieread commented 10 years ago

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.

oroalej commented 10 years ago

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