|
|
@ -1,15 +1,12 @@
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
class Controller
|
|
|
|
class UserController
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private Connection $con;
|
|
|
|
private Connection $con;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
function __construct() {
|
|
|
|
* @param Connection $con
|
|
|
|
global $dsn, $user, $password;
|
|
|
|
*/
|
|
|
|
$this->con=new Connection($dsn, $user, $password);;
|
|
|
|
function __construct(Connection $con) {
|
|
|
|
|
|
|
|
$this->con=$con;
|
|
|
|
|
|
|
|
session_start();
|
|
|
|
|
|
|
|
try{
|
|
|
|
try{
|
|
|
|
global $rep, $vues, $error;
|
|
|
|
global $rep, $vues, $error;
|
|
|
|
$action=$_REQUEST['action'];
|
|
|
|
$action=$_REQUEST['action'];
|
|
|
@ -49,7 +46,7 @@ class Controller
|
|
|
|
private function signUp() {
|
|
|
|
private function signUp() {
|
|
|
|
global $rep, $vues, $sel, $error;
|
|
|
|
global $rep, $vues, $sel, $error;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
$gateway = new JoueurGateway($this->con);
|
|
|
|
$gateway = new UtilisateurGateway($this->con);
|
|
|
|
$validation = new Validation();
|
|
|
|
$validation = new Validation();
|
|
|
|
if (! $validation->ValidateEmail($_REQUEST['email'])) {
|
|
|
|
if (! $validation->ValidateEmail($_REQUEST['email'])) {
|
|
|
|
$error = "Email invalides.";
|
|
|
|
$error = "Email invalides.";
|
|
|
@ -63,41 +60,54 @@ class Controller
|
|
|
|
$error = "Mots de passe invalides. Il ne doit pas dépasser 100 caractères.";
|
|
|
|
$error = "Mots de passe invalides. Il ne doit pas dépasser 100 caractères.";
|
|
|
|
throw(new Exception("Mot de passe non valide"));
|
|
|
|
throw(new Exception("Mot de passe non valide"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$j = $gateway->getJoueurByEmail($_REQUEST['email']);
|
|
|
|
$j = $gateway->getUtilisateurByEmail($_REQUEST['email']);
|
|
|
|
if ($j != null) {
|
|
|
|
if ($j->getEmail() != "null") {
|
|
|
|
$error = "Email déjà utilisé.";
|
|
|
|
$error = "Email déjà utilisé.";
|
|
|
|
throw (new Exception("Email déjà utilisé"));
|
|
|
|
throw (new Exception("Email déjà utilisé"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT);
|
|
|
|
$password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT);
|
|
|
|
$joueur = new Joueur($_REQUEST['email'], $_REQUEST['username'], $password);
|
|
|
|
$utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, false);
|
|
|
|
$gateway->insert($joueur);
|
|
|
|
$gateway->insert($utilisateur);
|
|
|
|
$_SESSION['connected'] = 'true';
|
|
|
|
$_SESSION['connected'] = 'true';
|
|
|
|
|
|
|
|
$_SESSION['role'] = 'utilisateur';
|
|
|
|
require ($rep.$vues['main']);
|
|
|
|
require ($rep.$vues['main']);
|
|
|
|
}catch (Exception $e){
|
|
|
|
}catch (PDOException $e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$error = "Erreur de connexion à la base de données.";
|
|
|
|
|
|
|
|
require ($rep.$vues['erreur']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception $e){
|
|
|
|
require($rep.$vues['erreur']);
|
|
|
|
require($rep.$vues['erreur']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private function login(){
|
|
|
|
private function login(){
|
|
|
|
global $rep, $vues, $sel, $error;
|
|
|
|
global $rep, $vues, $sel, $error;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
$gateway = new JoueurGateway($this->con);
|
|
|
|
$gateway = new UtilisateurGateway($this->con);
|
|
|
|
$joueur = $gateway->getJoueurByEmail($_REQUEST['email']);
|
|
|
|
$utilisateur = $gateway->getUtilisateurByEmail($_REQUEST['email']);
|
|
|
|
if ($joueur->getEmail() == null){
|
|
|
|
if ($utilisateur->getEmail() == null){
|
|
|
|
$error = "Joueur non trouvé.";
|
|
|
|
$error = "Utilisateur non trouvé.";
|
|
|
|
throw new Exception("Joueur introuvable");
|
|
|
|
throw new Exception("Utilisateur introuvable");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$mdp = $gateway->getMdpByEmail($_REQUEST['email']);
|
|
|
|
$mdp = $gateway->getMdpByEmail($_REQUEST['email']);
|
|
|
|
if (password_verify($mdp, $_REQUEST['password'])){
|
|
|
|
if (password_verify($mdp, $_REQUEST['password'])){
|
|
|
|
$error = "Mot de passe incorrect.";
|
|
|
|
$error = "Mot de passe incorrect.";
|
|
|
|
throw new Exception("Mot de passe invalide");
|
|
|
|
throw new Exception("Mot de passe invalide");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$estAdmin =$gateway->getEstAdminByEmail($_REQUEST['email']);
|
|
|
|
|
|
|
|
if ($estAdmin == true) {
|
|
|
|
|
|
|
|
$_SESSION['role'] = "admin";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
$_SESSION['role'] = "utilisateur";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$_SESSION['connected'] = 'true';
|
|
|
|
$_SESSION['connected'] = 'true';
|
|
|
|
require ($rep.$vues['main']);
|
|
|
|
require ($rep.$vues['main']);
|
|
|
|
}catch (Exception $e){
|
|
|
|
}catch (Exception $e){
|
|
|
|
require($rep.$vues['erreur']);
|
|
|
|
require($rep.$vues['erreur']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// require error page with given message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function goToPresentation() {
|
|
|
|
private function goToPresentation() {
|
|
|
|
global $rep, $vues, $error;
|
|
|
|
global $rep, $vues, $error;
|