|
|
@ -4,11 +4,13 @@ namespace App\Http\Controllers; |
|
|
|
|
|
|
|
use App\Http\Resources\UserResource; |
|
|
|
use App\Models\Business; |
|
|
|
use App\Models\Fingerprint; |
|
|
|
use App\Models\User; |
|
|
|
use App\Notifications\DBNotification; |
|
|
|
use App\Notifications\MailNotification; |
|
|
|
use Illuminate\Http\JsonResponse; |
|
|
|
use Illuminate\Http\Request; |
|
|
|
use Illuminate\Session\TokenMismatchException; |
|
|
|
use Illuminate\Support\Facades\Auth; |
|
|
|
use Illuminate\Support\Facades\Cache; |
|
|
|
use Illuminate\Support\Facades\Hash; |
|
|
@ -443,4 +445,50 @@ class AuthController extends Controller |
|
|
|
return $this->authWithInfo(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param Request $request |
|
|
|
* @return mixed |
|
|
|
* @throws TokenMismatchException |
|
|
|
*/ |
|
|
|
public function logout(Request $request) |
|
|
|
{ |
|
|
|
$token = $request->bearerToken(); |
|
|
|
|
|
|
|
if (blank($token)) { |
|
|
|
return new JsonResponse([ |
|
|
|
'message' => 'Not authorized request.', |
|
|
|
'status' => Response::HTTP_UNAUTHORIZED |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** @var Fingerprint $token */ |
|
|
|
$token = Auth::user()->fingerprints()->firstWhere([ |
|
|
|
'token' => $token, |
|
|
|
]); |
|
|
|
|
|
|
|
if ($token) { |
|
|
|
return $token->delete(); |
|
|
|
} |
|
|
|
|
|
|
|
throw new TokenMismatchException('Invalid token!'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param string $token |
|
|
|
* @throws TokenMismatchException |
|
|
|
*/ |
|
|
|
public function revoke(string $token) |
|
|
|
{ |
|
|
|
/** @var Fingerprint $token */ |
|
|
|
$token = Fingerprint::firstWhere([ |
|
|
|
'token' => $token, |
|
|
|
]); |
|
|
|
|
|
|
|
if ($token) { |
|
|
|
return $token->delete(); |
|
|
|
} |
|
|
|
|
|
|
|
throw new TokenMismatchException(); |
|
|
|
} |
|
|
|
|
|
|
|
} |