2022-12-09 17:31:07 +01:00
|
|
|
<?php
|
|
|
|
|
2022-12-14 16:38:46 +01:00
|
|
|
namespace App\Service;
|
2022-12-09 17:31:07 +01:00
|
|
|
|
2022-12-14 16:38:46 +01:00
|
|
|
use App\SQLLogin\SQLLoginConnect;
|
|
|
|
use App\SQLLogin\SQLLoginRequest;
|
2022-12-09 17:31:07 +01:00
|
|
|
use PDO;
|
|
|
|
use PDOException;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
|
|
|
|
2022-12-14 16:38:46 +01:00
|
|
|
class SQLLoginService extends AbstractController
|
2022-12-09 17:31:07 +01:00
|
|
|
{
|
|
|
|
private $params;
|
2022-12-14 16:38:46 +01:00
|
|
|
public SQLLoginRequest $sqlLoginRequest;
|
2022-12-09 17:31:07 +01:00
|
|
|
|
2022-12-14 16:38:46 +01:00
|
|
|
public function __construct(ParameterBagInterface $params, SQLLoginRequest $sqlLoginRequest)
|
2022-12-09 17:31:07 +01:00
|
|
|
{
|
|
|
|
$this->params = $params;
|
2022-12-14 16:38:46 +01:00
|
|
|
$this->sqlLoginRequest = $sqlLoginRequest;
|
2022-12-09 17:31:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function fetchDatas($login)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$dbh = $this->getConnection();
|
|
|
|
|
|
|
|
// forge de la requête
|
2022-12-14 16:38:46 +01:00
|
|
|
$request = $this->sqlLoginRequest->getRequestScope();
|
2022-12-09 17:31:07 +01:00
|
|
|
|
|
|
|
// Préparation de la requête
|
|
|
|
$query = $dbh->prepare($request);
|
2022-12-14 16:38:46 +01:00
|
|
|
$query->execute([$this->sqlLoginRequest->getLoginColumnName() => $login]);
|
2022-12-09 17:31:07 +01:00
|
|
|
$datas = $query->fetch(PDO::FETCH_ASSOC);
|
|
|
|
} catch (PDOException $e) {
|
2022-12-13 15:46:24 +01:00
|
|
|
\Sentry\captureException($e);
|
|
|
|
|
|
|
|
throw new PDOException();
|
2022-12-09 17:31:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $datas;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $login
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function fetchPassword($login)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$dbh = $this->getConnection();
|
2022-12-14 16:38:46 +01:00
|
|
|
$request = $this->sqlLoginRequest->getRequestPassword();
|
2022-12-09 17:31:07 +01:00
|
|
|
$query = $dbh->prepare($request);
|
2022-12-14 16:38:46 +01:00
|
|
|
$query->execute([$this->sqlLoginRequest->getLoginColumnName() => $login]);
|
2022-12-09 17:31:07 +01:00
|
|
|
$password = $query->fetch(PDO::FETCH_ASSOC);
|
|
|
|
} catch (PDOException $e) {
|
2022-12-13 15:46:24 +01:00
|
|
|
\Sentry\captureException($e);
|
|
|
|
dd($e);
|
|
|
|
throw new PDOException();
|
|
|
|
}
|
|
|
|
if ($password) {
|
2022-12-14 16:38:46 +01:00
|
|
|
return [
|
|
|
|
$password[$this->sqlLoginRequest->egtPasswordColumnName()],
|
|
|
|
isset($password[$this->sqlLoginRequest->getSaltColumnName()]) ? $password[$this->sqlLoginRequest->getSaltColumnName()] : null,
|
|
|
|
];
|
2022-12-09 17:31:07 +01:00
|
|
|
}
|
|
|
|
|
2022-12-13 15:46:24 +01:00
|
|
|
return false;
|
2022-12-09 17:31:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getConnection()
|
|
|
|
{
|
|
|
|
// Appel du singleton
|
2022-12-14 16:38:46 +01:00
|
|
|
$pdo = SQLLoginConnect::getInstance();
|
2022-12-09 17:31:07 +01:00
|
|
|
// Connection bdd
|
2022-12-14 16:38:46 +01:00
|
|
|
return $pdo->connect($this->sqlLoginRequest->getDatabaseDsn(), $this->sqlLoginRequest->getDbUser(), $this->sqlLoginRequest->getDbPassword());
|
2022-12-09 17:31:07 +01:00
|
|
|
}
|
|
|
|
}
|