develop #5
3 changed files with 14 additions and 4 deletions
|
@ -37,4 +37,9 @@ final class EnvironmentHandler
|
|||
public function isProduction(): bool {
|
||||
return $_SERVER['PRODUCTION'] === 'true';
|
||||
}
|
||||
|
||||
public function useSSL(): bool
|
||||
{
|
||||
return $_SERVER['USE_SSL'] === 'true';
|
||||
}
|
||||
}
|
|
@ -7,12 +7,14 @@ use Doctrine\ORM\EntityManager;
|
|||
use GamesShop\Api\DiscordAPI;
|
||||
use GamesShop\ContainerHandler;
|
||||
use GamesShop\Entities\Account\User;
|
||||
use GamesShop\Environment\EnvironmentHandler;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
final class DiscordLoginProvider implements LoginProvider
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManager $entityManager
|
||||
private readonly EntityManager $entityManager,
|
||||
private readonly EnvironmentHandler $env
|
||||
)
|
||||
{
|
||||
}
|
||||
|
@ -20,7 +22,12 @@ final class DiscordLoginProvider implements LoginProvider
|
|||
public function getUser(ServerRequestInterface $request): User
|
||||
{
|
||||
$discordApiHandler = ContainerHandler::get(DiscordAPI::class);
|
||||
$result = $discordApiHandler->getUserFromCode($request->getQueryParams()['code'], (string)$request->getUri()->withQuery(''));
|
||||
$result = $discordApiHandler->getUserFromCode(
|
||||
$request->getQueryParams()['code'],
|
||||
(string)$request->getUri()
|
||||
->withScheme($this->env->useSSL() ? 'https' : 'http')
|
||||
->withQuery('')
|
||||
);
|
||||
|
||||
$repo = $this->entityManager->getRepository(User::class);
|
||||
$users = $repo->findBy(['loginMethod' => LoginMethod::DISCORD, 'foreignLoginId' => $result['id']]);
|
||||
|
|
|
@ -15,8 +15,6 @@ require_once __DIR__ . '/../src/php/bootstrap.php';
|
|||
|
||||
ContainerHandler::get(CrashHandler::class)->register();
|
||||
|
||||
throw new Exception();
|
||||
|
||||
$router = ContainerHandler::getInstance()->get(Router::class);
|
||||
$result = $router->route();
|
||||
|
||||
|
|
Loading…
Reference in a new issue