2016-09-13 4 views
1

각 유형의 사용자에 대해 두 가지 로그인 방법을 사용하는 admin 및 클라이언트에 대해 두 개의 테이블이 있습니다. 이미 admin에 대해 attempt() 메소드를 사용하고 있습니다. 나는 클라이언트를위한 JWTAuthentication을 만들려고 노력하고있다. 이 순간에 내가 클라이언트 로그인을 인증하려고 할 때 클라이언트 테이블 내부에서 질의하는 동안 관리 테이블 내에서 laravel 쿼리가 수행됩니다. 나는 특히 클라이언트 모델을 조사하기 위해 config를 설정하려고 시도했다. 하지만 여전히 Admin을 조사 중입니다.Laravel 인증 모델 변경

클라이언트가 로그인을 시도 할 때 관리자 테이블을 조사하지 않도록 laravel에게 어떻게 말합니까?

if($dbPass==$password) 
    { 
     //find secret api key and send it to curl 
     //$this->callTeamworkApi($query->secretApiKey); 
     //set session 
    //JWT authenticate 
    //$credentials = ["email"=>$email,"password"=>$password]; 
     //$credentials = $request->all('email','password'); 
     $credentials =[]; 
     $credentials['email'] = $email; 
     $credentials['password'] = $request->password; 

     try{ 
      \Config::set('auth.model', 'Client'); 
      \Config::set('auth.table' , 'clients'); 
      if(! $token = JWTAuth::attempt($credentials)) 
       { 
       return response()->json([ 
        'response' => 'Some error with user credentials' 
       ]); 
       }else{ 
       // $request->session()->put('secretApiKey', $query->secretApiKey); 
       // $request->session()->put('userEmail', $sessionEmail); 
       // $request->session()->put('userId', $sessionId); 
       // $request->session()->put('userName', $sessionName); 
       // $request->session()->put('timeCreated', $timeCreated); 
       //find user details and put them inside session array 
       $msg = "Login_checked"; 
       return response()->json(["token"=>compact('token'), "msg"=> $msg]); 
      } 

     }catch(JWTExceptions $err){ 
      return response()->json(['response'=>$err]); 
     } 

    }else{ 
     $msg = "Password_wrong"; 
    } 

답변

0

모든 인증 드라이버에는 사용자 제공 업체가 있습니다. 이것은 사용자가 데이터베이스 또는 사용자의 데이터를 유지하기 위해이 응용 프로그램에서 사용하는 다른 저장소 메커니즘에서 실제로 검색되는 방법을 정의합니다.

사용자 테이블이나 모델이 여러 개인 경우 각 모델/테이블을 나타내는 여러 소스를 구성해야합니다.

config/auth.php 파일로 작성해야합니다.

'providers' => [ 

    'admins' => [ 
     'driver' => 'eloquent', 
     'model' => App\Admin::class, 
    ], 
    'clients' => [ 
     'driver' => 'eloquent', 
     'model' => App\Client::class, 
    ], 

], 

Laravel 5에서 작동합니다. 버전 4 이하는 확실하지 않습니다.