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.
136 lines
4.1 KiB
136 lines
4.1 KiB
<?php
|
|
|
|
class Controller
|
|
{
|
|
private Connection $con;
|
|
|
|
/**
|
|
* @param Connection $con
|
|
*/
|
|
function __construct(Connection $con) {
|
|
$this->con=$con;
|
|
session_start();
|
|
try{
|
|
global $rep, $vues;
|
|
$action=$_REQUEST['action'];
|
|
switch($action) {
|
|
case NULL:
|
|
require ($rep.$vues['main']);
|
|
break;
|
|
case "signUp":
|
|
$this->signUp();
|
|
break;
|
|
case "login":
|
|
$this->login();
|
|
break;
|
|
case "goToPresentation":
|
|
$this->goToPresentation();
|
|
break;
|
|
case "goToHome":
|
|
$this->goToHome();
|
|
break;
|
|
case "goToLogin":
|
|
$this->goToLogin();
|
|
break;
|
|
case "goToSignUp":
|
|
$this->goToSignUp();
|
|
break;
|
|
case "goToEnigme":
|
|
$this->goToEnigme();
|
|
break;
|
|
}
|
|
} catch (PDOException $e)
|
|
{
|
|
require ($rep.$vues['erreurBd']);
|
|
}
|
|
}
|
|
|
|
private function signUp() {
|
|
global $rep, $vues, $sel;
|
|
try {
|
|
$gateway = new JoueurGateway($this->con);
|
|
$validation = new Validation();
|
|
if (! $validation->ValidateEmail($_REQUEST['email'])) {
|
|
throw (new Exception("Email non valide"));
|
|
}
|
|
if(! $validation->ValidateUsername($_REQUEST['username'])){
|
|
throw(new Exception("Pseudo non valide"));
|
|
}
|
|
if(! $validation->ValidatePassword($_REQUEST['password'])){
|
|
throw(new InvalidMdpException("Mot de passe non valide"));
|
|
}
|
|
$password = password_hash($_REQUEST['password']+$selNoHash, PASSWORD_DEFAULT);
|
|
$joueur = new Joueur($_REQUEST['email'], $_REQUEST['username'], $password);
|
|
$gateway->insert($joueur);
|
|
$_SESSION['connected'] = 'true';
|
|
require ($rep.$vues['main']);
|
|
}catch (Exception $e){
|
|
require($rep.$vues['erreurSignUp']);
|
|
}
|
|
}
|
|
private function login(){
|
|
global $rep, $vues, $sel;
|
|
try {
|
|
$gateway = new JoueurGateway($this->con);
|
|
$joueur = $gateway->getJoueurByEmail($_REQUEST['email']);
|
|
if ($joueur->getEmail() == null){
|
|
throw new JoueurNotFoundException("Joueur introuvable");
|
|
}
|
|
$mdp = $gateway->getMdpByEmail($_REQUEST['email']);
|
|
if (password_verify($mdp, $_REQUEST['password']+$sel)){
|
|
throw new InvalidMdpException("Mot de passe invalide");
|
|
}
|
|
$_SESSION['connected'] = 'true';
|
|
require ($rep.$vues['main']);
|
|
}catch (JoueurNotFoundException $e){
|
|
require($rep.$vues['erreurLoginEmail']);
|
|
}catch (InvalidMdpException $m) {
|
|
require($rep . $vues['erreurLoginMdp']);
|
|
}
|
|
}
|
|
|
|
private function goToPresentation() {
|
|
global $rep, $vues;
|
|
try {
|
|
require ($rep.$vues['presenation']);
|
|
}catch (Exception $e){
|
|
require($rep.$vues['erreur404']);
|
|
}
|
|
}
|
|
|
|
private function goToHome() {
|
|
global $rep, $vues;
|
|
try {
|
|
require ($rep.$vues['main']);
|
|
}catch (Exception $e){
|
|
require($rep.$vues['erreur404']);
|
|
}
|
|
}
|
|
|
|
private function goToLogin() {
|
|
global $rep, $vues;
|
|
try {
|
|
require ($rep.$vues['login']);
|
|
}catch (Exception $e){
|
|
require($rep.$vues['erreur404']);
|
|
}
|
|
}
|
|
|
|
private function goToSignUp() {
|
|
global $rep, $vues;
|
|
try {
|
|
require ($rep.$vues['signUp']);
|
|
}catch (Exception $e){
|
|
require($rep.$vues['erreur404']);
|
|
}
|
|
}
|
|
|
|
private function goToEnigme() {
|
|
global $rep, $vues;
|
|
try {
|
|
require ($rep.$vues['enigme']);
|
|
}catch (Exception $e){
|
|
require($rep.$vues['erreur404']);
|
|
}
|
|
}
|
|
} |