-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
39 lines (34 loc) · 1.37 KB
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
session_start();
require_once('./libs/config.php');
require_once('./src/models/User.php');
require_once('./src/models/UserManager.php');
$errors = [];
$messages = [];
// Pour rendre la page 'login.php' inaccessible si l'utilisateur est déjà connecté
if (isset($_SESSION['user'])) {
header('location: ./profil.php');
}
$manager = new UserManager;
//$check = '';
// On vérifie que le formulaire a bien été soumis
if (!empty($_POST)) {
// Vérification du bon remplissage des champs ET avec des champs non vides
if (isset($_POST['email'], $_POST['password']) && !empty($_POST['email']) && !empty($_POST['password'])) {
// Vérification si l'email est bien un email (le type 'email' n'est pas suffisant car modifiable en Front avec l'inspecteur de code)
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errors[] = 'Format d\'Email invalide';
} else {
// Email valide, instanciation de $checkUser
$checkUser = new User();
$checkUser->setEmail($_POST['email']);
$checkUser->setPassword($_POST['password']);
// On lance ensuite la vérification du Password
$check = $manager->verifyUserLoginPassword($checkUser);
$errors[] = $check;
}
} else {
$errors[] = 'Formulaire incomplet';
}
}
require_once('./templates/login.php');