jeudi 8 décembre 2016

add new "password" column for authentication in laravel

I need to do two kind of authentication users. First is by password, so you need to type login+password and second must by by login+pin. How to do it? I tried a lot of ways to do it, but nothing happened. It always throw me error: 'User credentials are not correct!'. My code:

public function authenticate(Request $request) {

    if(isset($request->pin)){
        $credentials = $request->only('login', 'pin');
    }else{
    $credentials = $request->only('login', 'password');
    }

    \Config::set('auth.providers.users.model', \App\User::class);

    try {
        if (!$token = \Tymon\JWTAuth\Facades\JWTAuth::attempt($credentials)) {
            return response()->json(['error' => 'User credentials are not correct!'], 500);
        }
    } catch (\Tymon\JWTAuth\Exceptions\JWTException $ex) {
        return response()->json(['error' => 'something went wrong'], 500);
    }
}

Can anybody help me, pls?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire