-
Notifications
You must be signed in to change notification settings - Fork 0
/
connexion.php
50 lines (45 loc) · 1.41 KB
/
connexion.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
40
41
42
43
44
45
46
47
48
49
50
<?php
use App\App;
use App\Vendor\User;
use Core\Config;
require 'core/init.php';
if(connect()) {
User::redirect('/');
}
//On défini le titre
App::setTitle('Connexion');
$id_page = "login";
$user = User::getInstance($DB_con);
if(isset($_POST['SubmitButton'])) {
$errors = null;
$encoding = 'utf-8';
$username = htmlspecialchars(trim($_POST['InputUsername']), ENT_QUOTES, $encoding);
$password = htmlspecialchars(trim($_POST['InputPassword']), ENT_QUOTES, $encoding);
if(isset($_POST['InputStayOnline'])) {
$stayonline = htmlspecialchars($_POST['InputStayOnline']);
} else {
$stayonline = null;
}
/* On vérifie que tous les champs sont saisies */
if(empty($username) || empty($password)) {
$errors['FieldsEmpty'] = "Veuillez saisir tous les champs de texte";
}
/* On vérifie qu'il n'y a pas d'erreurs */
if($errors) {
$allerror = "<ul>";
foreach ($errors as $key) {
$allerror .= "<li>" . $key . "</li>";
}
$allerror .= "</ul>";
setFlash($allerror, "danger");
} else {
if($user->login($username, $password, $stayonline)) {
User::redirect('/');
} else {
$errors['LoginFail'] = "Identifiant ou mot de passe incorrect :/";
setFlash($errors['LoginFail'], "danger");
}
}
}
//On importe la vue
require Config::get('view.paths') . 'connexion.view.php';