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

74 lines
2.5 KiB

<?php
require 'JoueurGateway.php';
require '../Config/Validation.php';
require './JoueurNotFoundException.php';
require './InvalidMdpException.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 ('../View/src/pages/Main.html');
header('Location: http://londres.uca.local/~nogarnier1/Scripted/WEB/View/src/pages/Main.html');
break;
case "signUp":
$this->signUp();
break;
case "login":
$this->login();
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);
//$gateway->showAll();
header('Location: http://londres.uca.local/~nogarnier1/Scripted/WEB/View/src/pages/Main.html');
}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");
}
header('Location: http://londres.uca.local/~nogarnier1/Scripted/WEB/View/src/pages/Main.html');
}catch (JoueurNotFoundException $e){
require($rep.$vues['erreurLoginEmail']);
}catch (InvalidMdpException $m) {
require($rep . $vues['erreurLoginMdp']);
}
}
}