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.
ProjetPHP/model/UserModel.php

83 lines
2.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
require('business/User.php');
require('dal/UserGateway.php');
require_once("config/config.php");
class UserModel{
private $con;
private $gat;
private $TMessage;
public function __construct(Connection $con, $TMessage) {
$this->TMessage = $TMessage;
$this->con = $con;
$this->gat = new UserGateway($con);
}
function connexion($login, $mdp){
Validation::val_form_texte($login, $this->TMessage);
Validation::val_form_mdp($mdp, $this->TMessage);
$result = $this->gat->findUser($login, $mdp);
if(!isset($result)) echo 'not set works';
else
{
$_SESSION['login'] = $result;
}
}
function deconnexion(){
session_unset();
session_destroy();
}
function isConnected(){ //teste rôle dans la session, retourne instance dobjet ou booleen
Validation::val_form_texte($_SESSION['login'], $this->TMessage);
if(isset($_SESSION['login']) && $_SESSION['login']!="")
return true;
else
return false;
}
function ajouter($login, $mdp){
Validation::val_form_texte($login, $this->TMessage);
Validation::val_form_mdp($mdp, $this->TMessage);
$user = $this->findByLogin($login);
if (empty($user))
$this->gat->create($login, $mdp);
}
function supprimer($login){
Validation::val_form_texte($login, $this->TMessage);
$this->gat->delete($login);
}
function modifMdp($login, $mdp){
Validation::val_form_texte($login, $this->TMessage);
Validation::val_form_mdp($mdp, $this->TMessage);
$this->gat->updateMdp($login, $mdp);
}
function findByLogin($login){
Validation::val_form_texte($login, $this->TMessage);
$user = null;
if ($login !== " " && $login != null )
{
$results = $this->gat->find($login, 'login');
foreach($results as $row){
$user = new User($results['login']);
}
return $user;
}
}
function modifLogin($oldLogin, $newLogin){
Validation::val_form_texte($oldLogin, $this->TMessage);
Validation::val_form_texte($newLogin, $this->TMessage);
$user = $this->findByLogin($oldLogin);
if (empty($user))
$this->gat->updateLogin($oldLogin, $newLogin);
}
}
?>