microserviciile de register, login finalizate
This commit is contained in:
Executable
+48
@@ -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];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user