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.
Scripted/WEB/Controller/Controller.php

129 lines
3.7 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;
try {
$gateway = new JoueurGateway($this->con);
$validation = new Validation();
if (! $validation->ValidateEmail($_REQUEST['email'])) {
throw (new Exception("Email non valide"));
}
$joueur = new Joueur($_REQUEST['email'], $_REQUEST['username'], $_REQUEST['password']);
$gateway->insert($joueur);
$_SESSION['connected'] = 'true';
require ($rep.$vues['main']);;
}catch (Exception $e){
require($rep.$vues['erreurSignUp']);
}
}
private function login(){
global $rep, $vues;
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 ($mdp != $_REQUEST['password']){
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']);
}
}
}