2017-05-18 10 views
1

要するに、私は次のエラーを受け取りますルーメン:JWT認証なしのユーザーテーブルと

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

liitle背景:私はusersテーブルを持っている

、そしてpincodesテーブル、 usersテーブルには2つのカラムmobile_numberstatusがあり、私はusersテーブルのモバイル番号にSMSを送信しています.SMSは秘密コードを持っていますので、user_idpincodesテーブル。

認証がpincodesに適用されます。ここでは、user_idcodeがあり、ユーザーが本物かどうかを確認できます。私は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_idあり、code。どちらが正しいのですか?

とトークンが生成することになっている検証方法:

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(); 
}