Created
August 9, 2016 00:43
-
-
Save computerex/d41b5f32ee4dd44f134d654990ec2f59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Http\Request; | |
use JWTAuth; | |
class AuthController extends Controller | |
{ | |
public function __construct() | |
{ | |
} | |
public function postLogin(Request $request) | |
{ | |
$this->validate($request, [ | |
'email' => 'required|email|max:255', | |
'password' => 'required', | |
]); | |
try { | |
$creds = $request->only('email', 'password'); | |
echo print_r($creds, true); | |
if (! $token = JWTAuth::attempt($creds)) { | |
echo $request->input('email'); | |
echo $request->input('password'); | |
return response()->json(['user_not_found'], 404); | |
} | |
} catch (\Tymon\JWTAuth\Exceptions\TokenExpiredException $e) { | |
return response()->json(['token_expired'], 500); | |
} catch (\Tymon\JWTAuth\Exceptions\TokenInvalidException $e) { | |
return response()->json(['token_invalid'], 500); | |
} catch (\Tymon\JWTAuth\Exceptions\JWTException $e) { | |
return response()->json(['token_absent' => $e->getMessage()], 500); | |
} | |
return response()->json(compact('token')); | |
} | |
} | |
Array ( [email] => mohd.ali.el@gmail.com [password] => foobar ) mohd.ali.el@gmail.comfoobar["user_not_found"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment