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.3 KiB
48 lines
1.3 KiB
<?php
|
|
|
|
namespace IQBall\Core\Gateway;
|
|
|
|
use IQBall\Core\Connection;
|
|
use PDO;
|
|
|
|
class AuthGateway {
|
|
private Connection $con;
|
|
|
|
/**
|
|
* @param Connection $con
|
|
*/
|
|
public function __construct(Connection $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(username, hash, email) 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;
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|