You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
<?php
|
|
|
|
namespace App\Gateway;
|
|
|
|
use App\Connexion;
|
|
use PDO;
|
|
|
|
class AuthGateway {
|
|
private Connexion $con;
|
|
|
|
/**
|
|
* @param Connexion $con
|
|
*/
|
|
public function __construct(Connexion $con) {
|
|
$this->con = $con;
|
|
}
|
|
|
|
|
|
public function mailExist(string $email): bool {
|
|
return $this->getUserFields($email) != null;
|
|
}
|
|
|
|
|
|
public function insertAccount(string $username, string $hash, string $email): void {
|
|
$this->con->exec("INSERT INTO AccountUser VALUES (:username,:hash,:email)", [':username' => [$username, PDO::PARAM_STR],':hash' => [$hash, PDO::PARAM_STR],':email' => [$email, PDO::PARAM_STR]]);
|
|
}
|
|
|
|
public function getUserHash(string $email): string {
|
|
$results = $this->con->fetch("SELECT hash FROM AccountUser WHERE email = :email", [':email' => [$email, PDO::PARAM_STR]]);
|
|
return $results[0]['hash'];
|
|
}
|
|
|
|
|
|
/**
|
|
* @param string $email
|
|
* @return array<string,string>|null
|
|
*/
|
|
public function getUserFields(string $email): ?array {
|
|
$results = $this->con->fetch("SELECT username,email FROM AccountUser WHERE email = :email", [':email' => [$email, PDO::PARAM_STR]]);
|
|
$firstRow = $results[0] ?? null;
|
|
return $firstRow;
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|