mardi 6 juin 2017

Authentication with both email and username (same field) (laravel API )

I am building laravel API of my website . I am using laravel 5.3

I am using the API in building mobile app .

In login section, there are two fields :

  1. Enter email or username
  2. Enter password

In my DB , email and username are different columns.

Here is the function:

public function authenticate()
{

$credentials=request()->only('username','password');

try {

    $token=JWTAuth::attempt($credentials);

    if(!$token){
        return response()->json(['error'=>'credentials wrong'],401);
    }
}
catch(JWTException $e) {

 return response()->json(['error'=>'something_went_wrong'],500);

}
return response()->json(['token'=>$token],200);
}

Here only username is used,I want to use both username and password.

If need any other info please ask.

ty:)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire