Domanda

I have 3 types of users:

  1. Client
  2. Admin
  3. Super Admin

Now, I need to allow both admin and super admin to login in my admin portal how ever to implement the authentication we are going to put in array form our credentials like:

$creds = array('username'=>Input::get('uname'),'password'=>Input::get('pwd'),'usertype'=>$utype);

How can I allow both admin and super admin in Auth if I am only allowed to declare usertype once in my $creds array?

È stato utile?

Soluzione

Apply some groups to your users, add the user to a group and validate on that. ( Or even, apply ACL to groups, and check on that ) Is the future requires more types of users you can just add them to a group instead of altering your $creds array.

Altri suggerimenti

we all know that if we are going to attemp an authnetication, we are going to pass an array of credetials. My problem my usertype can have two value( admin and super admin ) but we cant put two usertype in an array like this:

$creds = array('username'=>$uname,'password'=>$pwd,'usertype'=>'admin','usertype'=>'super admin');

SOLUTION: The only way for this is grouping it(as of the moment I think.)

Route::filter('admin-auth', function(){
if(Auth::guest() || Auth::user()->usertype == 'client' || Auth::user()->active == 0) return Redirect::to('admin/login?ret='.Request::url());
});

NOTE: the Redirect::to('admin/login?ret='.Request::url()) is not advisable because laravel has already the Redirect::intended() function if you are going to redirect someone to a certain page after successful authentication however I did this because Im using ajax.

You can use a little trick that i found. on credentials array you can add DB::RAW to your condition like this:

$creds = array(
                'username'=> Input::get('uname'),
                'password'=> DB:RAW(Input::get('pwd') . ' and `usertype` in (your user types);

Maybe not the best solution but it works. You can check your query to see that it's ok

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top