2022-12-14 16:38:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\SQLLogin;
|
|
|
|
|
|
|
|
class SQLLoginRequest
|
|
|
|
{
|
|
|
|
public const DATA_TO_FETCH = 'data_to_fetch';
|
|
|
|
public const LOGIN_COLUMN_NAME = 'login_column_name';
|
|
|
|
public const SALT_COLUMN_NAME = 'salt_column_name';
|
|
|
|
public const PASSWORD_COLUMN_NAME = 'password_column_name';
|
2022-12-16 15:00:14 +01:00
|
|
|
public const PASSWORD_NEED_UPGRADE = 'password_need_upgrade';
|
2022-12-14 16:38:46 +01:00
|
|
|
public const TABLE_NAME = 'table_name';
|
|
|
|
|
|
|
|
protected array $config;
|
|
|
|
protected string $dsn;
|
|
|
|
protected string $user;
|
|
|
|
protected string $password;
|
|
|
|
|
|
|
|
public function __construct(array $config = [], string $dsn, string $user, string $password)
|
|
|
|
{
|
|
|
|
$this->config = $config;
|
|
|
|
$this->dsn = $dsn;
|
|
|
|
$this->user = $user;
|
|
|
|
$this->password = $password;
|
|
|
|
}
|
|
|
|
|
2022-12-16 15:00:14 +01:00
|
|
|
public function getDatabaseDsn(): string
|
2022-12-14 16:38:46 +01:00
|
|
|
{
|
|
|
|
return $this->dsn;
|
|
|
|
}
|
|
|
|
|
2022-12-16 15:00:14 +01:00
|
|
|
public function getDbUser(): string
|
2022-12-14 16:38:46 +01:00
|
|
|
{
|
|
|
|
return $this->user;
|
|
|
|
}
|
|
|
|
|
2022-12-16 15:00:14 +01:00
|
|
|
public function getDbPassword(): string
|
2022-12-14 16:38:46 +01:00
|
|
|
{
|
|
|
|
return $this->password;
|
|
|
|
}
|
|
|
|
|
2022-12-16 15:00:14 +01:00
|
|
|
public function getLoginColumnName(): string
|
2022-12-14 16:38:46 +01:00
|
|
|
{
|
|
|
|
return $this->config[self::LOGIN_COLUMN_NAME];
|
|
|
|
}
|
|
|
|
|
2022-12-16 15:00:14 +01:00
|
|
|
public function getPasswordColumnName(): string
|
2022-12-14 16:38:46 +01:00
|
|
|
{
|
|
|
|
return $this->config[self::PASSWORD_COLUMN_NAME];
|
|
|
|
}
|
|
|
|
|
2022-12-16 15:00:14 +01:00
|
|
|
public function getSaltColumnName(): ?string
|
2022-12-14 16:38:46 +01:00
|
|
|
{
|
|
|
|
return $this->config[self::SALT_COLUMN_NAME];
|
|
|
|
}
|
|
|
|
|
2022-12-16 15:00:14 +01:00
|
|
|
public function getTableName(): string
|
|
|
|
{
|
|
|
|
return $this->config[self::TABLE_NAME];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDataToFetch(): array
|
|
|
|
{
|
|
|
|
return $this->config[self::DATA_TO_FETCH];
|
|
|
|
}
|
|
|
|
|
2022-12-14 16:38:46 +01:00
|
|
|
public function getRequestScope()
|
|
|
|
{
|
|
|
|
$scope = '';
|
|
|
|
foreach ($this->config[self::DATA_TO_FETCH] as $data) {
|
|
|
|
$scope .= $data.',';
|
|
|
|
}
|
|
|
|
$scope = substr($scope, 0, -1);
|
|
|
|
|
2022-12-16 15:00:14 +01:00
|
|
|
return 'SELECT '.$scope.' FROM '.$this->getTableName().' WHERE '.$this->getLoginColumnName().' = :'.$this->getLoginColumnName().';';
|
2022-12-14 16:38:46 +01:00
|
|
|
}
|
|
|
|
|
2022-12-16 15:00:14 +01:00
|
|
|
/**
|
|
|
|
* Construction de la string pour la requête préparée selon la configuration yaml
|
|
|
|
* intègre la récupération du mot de passe hashé, du salt et de besoin d'upgrade de la méthode de hashage
|
|
|
|
*/
|
2022-12-14 16:38:46 +01:00
|
|
|
public function getRequestPassword()
|
|
|
|
{
|
2022-12-16 15:00:14 +01:00
|
|
|
$fields = $this->getPasswordColumnName();
|
|
|
|
if (!empty($this->getSaltColumnName())) {
|
|
|
|
$fields .= ', '.$this->getSaltColumnName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'SELECT '.$fields.' FROM '.$this->getTableName().' WHERE '.$this->getLoginColumnName().' = :'.$this->getLoginColumnName().';';
|
|
|
|
}
|
2022-12-14 16:38:46 +01:00
|
|
|
}
|