-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
72 lines (63 loc) · 1.97 KB
/
index.php
File metadata and controls
72 lines (63 loc) · 1.97 KB
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
<?php
// Affichage 'non connecté'
if(!isset($_SESSION)) {
session_start();
$nom = " ";
}
// Affichage 'bonjour"
if(isset($_SESSION['ID'])){
$nom = "<p>Bonjour ".$_SESSION['nom']."</p>";
}
// Appel du modèle
require('modele.php');
// Voir les différentes news
$news = getNews();
// Bouton deconnexion
if(isset($_SESSION['ID'])) {
$deconnexion = "<li><a href='disconnect.php'>Déconnexion</a></li>";
} else {
$deconnexion = "";
}
$categories = getCategories();
// Poster une news
if (isset($_POST["validerPostSujet"])) {
// Dans un premier temps on teste la connexion
echo'on poste une news';
posterNews($_SESSION['ID'],date('Y-m-d'),$_POST['contenuSujet'],$_POST['categorie']);
}
// Connexion de l'utilisateur
if (!empty($_POST['email_connexion']) && !empty($_POST['mot_de_passe_connexion'])) {
if (testConnexion($_POST['email_connexion'], $_POST['mot_de_passe_connexion']) != false) {
// Test réussi, utilisateur connecté
session_destroy();
session_start();
// On définit les variables de session
$dataID = getID($_POST['email_connexion']);
$_SESSION['ID'] = $dataID['ID'];
$dataNom = getNom($_POST['email_connexion']);
$_SESSION['nom'] = $dataNom['nom'];
header('Refresh:0');
$messageConnexion= "Vous êtes connecté !";
} else {
$messageConnexion = "Email ou mot de passe incorrect";
}
}
// Vérification inscription
if (!empty($_POST['nom']) && !empty($_POST['email']) && !empty($_POST['mot_de_passe'])) {
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
if(strlen($_POST['mot_de_passe']) >= 5) {
if(verifEmail($_POST['email'])) {
creerCompte($_POST['nom'],$_POST['email'],$_POST['mot_de_passe']);
$message = "Compte créé avec succès !";
} else {
$message = "Cette adresse mail est déjà utilisée";
}
} else {
$message = "Mot de passe trop court (min 5 caractères)";
}
} else {
$message = "Email non valide";
}
}
// Appel de la vue
require('vue.php');