Untitled
Never
<?php namespace App\Http\Controllers\API; use App\Models\Server; use App\Helpers\HelperAccessToken; use App\Http\Controllers\Controller; use App\Http\Requests\API\GameServerAuthRequest; use App\Exceptions\GameServerApiException; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Response; class GameServerAuthController extends Controller { /** * Handle a authorization the game server request to the application. * * @param GameServerAuthRequest $request * @return JsonResponse * @throws GameServerApiException */ public function __invoke(GameServerAuthRequest $request): JsonResponse { $server = $this->getGameServer($request); $authToken = $request->input('auth_token'); if ($this->attemptGameServer($server, $authToken)) { return $this->sendResponseOnAuth($server); } return $this->sendResponseOnFailedAuth(); } /** * Gets an instance of game server model based on request. * * @param Request $request * @return Server * @throws GameServerApiException */ protected function getGameServer(Request $request): Server { return Server::where([ ['ip', $request->ip()], ['port', $request->input('port')] ])->firstOr(function () { throw new GameServerApiException('Game server not found.', JsonResponse::HTTP_NOT_FOUND); }); } /** * Attempt to auth the game server into the application. * * @param Server $server * @param string $authToken * @return bool */ protected function attemptGameServer(Server $server, string $authToken): bool { return Hash::check($authToken, $server->auth_token); } /** * Send the response after the game server was authorized. * * @param Server $server * @return JsonResponse */ protected function sendResponseOnAuth(Server $server): JsonResponse { $server->access_token()->updateOrCreate( ['server_id' => $server->id], [ 'token' => HelperAccessToken::generateToken(), 'expires_in' => HelperAccessToken::createExpiresDate() ] ); $server->update(['active' => true]); return Response::json([ 'success' => true, 'access_token' => $server->access_token ], JsonResponse::HTTP_OK); } /** * Gets an instance of response with an error on authorization. * * @throws GameServerApiException */ protected function sendResponseOnFailedAuth() { return throw new GameServerApiException('Game server is unauthorized',JsonResponse::HTTP_UNAUTHORIZED); } }
Raw Text
-
LOAN4K. Lady with hot round tits gets sum of money borrowed after sex
13 min ago
-
fitspresso
16 min ago
-
Carnival row s02 free download
35 min ago
-
Bloom CBD Gummies
40 min ago
-
Step-niece with hot curves fulfills her uncle's fantasy
43 min ago
-
NEW🔥 UPDATED🔗 CP😈😏 FOLDERS📁 500 VIDEOS
1 hour ago
-
TRANSANDO GOSTOSO COM A MORENA MAIS FODA DE CURITIBA (LIS MODEL)
1 hour ago
-
Fitspresso For Coffee Loophole
1 hour ago
-
C_🔥P D000D latest
1 hour ago
-
What are the rapid results of keto ACV gummies?
1 hour ago