简体   繁体   中英

Cartalyst/Sentinel Laravel 5.4 - Check a database field before Logging user in

I am using Sentinel by Cartalyst in my Laravel 5.4 project. However I am tying to check the value of a database field of the 'users' table after the user provides his/her credentials for logging in.

if(Sentinel::authenticate($credentials, $rememberMe)) {

     $slug = Sentinel::getUser()->roles()->first()->slug;
     if($slug == 'A') {
         Session::flash('welcome_message' , 'A');
         return response()->json(['redirect' => '/A/dashboard']);
     } elseif($slug == 'B') {
         Session::flash('welcome_message' , 'B');
         return response()->json(['redirect' => '/B/dashboard']);
    }
} else {
    return response()->json(['error' => 'Wrong credentials entered'], 500);
}


// if(Sentinel::getUser()->status == 'Active') -- if this is true we log in

The problem I cant find a way to implement this..though it checks the field but if it returns false then also the user gets logged in

Try following :

if($user = Sentinel::authenticate($credentials, $rememberMe) && $user->status == 'Active') {

     $slug = Sentinel::getUser()->roles()->first()->slug;
     if($slug == 'A') {
         Session::flash('welcome_message' , 'A');
         return response()->json(['redirect' => '/A/dashboard']);
     } elseif($slug == 'B') {
         Session::flash('welcome_message' , 'B');
         return response()->json(['redirect' => '/B/dashboard']);
    }
} else {
    return response()->json(['error' => 'Wrong credentials entered'], 500);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM