inscription fonctionnel (pages d'erreurs et success à ajouter) + nouvelle architecture #35
Merged
leo.tuaillon
merged 2 commits from inscription-connection
into master
1 year ago
@ -0,0 +1,6 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteBase /php/public/
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^(.*)$ index.php [QSA,L]
|
||||
</IfModule>
|
@ -1,12 +1,11 @@
|
||||
{
|
||||
"require": {
|
||||
"twig/twig": "^3.0"
|
||||
"twig/twig": "^3.0",
|
||||
"ext-pdo": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"controleur\\": "controleur/",
|
||||
"config\\": "config/",
|
||||
"modeles\\": "modeles/"
|
||||
"App\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
//gen
|
||||
$rep = __DIR__ . '/../';
|
||||
|
||||
// liste des modules à inclure
|
||||
$dConfig['includes']= array('controleur/Validation.php');
|
||||
|
||||
//BD
|
||||
$base = '';
|
||||
$login = '';
|
||||
$mdp = '';
|
@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace controleur;
|
||||
|
||||
use config\Validation;
|
||||
|
||||
class UtilisateurControleur
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
global $twig;
|
||||
if (!isset($_REQUEST["action"])) {
|
||||
$action = NULL;
|
||||
} else {
|
||||
$action = Validation::nettoyerString($_REQUEST["action"]);
|
||||
}
|
||||
switch ($action) {
|
||||
case NULL:
|
||||
case "accueil":
|
||||
$this->accueil();
|
||||
break;
|
||||
case "connection":
|
||||
$this->connection();
|
||||
break;
|
||||
case "inscription":
|
||||
$this->inscription();
|
||||
break;
|
||||
case "consulterProfilLimite":
|
||||
$this->consulterProfilLimite();
|
||||
break;
|
||||
default:
|
||||
$dVueErreur[] ="Action inconnue ou non autorisée";
|
||||
echo $twig->render("erreur.html",['dVueErreur' => $dVueErreur]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected function connection()
|
||||
{
|
||||
global $twig;
|
||||
echo $twig->render('connexion.html', []);
|
||||
}
|
||||
|
||||
protected function inscription()
|
||||
{
|
||||
global $twig;
|
||||
echo $twig->render('inscription.html', []);
|
||||
}
|
||||
|
||||
protected function accueil()
|
||||
{
|
||||
global $twig;
|
||||
echo $twig->render('accueil.html', []);
|
||||
}
|
||||
|
||||
protected function consulterProfilLimite()
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
/** PC IUT - PHP 8.1 */
|
||||
|
||||
/** Chargement config */
|
||||
require_once __DIR__ . '/config/config.php';
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
use controleur\FrontControleur;
|
||||
|
||||
/** Configuration twig */
|
||||
$loader = new \Twig\Loader\FilesystemLoader('vues');
|
||||
$twig = new \Twig\Environment($loader, [
|
||||
'cache' => false,
|
||||
'debug' => true
|
||||
]);
|
||||
|
||||
$cont = new \controleur\FrontControleur();
|
@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace modeles;
|
||||
|
||||
class ModerateurControleur
|
||||
{
|
||||
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
namespace modeles;
|
||||
|
||||
class UtilisateurModele
|
||||
{
|
||||
/**
|
||||
* @description Charger le flux d'activiter
|
||||
* @return array flux
|
||||
*/
|
||||
public function LoadFeed() : array
|
||||
{
|
||||
// TO DO
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @description se connecter
|
||||
* @param string email
|
||||
* @param string hash
|
||||
* @return \Alumni
|
||||
*/
|
||||
public function Login(string $email,string $hash) : \Alumni
|
||||
{
|
||||
// TO DO
|
||||
return new \Alumni(null,null,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description s'inscrire
|
||||
* @param string email
|
||||
* @param string hash
|
||||
* @param string $pseudo
|
||||
* @return \Alumni chargé
|
||||
*/
|
||||
public function signIn(string $email,string $pseudo,string $hash) : \Alumni
|
||||
{
|
||||
// TO DO
|
||||
return new Compte(null,null,null);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/** PC IUT - PHP 8.1 */
|
||||
|
||||
/** Chargement config */
|
||||
require_once __DIR__ . '/../src/config/config.php';
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
|
||||
/** Configuration twig */
|
||||
$loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/../templates');
|
||||
$twig = new \Twig\Environment($loader, [
|
||||
'cache' => false,
|
||||
'debug' => true
|
||||
]);
|
||||
|
||||
$cont = new \App\controleur\FrontControleur();
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
spl_autoload_register(function ($class) {
|
||||
$prefix = 'MyProject\\';
|
||||
$baseDir = __DIR__;
|
||||
|
||||
$class = ltrim($class, '\\');
|
||||
$file = '';
|
||||
|
||||
if (0 === strpos($class, $prefix)) {
|
||||
$class = substr($class, strlen($prefix));
|
||||
$file = $baseDir . '/' . str_replace('\\', '/', $class) . '.php';
|
||||
}
|
||||
|
||||
if (file_exists($file)) {
|
||||
require $file;
|
||||
}
|
||||
});
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace config;
|
||||
namespace App\config;
|
||||
|
||||
class Validation
|
||||
{
|
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace App\config;
|
||||
//gen
|
||||
$rep = __DIR__ . '/php/';
|
||||
|
||||
// liste des modules à inclure
|
||||
$dConfig['includes']= array('controleur/Validation.php');
|
||||
|
||||
//BD
|
||||
$base = 'mysql:host=localhost;dbname=dbAlica';
|
||||
$login = 'root';
|
||||
$mdp = '';
|
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\controleur;
|
||||
|
||||
class UtilisateurControleur
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
global $twig;
|
||||
if (!isset($_REQUEST["action"])) {
|
||||
$action = NULL;
|
||||
} else {
|
||||
$action = \App\config\Validation::nettoyerString($_REQUEST["action"]);
|
||||
}
|
||||
switch ($action) {
|
||||
case NULL:
|
||||
case "accueil":
|
||||
$this->accueil();
|
||||
break;
|
||||
case "connection":
|
||||
$this->connection();
|
||||
break;
|
||||
case "inscription":
|
||||
$this->inscription();
|
||||
break;
|
||||
case "consulterProfilLimite":
|
||||
$this->consulterProfilLimite();
|
||||
break;
|
||||
default:
|
||||
$dVueErreur[] ="Action inconnue ou non autorisée";
|
||||
echo $twig->render("erreur.html",['dVueErreur' => $dVueErreur]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected function connection()
|
||||
{
|
||||
global $twig;
|
||||
echo $twig->render('connexion.html', []);
|
||||
}
|
||||
|
||||
protected function inscription()
|
||||
{
|
||||
global $twig;
|
||||
$dVueErreur = []; // Tableau pour stocker les erreurs, le cas échéant
|
||||
|
||||
if (isset($_POST['email'], $_POST['username'], $_POST['password'])) {
|
||||
$email = \App\config\Validation::nettoyerString($_POST['email']);
|
||||
$motDePasse = \App\config\Validation::nettoyerString($_POST['password']);
|
||||
|
||||
|
||||
// Validez les données d'inscription, par exemple, vérifiez si l'email est unique
|
||||
// Vous pouvez également effectuer d'autres validations nécessaires
|
||||
|
||||
$userModel = new \App\modele\UtilisateurModele();
|
||||
$nouvelUtilisateur = $userModel->inscription($email, $motDePasse);
|
||||
|
||||
// Si l'inscription a réussi, redirigez l'utilisateur vers une page de confirmation
|
||||
// Vous pouvez également gérer les erreurs ici en cas d'échec de l'inscription
|
||||
|
||||
if ($nouvelUtilisateur instanceof \App\modele\Alumni) {
|
||||
// L'inscription a réussi, redirigez l'utilisateur vers une page de confirmation
|
||||
// par exemple :
|
||||
header('Location: index.php?action=inscription_success');
|
||||
exit();
|
||||
} else {
|
||||
// L'inscription a échoué, ajoutez un message d'erreur
|
||||
$dVueErreur[] = "L'inscription a échoué, veuillez réessayer.";
|
||||
}
|
||||
}
|
||||
|
||||
// Affichez le formulaire d'inscription ou les erreurs le cas échéant
|
||||
echo $twig->render('inscription.html', ['dVueErreur' => $dVueErreur]);
|
||||
}
|
||||
|
||||
protected function accueil()
|
||||
{
|
||||
global $twig;
|
||||
echo $twig->render('accueil.html', []);
|
||||
}
|
||||
|
||||
protected function consulterProfilLimite()
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +1,28 @@
|
||||
<?php
|
||||
namespace App\gateway;
|
||||
use PDO;
|
||||
|
||||
class AlumniGateway
|
||||
{
|
||||
private Connection $con;
|
||||
private \App\gateway\Connection $con;
|
||||
|
||||
/**
|
||||
* @param $con
|
||||
*/
|
||||
public function __construct(Connection $con){
|
||||
public function __construct(\App\gateway\Connection $con){
|
||||
$this->con = $con;
|
||||
}
|
||||
|
||||
public function insert(string $email, int $id, string $motDePasse, Role $role){
|
||||
$query='INSERT INTO Alumni VALUES (:i, :e, :m, :r)';
|
||||
$this->con->executeQuery($query, array(
|
||||
':i' => array($id, PDO::PARAM_INT),
|
||||
':e' => array($email, PDO::PARAM_STR),
|
||||
':m' => array($motDePasse, PDO::PARAM_STR),
|
||||
':r' => array($role, PDO::PARAM_STR)
|
||||
public function insert(string $email, string $motDePasse, string $role){
|
||||
$query = 'INSERT INTO Alumni (mail, mdp, role) VALUES (:mail, :mdp, :role)';
|
||||
return $this->con->executeQuery($query, array(
|
||||
':mail' => array($email, PDO::PARAM_STR),
|
||||
':mdp' => array($motDePasse, PDO::PARAM_STR),
|
||||
':role' => array($role, PDO::PARAM_STR)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public function updateEmail(int $id, string $newEmail){
|
||||
$query='UPDATE Alumni SET email=:new WHERE id=:i';
|
||||
$this->con->executeQuery($query, array(
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace App\gateway;
|
||||
use PDO;
|
||||
|
||||
class Connection extends PDO {
|
||||
class Connection extends \PDO {
|
||||
|
||||
/**
|
||||
* @var Statement
|
@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\gateway;
|
||||
class EvenementGateway
|
||||
{
|
||||
private Connection $con;
|
||||
private \App\gateway\Connection $con;
|
||||
|
||||
/**
|
||||
* @param $con
|
||||
*/
|
||||
public function __construct(Connection $con){
|
||||
public function __construct(\App\gateway\Connection $con){
|
||||
$this->con = $con;
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\gateway;
|
||||
class OffreGateway
|
||||
{
|
||||
private Connection $con;
|
||||
private \App\gateway\Connection $con;
|
||||
|
||||
/**
|
||||
* @param $con
|
||||
*/
|
||||
public function __construct(Connection $con){
|
||||
public function __construct(\App\gateway\Connection $con){
|
||||
$this->con = $con;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
namespace App\modele;
|
||||
|
||||
class Article
|
||||
{
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
namespace App\modele;
|
||||
|
||||
class Evenement
|
||||
{
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
namespace App\modele;
|
||||
|
||||
class Experience
|
||||
{
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
namespace App\modele;
|
||||
|
||||
class Formation
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace modeles;
|
||||
namespace App\modele;
|
||||
|
||||
class MembreModele extends UtilisateurModele
|
||||
{
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
namespace App\modele;
|
||||
|
||||
class Profil
|
||||
{
|
||||
/**
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace App\modele;
|
||||
enum Role
|
||||
{
|
||||
case Admin;
|
||||
case Moderateur;
|
||||
case Utilisateur;
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace App\modele;
|
||||
class UtilisateurModele
|
||||
{
|
||||
/**
|
||||
* @description Charger le flux d'activiter
|
||||
* @return array flux
|
||||
*/
|
||||
public function LoadFeed() : array
|
||||
{
|
||||
// TO DO
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @description se connecter
|
||||
* @param string email
|
||||
* @param string hash
|
||||
* @return \App\modele\Alumni
|
||||
*/
|
||||
public function Login(string $email,string $hash) : \App\modele\Alumni
|
||||
{
|
||||
// TO DO
|
||||
return new \App\modele\Alumni(null,null,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description s'inscrire
|
||||
* @param string email
|
||||
* @param string hash
|
||||
* @param string $pseudo
|
||||
* @return \Alumni chargé
|
||||
*/
|
||||
public function inscription(string $email, string $hashpassword): \App\modele\Alumni
|
||||
{
|
||||
$dsn = "mysql:host=localhost;dbname=dbAlica";
|
||||
$username = "Dev";
|
||||
$password = "Dev";
|
||||
|
||||
$role = "Utilisateur";
|
||||
$con = new \App\gateway\Connection($dsn, $username, $password);
|
||||
$gate = new \App\gateway\AlumniGateway($con);
|
||||
// Insérez le nouvel utilisateur dans la base de données en utilisant AlumniGateway
|
||||
if ($gate->insert($email, $hashpassword, $role)) {
|
||||
// L'insertion a réussi, retournez le nouvel utilisateur
|
||||
$nouvelUtilisateur = new \App\modele\Alumni($email, $hashpassword, $role);
|
||||
return $nouvelUtilisateur;
|
||||
} else {
|
||||
// L'insertion a échoué, renvoyez un utilisateur vide pour indiquer l'échec
|
||||
return new \App\modele\Alumni(null, null, null);
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue