microserviciile de register, login finalizate

This commit is contained in:
Cerbu Andrei Mihnea
2023-06-15 22:21:53 +03:00
parent a739a66ae4
commit 4e585ba278
159 changed files with 4775 additions and 1747 deletions
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace app\models;
use app\core\AuthInterface;
use app\exceptions\GenericErrorException;
use app\exceptions\UserNotExistingException;
use Exception;
use mysqli;
class LoginModel implements AuthInterface
{
private ?mysqli $conn = NULL;
private array $config;
public function __construct()
{
$this->config = $_SESSION['database_configuration'];
}
/**
* @throws GenericErrorException
*/
public function createConnection(): void
{
try {
$this->conn = new mysqli($this->config['dsn'], $this->config['user'], $this->config['password'], $this->config['dbname']);
} catch (Exception){
throw new GenericErrorException();
}
}
/**
* @throws UserNotExistingException
*/
public function executeReq(array $body): int|string
{
$email = $body["email"];
$password = $body["password"];
$query = "SELECT id FROM Users WHERE email = '$email' AND password = '$password'";
$result = $this->conn->query($query);
if(!$result->num_rows) throw new UserNotExistingException();
$row = mysqli_fetch_row($result);
return $row[0];
}
}