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.
SAE_2A_FA-Reseau_ALICA/php/src/modele/UtilisateurModele.php

108 lines
3.8 KiB

<?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\metier\Alumni
*/
public function connection(string $email, string $mdp) : ? \App\metier\Alumni
{
$dsn = "mysql:host=localhost;dbname=dbAlica";
$username = "Dev";
$password = "Dev";
$con = new \App\gateway\Connection($dsn, $username, $password);
$gate = new \App\gateway\AlumniGateway($con);
// Récupérez l'utilisateur avec l'email donné en utilisant AlumniGateway
$utilisateur = $gate->findByEmail($email);
if ($utilisateur instanceof \App\metier\Alumni) {
// L'utilisateur existe, vérifiez le mot de passe
if (password_verify($mdp, $utilisateur->getPassword())) {
// Le mot de passe est correct, retournez l'utilisateur
session_start();
return $utilisateur;
} else {
// Le mot de passe est incorrect, renvoyez null
return null;
}
} else {
// L'utilisateur n'existe pas, renvoyez null
return null;
}
}
/**
* @description s'inscrire
* @param string email
* @param string hash
* @param string $pseudo
* @return \Alumni chargé
*/
public function inscription(string $prenom, string $nom,string $email, string $hashpassword):? \App\metier\Alumni
{
$dsn = "mysql:host=localhost;dbname=dbAlica";
$username = "test";
$password = "test";
$role = "Membre";
$con = new \App\gateway\Connection($dsn, $username, $password);
$gate = new \App\gateway\AlumniGateway($con);
$profilGate = new \App\gateway\ProfilGateway($con);
// Insérez le nouvel utilisateur dans la base de données en utilisant AlumniGateway
if ($gate->insert($email, $hashpassword, $role)) {
// <<<<<<< HEAD
// // L'insertion a réussi, retournez le nouvel utilisateur
// $nouvelUtilisateur = new \App\metier\Alumni($email, $hashpassword, $role);
// return $nouvelUtilisateur;
// } else {
// // L'insertion a échoué, renvoyez un utilisateur vide pour indiquer l'échec
// return new \App\metier\Alumni(null, null, null);
// =======
$alumni = $gate->getID($email);
if($profilGate->insert($alumni,$nom, $prenom,$email)){
// L'insertion a réussi, retournez le nouvel utilisateur
$nouvelUtilisateur = new \App\metier\Alumni($email, $hashpassword, $role,$nom,$prenom);
return $nouvelUtilisateur;
}
return null;
} else {
// L'insertion a échoué, renvoyez un utilisateur vide pour indiquer l'échec
return null;
}
}
public function getUtilisateurByEmail(string $email)
{
$dsn = "mysql:host=localhost;dbname=dbAlica";
$username = "Dev";
$password = "Dev";
$con = new \App\gateway\Connection($dsn, $username, $password);
$gate = new \App\gateway\AlumniGateway($con);
// Récupérez l'utilisateur avec l'email donné en utilisant AlumniGateway
$utilisateur = $gate->findByEmail($email);
if ($utilisateur instanceof \App\metier\Alumni) {
// L'utilisateur existe, retournez-le
return $utilisateur;
} else {
// L'utilisateur n'existe pas, renvoyez null
return null;
}
}
}