Added Check to game steam login to verify if the user needs to have a special role to play the game.

the role/s can be set in the .env with `ROLES_ALLOWED_TO_PLAY=`
This commit is contained in:
Vari
2024-09-02 00:12:22 +02:00
parent e97d70ecb4
commit 9eee06dc2e
3 changed files with 19 additions and 0 deletions

View File

@@ -31,6 +31,13 @@ public function login(SteamLoginRequest $request)
}
$foundUser = User::firstOrCreate(['steam_id' => $steamResponse->steamId], ['source' => 'GAME', 'steam_id' => $steamResponse->steamId]);
if(!$this->checkIfPlayAllowed($foundUser)) {
$log->notice('User with SteamID "{id}" denied login. User has not sufficent roele', ['id' => $steamResponse->steamId]);
return response('Unauthorized: Not Allowed', 401);
}
Auth::login($foundUser);
$this->fillSteamData($foundUser);
@@ -64,4 +71,10 @@ protected function fillSteamData(User &$user): void
$user->avatar_full = $player->avatarFull;
$user->save();
}
protected function checkIfPlayAllowed(User &$user): bool {
if(config('app.roles_allowed_to_play') === null)
return true;
return $user->hasAnyRole(config('app.roles_allowed_to_play'));
}
}