Skip to content

Instantly share code, notes, and snippets.

@computerex
Created August 9, 2016 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save computerex/d41b5f32ee4dd44f134d654990ec2f59 to your computer and use it in GitHub Desktop.
Save computerex/d41b5f32ee4dd44f134d654990ec2f59 to your computer and use it in GitHub Desktop.
<?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