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.
39 lines
932 B
39 lines
932 B
<?php
|
|
|
|
namespace model;
|
|
|
|
use gateway\UserGateway;
|
|
|
|
abstract class AbsModel
|
|
{
|
|
public function connection(string $login, string $password){
|
|
$gtw = new UserGateway();
|
|
$hash = $gtw->login($login) ?? null;
|
|
|
|
if ($hash != null && password_verify($password, $hash)) {
|
|
$user = $gtw->findUserByEmail($login);
|
|
$_SESSION['login'] = $login;
|
|
|
|
$roles = array();
|
|
foreach ($user->getRoles() as $role) $roles[] = $role;
|
|
$_SESSION['roles'] = $roles;
|
|
|
|
return $user;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function deconnection(){
|
|
session_unset();
|
|
session_destroy();
|
|
$_SESSION = array();
|
|
}
|
|
|
|
public function checkLoginExist(string $login): bool {
|
|
$gtw = new UserGateway();
|
|
return $gtw->findUserByEmail($login) != null;
|
|
}
|
|
|
|
public abstract function is(string $login, array $roles): User;
|
|
} |