hydra-sql/src/Service/SQLLoginService.php
rudy bcc91a17b4
Some checks reported warnings
Cadoles/hydra-sql/pipeline/head This commit is unstable
Cadoles/hydra-sql/pipeline/pr-develop This commit is unstable
fix (oidc timeout) #31: ajout d'une règle de redirection en cas de donnée de session perdue
2024-04-18 17:13:42 +02:00

69 lines
2.1 KiB
PHP

<?php
namespace App\Service;
use App\SQLLogin\SQLLoginConnect;
use App\SQLLogin\SQLLoginRequest;
use PDO;
use PDOException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class SQLLoginService extends AbstractController
{
public SQLLoginRequest $sqlLoginRequest;
public function __construct(SQLLoginRequest $sqlLoginRequest)
{
$this->sqlLoginRequest = $sqlLoginRequest;
}
public function fetchDatas(string $login)
{
try {
$dbh = $this->getConnection();
// forge de la requête
$request = $this->sqlLoginRequest->getRequestScope();
// Préparation de la requête
$query = $dbh->prepare($request);
$query->execute([$this->sqlLoginRequest->getLoginColumnName() => $login]);
$datas = $query->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
\Sentry\captureException($e);
throw new PDOException();
}
return $datas;
}
public function fetchPassword(string $login)
{
try {
$dbh = $this->getConnection();
$request = $this->sqlLoginRequest->getRequestPassword();
$query = $dbh->prepare($request);
$query->execute([$this->sqlLoginRequest->getLoginColumnName() => $login]);
$password = $query->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
\Sentry\captureException($e);
throw new PDOException();
}
if ($password) {
return [
$password[$this->sqlLoginRequest->getPasswordColumnName()],
isset($password[$this->sqlLoginRequest->getSaltColumnName()]) ? $password[$this->sqlLoginRequest->getSaltColumnName()] : null,
];
}
return false;
}
public function getConnection()
{
// Appel du singleton
$sqlLogin = SQLLoginConnect::getInstance();
// Connection bdd
return $sqlLogin->connect($this->sqlLoginRequest->getDatabaseDsn(), $this->sqlLoginRequest->getDbUser(), $this->sqlLoginRequest->getDbPassword());
}
}