samedi 21 mai 2016

laravel 5 JWTAuth allow multiple login

Is there a better way of doing this?, sorry i'm quite new to this i looked lots of places but i could not find anything that answers my question.

thank you for looking.

public function authenticate(Request $request)
{
    $email = $request->only('email', 'PASSWORD');
    $ssn = $request->only('SSN', 'PASSWORD');
    $badgenumber = $request->only('BADGENUMBER', 'PASSWORD');
    $error = 0;


    try {
        // verify the $email and create a token for the user
        if (!$token = JWTAuth::attempt($email)) {
            $error = 1;
        }
        if ($error == 1) {
            $error = 0;
            if (!$token = JWTAuth::attempt($ssn)) {
                $error = 1;
            }
        }
        if ($error == 1) {
            $error = 0;
            if (!$token = JWTAuth::attempt($badgenumber)) {
                $error = 1;
            }
        }

        if($error == 1){
            return response()->json(['error' => 'invalid_credentials'], 401);
        }

    } catch (JWTException $e) {
        // something went wrong
        return response()->json(['error' => 'could_not_create_token'], 500);
    }

    // if no errors are encountered we can return a JWT
    return response()->json(compact('token'));
}

i'm trying to allow user multiple login options such as email, badgenumber or ssn



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1WIEOOq
via IFTTT

Aucun commentaire:

Enregistrer un commentaire