ADD: gestion des erreurs pour la connction et l'inscription (manque encore le sanitize)

master
Lucie Bedouret 2 years ago
parent 87163c1035
commit ba0806aab2

@ -3,30 +3,25 @@
class Validation { class Validation {
static function val_connexion($usrName,$mdp,$dataVueEreur) { static function val_connexion($usrName,$mdp,$dataVueEreur) {
if (!isset($usrName)||$usrName=="") { if (!isset($usrName)||$usrName=="") {
$dataVueEreur[] ="Nom d'utilisateur manquant"; $dataVueEreur[] ="Username or password missing";
throw new Exception('pas de username');
} }
$usrName = Validation::clear_string($usrName); $usrName = Validation::clear_string($usrName);
if($usrName == false){ if($usrName == false){
$dataVueEreur[] = "Sanitizing error"; $dataVueEreur[] = "Sanitizing error";
throw new Exception('sanitizing fail');
} }
if (!isset($mdp)||$mdp=="") { if (!isset($mdp)||$mdp=="") {
$dataVueEreur[] ="Mot de passe manquant"; $dataVueEreur[] ="Username or password missing";
throw new Exception('pas de password');
} }
$mdp = Validation::clear_string($mdp); $mdp = Validation::clear_string($mdp);
if($mdp == false){ if($mdp == false){
$dataVueEreur[] = "Sanitizing error"; $dataVueEreur[] = "Sanitizing error";
throw new Exception('sanitizing fail');
} }
return $dataVueEreur; return $dataVueEreur;
} }
static function val_inscription($username,$pwd1,$pwd2,$dataVueEreur){ static function val_inscription($username,$pwd1,$pwd2,$dataVueEreur){
if (!isset($username)||$username==="") { if (!isset($username)||$username==="") {
$dataVueEreur[] ="Nom d'utilisateur manquant"; $dataVueEreur[] ="All fields are required";
throw new Exception('pas de username');
} }
$username = Validation::clear_string($username); $username = Validation::clear_string($username);
if($username == false){ if($username == false){
@ -34,26 +29,21 @@
throw new Exception('sanitizing fail'); throw new Exception('sanitizing fail');
} }
if (!isset($pwd1)||$pwd1==="") { if (!isset($pwd1)||$pwd1==="") {
$dataVueEreur[] ="Mot de passe manquant"; $dataVueEreur[] ="All fields are required";
throw new Exception('pas de password');
} }
$pwd1 = Validation::clear_string($pwd1); $pwd1 = Validation::clear_string($pwd1);
if($pwd1 == false){ if($pwd1 == false){
$dataVueEreur[] = "Sanitizing error"; $dataVueEreur[] = "Sanitizing error";
throw new Exception('sanitizing fail');
} }
if (!isset($pwd2)||$pwd2==="") { if (!isset($pwd2)||$pwd2==="") {
$dataVueEreur[] ="Confirmation mot de passe manquant"; $dataVueEreur[] ="All fields are required";
throw new Exception('pas de confirmation password');
} }
$pwd2 = Validation::clear_string($pwd2); $pwd2 = Validation::clear_string($pwd2);
if($pwd2 == false){ if($pwd2 == false){
$dataVueEreur[] = "Sanitizing error"; $dataVueEreur[] = "Sanitizing error";
throw new Exception('sanitizing fail');
} }
if($pwd1 !== $pwd2){ if($pwd1 !== $pwd2){
$dataVueEreur[]="Mot de passe et confirmation différents"; $dataVueEreur[]="Invalid confirmation";
throw new Exception("Mot de passe et confirmation différents");
} }
return $dataVueEreur; return $dataVueEreur;
} }

@ -122,6 +122,9 @@ class ControleurVisiteur {
$usrname=$_POST['login']; $usrname=$_POST['login'];
$pwd=$_POST['mdp']; $pwd=$_POST['mdp'];
$vues_erreur=Validation::val_connexion($usrname,$pwd,$vues_erreur); $vues_erreur=Validation::val_connexion($usrname,$pwd,$vues_erreur);
if(!empty($vues_erreur)){
require($rep.$vues['connection']);
}
$model= new VisiteurModel(); $model= new VisiteurModel();
if($model->existUser($usrname)){ if($model->existUser($usrname)){
if(password_verify($pwd,$model->getHashedPassword($usrname))){ if(password_verify($pwd,$model->getHashedPassword($usrname))){
@ -130,13 +133,13 @@ class ControleurVisiteur {
$this->reinit(); $this->reinit();
} }
else{ else{
$arrayErrorViews =array('username'=>$usrname,'password'=>$pwd); $vues_erreur =array('username'=>$usrname,'password'=>$pwd);
require($rep.$vues['erreur']); require($rep.$vues['connection']);
} }
} }
else{ else{
$arrayErrorViews =array('username'=>$usrname,'password'=>$pwd); $vues_erreur =array('username'=>$usrname,'password'=>$pwd);
require($rep.$vues['erreur']); require($rep.$vues['connection']);
} }
} }
@ -145,12 +148,19 @@ class ControleurVisiteur {
$usrname=$_POST['username']; $usrname=$_POST['username'];
$pwd=$_POST['password']; $pwd=$_POST['password'];
$confirm=$_POST['confirmpassword']; $confirm=$_POST['confirmpassword'];
$model = new VisiteurModel();
$vues_erreur=Validation::val_inscription($usrname,$pwd,$confirm,$vues_erreur); $vues_erreur=Validation::val_inscription($usrname,$pwd,$confirm,$vues_erreur);
if($vues_erreur == []){ if($model->existUser($usrname)){
$vues_erreur[]="Username already taken";
}
if(empty($vues_erreur)){
$hash= password_hash($pwd,PASSWORD_DEFAULT); $hash= password_hash($pwd,PASSWORD_DEFAULT);
$model = new VisiteurModel();
$model->inscription($usrname,$hash); $model->inscription($usrname,$hash);
} }
else{
require($rep.$vues['inscription']);
}
$_REQUEST['action']=null; $_REQUEST['action']=null;
new ControleurVisiteur(); new ControleurVisiteur();
} }

@ -10,6 +10,12 @@ h1{
margin-left: 5%; margin-left: 5%;
} }
#error{
margin-top: 5%;
margin-bottom: -5%;
margin-left: 29%;
}
#connectionForm{ #connectionForm{
background-color: #E4F8FF; background-color: #E4F8FF;
width: 50%; width: 50%;

@ -3,8 +3,8 @@
<head> <head>
<title>Acceuil</title> <title>Acceuil</title>
<link rel="stylesheet" href="<?=$styles['commun']?>"/> <link rel="stylesheet" href="styles/commonStyles.css"/>
<link rel="stylesheet" href="<?=$styles['acceuil']?>"/> <link rel="stylesheet" href="styles/acceuilStyles.css"/>
</head> </head>
<body> <body>

@ -2,8 +2,8 @@
<html> <html>
<head> <head>
<title>connection</title> <title>connection</title>
<link rel="stylesheet" href="<?=$styles['commun']?>"/> <link rel="stylesheet" href="styles/commonStyles.css"/>
<link rel="stylesheet" href="<?=$styles['connection']?>"/> <link rel="stylesheet" href="styles/connectionStyles.css"/>
</head> </head>
<body> <body>
<header> <header>
@ -15,12 +15,15 @@
</header> </header>
<div class="body"> <div class="body">
<form method="POST" name="connectionForm" id="connectionForm"> <form method="POST" name="connectionForm" id="connectionForm">
<h4>Login</h4> <h4>Username</h4>
<input type="text" name="login" required/> <input type="text" name="login" required/>
<h4>Password</h4> <h4>Password</h4>
<input type="password" name="mdp" required/> <input type="password" name="mdp" required/>
<br/> <?php
<br/> if(isset($vues_erreur)){
echo '<h4 id="error">Incorrect Username or Password</h4>';
}
?>
<input class="button" type="submit" value="Log In"/> <input class="button" type="submit" value="Log In"/>
<input type="hidden" name="action" value="connection"> <input type="hidden" name="action" value="connection">
</form> </form>

@ -2,8 +2,8 @@
<html> <html>
<head> <head>
<title>connection</title> <title>connection</title>
<link rel="stylesheet" href="<?=$styles['commun']?>"> <link rel="stylesheet" href="styles/commonStyles.css"/>
<link rel="stylesheet" href="<?=$styles['connection']?>"> <link rel="stylesheet" href="styles/connectionStyles.css"/>
</head> </head>
<body> <body>
<header> <header>
@ -16,13 +16,17 @@
<div class="body"> <div class="body">
<h2>Please enter all the informations :</h2> <h2>Please enter all the informations :</h2>
<form method="POST" name="inscription" id="connectionForm"> <form method="POST" name="inscription" id="connectionForm">
<h4>Login</h4> <h4>Username</h4>
<input type="text" name="username" required/> <input type="text" name="username" required/>
<h4>Password</h4> <h4>Password</h4>
<input type="password" name="password" required/> <input type="password" name="password" required/>
<h4>Confirm Password</h4> <h4>Confirm Password</h4>
<input type="password" name="confirmpassword" required/> <input type="password" name="confirmpassword" required/>
<br/> <?php
if(isset($vues_erreur)){
echo '<h4 id="error">'.$vues_erreur[0].'</h4>';
}
?>
<input class="button" type="submit" value="Sign Up"/> <input class="button" type="submit" value="Sign Up"/>
<input type="hidden" name="action" value="inscription"/> <input type="hidden" name="action" value="inscription"/>
</form> </form>

Loading…
Cancel
Save