2017-05-18 4 views
1

즉, 나는 다음과 같은 오류를 수신 :루멘 : JWT 인증 없음 사용자 테이블

{ 
    "message": "Undefined index: password", 
    "status_code": 500 
} 

liitle 배경 : 나는 users 테이블이

, 그리고 pincodes 테이블, users 테이블에는 두 개의 열 mobile_numberstatus이 있는데 사용자 테이블의 휴대 전화 번호로 SMS를 전송합니다. SMS에는 비밀 코드가 있습니다. user_id과 함께이 코드를 저장합니다. pincodes 테이블.

인증이 pincodes에 적용됩니다. 사용자가 인증되었는지 확인하려면 user_id이고 code 인 경우 인증이 적용됩니다. JWT 인증 library을 사용하여 루멘 마이크로 프레임 워크를 사용하고 있습니다. 그래서 User 모델과 같은 것으로 Pincode 모델을 변경했습니다.

namespace App; 

use Illuminate\Auth\Authenticatable; 
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; 
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; 
use Illuminate\Database\Eloquent\Model; 
use Laravel\Lumen\Auth\Authorizable; 

class Pincode extends Model implements 
AuthenticatableContract, 
AuthorizableContract { 
    use Authenticatable, Authorizable; 

    protected $table = 'pincodes'; 
    public function user() { 
     return $this->belongsTo('App\User'); 
    } 
} 

메소드 리퀘스트 형 포스트 (아래 참조)되어 있는지 확인하고,이 PARAMS user_idcode이다. 어느 것이 맞는지.

그리고 토큰을 생성 해 확인 방법 : 나는 다음과 같은 오류를 수신

public function verify(Request $request) { 
    $uid = $request->get('uid'); 
    $pinCode = $request->get('code'); 

    $findPinCode = \App\Pincode::where('uid', $uid)->where('code', $pinCode)->first(); 
    if (!$findPinCode) { 
     return response()->json([ 
      'message' => 'No pin Code found', 
      'code' => 404, 
     ]); 
    } 

    $findPinCode->status = 'v'; 
    $findPinCode->dateVerify = Carbon::now(); 

    $findPinCode->save(); 

    try { 

     $this->validatePostLoginRequest($request); 

    } catch (HttpResponseException $e) { 
     return $this->onBadRequest(); 
    } 

    try { 
     if (!$token = JWTAuth::attempt(
      $this->getCredentials($request) 
    )) { 
      return 'asdasd'; 
      return $this->onUnauthorized(); 
     } 
    } catch (JWTException $e) { 
     return $this->onJwtGenerationError(); 
    } 

:

{ 
    "message": "Undefined index: password", 
    "status_code": 500 
} 

답변

1

당신이 사용하는 코드베이스는 tymondesigns/jwt-auth 패키지를 사용합니다. JWTAuth::attempt 메서드는 기본적으로 전자 메일과 암호를 사용합니다.

간단한 방법은 수동으로 사용하여 PIN 코드로 사용자를 확인하고, 사용자 객체를 인출하고, 사용자에 대해 사용 토큰을 생성하는 것 JWTAuth::fromUser

$user = User::find($uid); 

try { 
    if (!$token = JWTAuth::fromUser($user)) { 
     return $this->onUnauthorized(); 
    } 
} catch (JWTException $e) { 
    return $this->onJwtGenerationError(); 
}