-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnexion.php
106 lines (91 loc) · 3.44 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
include 'include/db.php';
session_start();
if(!empty($_SESSION["id"])){
header("Location: index.php");
}
//initialisation tableau associatif des éventuelles erreurs
$errors = [];
//pour éviter les manip sur l'URL
if (!empty($_GET)){
header("HTTP/1.1 404 NotFound");
include '404.php';
die();
}
//var_dump($_POST); //affiche les données saisies dans le formulaire sous forme d'un tableau
//die(); pour arrêter l'excecution de la suite
//vérifier que le formulaire est soumis
if (!empty($_POST)) {
//////////////////// 1. récupérer les données du formulaire ////////////////////
//strip_tags retire les balises html et empêche les attaques JS
$identifiant = strip_tags($_POST['identifiant']);
$password = $_POST['password'];
//////////////////// 2. valider les données ////////////////////
if (empty($identifiant)) {
$errors['identifiant'] = 'Veuillez saisir votre identifiant !';
} else {
$result= checkIdentifiant($identifiant);
if($result['email']==false and $result['pseudo']==false){
$errors['identifiant'] = 'Identifiant inconnu';
} else{
if($result['email']!=false) {
$boolean = password_verify($password, $result['email']['password']);
} else{
$boolean = password_verify($password, $result['pseudo']['password']);
}
if($boolean==false){
$errors['mdp'] = 'Mot de passe incorrect';
} else{
if($result['email']!=false){
$_SESSION["id"]=$result['email']['id'];
$_SESSION["username"]=$result['email']['username'];
} else{
$_SESSION["id"]=$result['pseudo']['id'];
$_SESSION["username"]=$result['pseudo']['username'];
}
header("Location: index.php");
}
}
}
}
?>
<!doctype html>
<html lang=fr>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/inscription.css">
<link rel="stylesheet" href="css/media.css">
<link rel="icon" type="image/png" href="media/img/faviconv2.gif"/>
<script src="https://kit.fontawesome.com/f9102af03b.js" crossorigin="anonymous"></script>
<title>Gazouillis - Inscription</title>
</head>
<body>
<header>
<i class="fas fa-dove"></i>
</header>
<main>
<section id="content">
<h1>Connexion</h1>
<form method="post" action="" novalidate> <!-- novalidate désactive tous les contrôles html style required-->
<label for="identifiant">Identifiant</label>
<input type="text" name="identifiant" id="identifiant"
value="<?= $pseudo ?? '' ?>"
placeholder="Email ou pseudo">
<?php if(!empty($errors['identifiant'])): ?>
<p><?=$errors['identifiant']?></p>
<?php endif; ?>
<label for="password">Mot de passe</label>
<input type="password" name="password" id="password">
<?php if(!empty($errors['mdp'])): ?>
<p><?=$errors['mdp']?></p>
<?php endif; ?>
<button><strong>Connexion</strong></button>
</form>
</section>
</main>
</body>
</html>