tableau de bordV1

- premier jet tableau de bord
- prise en charge des images de profil lors de l'inscription
- obligation d'entrer une adresse mail valide
- debug css pour index.php et inscription.php
pull/1/head
remi.biette 6 years ago
parent 1848655848
commit ff01859e48

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -15,4 +15,5 @@ function connexionBD(){
$db = pg_connect("host=$host port=5432 dbname=$dbname user=$user password=$pass") or die("Erreur lors de la connexion à la base de données."); $db = pg_connect("host=$host port=5432 dbname=$dbname user=$user password=$pass") or die("Erreur lors de la connexion à la base de données.");
return $db; return $db;
} }
?>

@ -0,0 +1,21 @@
<?php
/**
* Created by PhpStorm.
* User: REMI
* Date: 19/04/2019
* Time: 10:10
*/
require 'connectionBD.php';
$db = connexionBD();
init();
function init(){
session_start();
if (isset($_SESSION['mail'])){
session_unset();
session_destroy();
}
header('Location: index.php');
exit();
}

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg class="icon" height="512" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M512 24.380952C242.590476 24.380952 24.380952 242.590476 24.380952 512s218.209524 487.619048 487.619048 487.619048 487.619048-218.209524 487.619048-487.619048S781.409524 24.380952 512 24.380952z m-7.314286 170.666667c90.209524 0 164.571429 70.704762 164.571429 158.476191s-73.142857 158.47619-164.571429 158.47619C414.47619 512 341.333333 441.295238 341.333333 353.52381s73.142857-158.47619 163.352381-158.476191zM792.380952 782.628571c0 45.104762-95.085714 46.32381-212.114285 46.32381H443.733333C326.704762 828.952381 231.619048 828.952381 231.619048 782.628571v-13.409523c0-113.371429 95.085714-204.8 212.114285-204.8h136.533334c117.028571 0 212.114286 91.428571 212.114285 204.8v13.409523z" fill="#666666" /></svg>

After

Width:  |  Height:  |  Size: 966 B

@ -1,7 +1,5 @@
<?php <?php
require("connectionBD.php"); require("connectionBD.php");
$db = connexionBD(); $db = connexionBD();
init(); init();
@ -20,7 +18,8 @@ function getError($code){
} }
} }
function authentification($db, $mail, $password){ function authentification($mail, $password){
global $db;
$result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail)); $result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail));
if ($result){ if ($result){
$row = pg_fetch_array($result); $row = pg_fetch_array($result);
@ -33,23 +32,31 @@ function init(){
global $db; global $db;
session_start(); session_start();
/*if(isset($_COOKIE['mail']) && isset($_COOKIE['password'])){
if (authentification($_COOKIE['mail'], $_COOKIE['mail'])){
$_SESSION['mail'] = $_COOKIE['mail'];
}
}*/
if(!isset($_SESSION['mail'])){ if(!isset($_SESSION['mail'])){
if (isset($_POST['mail_field'])){ if (isset($_POST['mail_field'])){
$mail = htmlentities(pg_escape_string ($_POST['mail_field'])); $mail = strtolower(htmlentities(pg_escape_string ($_POST['mail_field'])));
$password = htmlentities(pg_escape_string($_POST['password'])); $password = htmlentities(pg_escape_string($_POST['password']));
$result = authentification($db, $mail, $password); $result = authentification($mail, $password);
if($result) { if($result) {
$_SESSION['mail'] = $mail; $_SESSION['mail'] = $mail;
header('Location: tableauBord/tableauBord.php'); header('Location: tableauBord/tableauBord.php');
exit();
} }
else { else {
header('Location: index.php?error=1'); header('Location: index.php?error=1');
exit();
} }
} }
} }
else{ else{
header('Location: tableauBord/tableauBord.php'); header('Location: tableauBord/tableauBord.php');
exit();
} }
} }
@ -62,7 +69,7 @@ function init(){
<title>Bienvenue sur Upssi'Covoit</title> <title>Bienvenue sur Upssi'Covoit</title>
</head> </head>
<body> <body>
<div id="formulaireMail"> <div id="formulaire">
<h1>Bienvenue sur Upssi'Covoit</h1> <h1>Bienvenue sur Upssi'Covoit</h1>
<form method="post" action="index.php"> <form method="post" action="index.php">
<div class="line"> <div class="line">

@ -5,25 +5,20 @@
font-size: 1em; font-size: 1em;
} }
body{ html, body{
background-image: url("wallpaper.jpg"); height: 100%;
background-attachment: fixed;
padding-top: 5%;
padding-bottom: 5%;
} }
#formulaireMail{ body{
margin-top: 50vh; display: flex;
transform: translate(-50%, -50%); flex-wrap: wrap;
flex-direction: row;
justify-content: center;
align-items: center;
} }
#formulaire{ #formulaire{
transform: translate(-50%);
}
#formulaire, #formulaireMail{
background-color: white; background-color: white;
margin-left: 50vw;
border-radius: 10px; border-radius: 10px;
padding: 4em; padding: 4em;
width: 40%; width: 40%;
@ -43,12 +38,16 @@ form{
} }
.form{ .form{
width: 55%;
box-sizing: border-box; box-sizing: border-box;
width: 55%;
border: 1px solid grey; border: 1px solid grey;
margin-bottom: 0.7em; margin-bottom: 0.7em;
} }
#avatar{
border-style: none;
}
.button{ .button{
cursor: pointer; cursor: pointer;
font-weight: bold; font-weight: bold;
@ -79,6 +78,7 @@ form{
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
flex-direction: row; flex-direction: row;
justify-content: left;
width: 100%; width: 100%;
} }
@ -92,16 +92,10 @@ form{
} }
label{ label{
font-size: 1.1em;
word-break: break-all;
box-sizing: border-box; box-sizing: border-box;
display: block; font-size: 1.1em;
width: 43%; width: 45%;
} min-width: 8em;
input{
margin-left: 2%;
font-size: 1em;
} }
h1{ h1{

@ -14,17 +14,23 @@ function printError(){
function getError($code){ function getError($code){
switch ($code){ switch ($code){
case 1: case 1:
return "Cette adresse est déjà associée à un compte."; return "L'adresse mail est invalide.";
case 2: case 2:
return "Ce login est déjà associé à un compte."; return "Cette adresse est déjà associée à un compte.";
case 3: case 3:
return "Erreur lors de la création du compte."; return "Ce login est déjà associé à un compte.";
case 4: case 4:
return "Erreur lors de la vérification de l'unicité de l'adresse mail."; return "Le fichier envoyé doit être une image au format PNG.";
case 5:
return "La taille de l'image ne doit pas dépasser 2 MB.";
case 6:
return "Erreur lors de la création du compte.";
} }
} }
function isMailUnique($db, $mail){ function isMailUnique($mail){
global $db;
$result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail)); $result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail));
if($result){ if($result){
$row = pg_fetch_array($result); $row = pg_fetch_array($result);
@ -33,7 +39,8 @@ function isMailUnique($db, $mail){
return false; return false;
} }
function isLoginUnique($db, $login){ function isLoginUnique($login){
global $db;
$result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE login = $1;", array($login)); $result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE login = $1;", array($login));
if($result){ if($result){
$row = pg_fetch_array($result); $row = pg_fetch_array($result);
@ -42,40 +49,69 @@ function isLoginUnique($db, $login){
return false; return false;
} }
function creerUtilisateur($db, $mail, $password, $prenom, $nom, $login, $phone, $dateN){ function creerUtilisateur($mail, $password, $prenom, $nom, $login, $phone, $dateN){
global $db;
$result = pg_query_params($db, "INSERT INTO Utilisateur VALUES ($1, $2, $3, $4, $5, $6, to_date($7, 'YYYY/MM/DD'), false);", array($mail, $password, $prenom, $nom, $login, $phone, $dateN)); $result = pg_query_params($db, "INSERT INTO Utilisateur VALUES ($1, $2, $3, $4, $5, $6, to_date($7, 'YYYY/MM/DD'), false);", array($mail, $password, $prenom, $nom, $login, $phone, $dateN));
return $result; return $result;
} }
function uploadAvatar($mail){
if(isset($_FILES['avatar']) and $_FILES['avatar']['name'] != "") {
$target_file = "imageProfil/$mail.png";
$file_tmp = $_FILES['avatar']['tmp_name'];
$extension = end(explode('.', $_FILES['avatar']['name']));
$check = getimagesize($file_tmp);
if($check === false or !in_array($extension, array('png'))) {
header('Location: inscription.php?error=4');
exit();
}
else if ($_FILES['avatar']['size'] > 2 * 1024 * 1024){
header('Location: inscription.php?error=5');
exit();
}
else{
move_uploaded_file($file_tmp, $target_file);
}
}
}
function init(){ function init(){
global $db;
session_start(); session_start();
if(!isset($_SESSION['mail'])){ if(!isset($_SESSION['mail'])){
if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) && empty($_FILES) && $_SERVER['CONTENT_LENGTH'] > 0 ){
echo "<p class='error'>PHP a ignoré les données POST à cause d'une requête dépassant post_max_size (".ini_get('post_max_size').").</p>";
exit();
}
if(isset($_POST['mail_field'])){ if(isset($_POST['mail_field'])){
$login = htmlentities(pg_escape_string ($_POST['login_field'])); $login = htmlentities(pg_escape_string ($_POST['login_field']));
$password = htmlentities(pg_escape_string ($_POST['password'])); $password = htmlentities(pg_escape_string ($_POST['password']));
$prenom = htmlentities(pg_escape_string ($_POST['prenom'])); $prenom = htmlentities(pg_escape_string ($_POST['prenom']));
$nom = htmlentities(pg_escape_string ($_POST['nom'])); $nom = htmlentities(pg_escape_string ($_POST['nom']));
$dateN = htmlentities(pg_escape_string ($_POST['dateN'])); $dateN = htmlentities(pg_escape_string ($_POST['dateN']));
$mail = htmlentities(pg_escape_string ($_POST['mail_field'])); $mail = strtolower(htmlentities(pg_escape_string ($_POST['mail_field'])));
$phone = htmlentities(pg_escape_string ($_POST['phone'])); $phone = htmlentities(pg_escape_string ($_POST['phone']));
if(!isMailUnique($db, $mail)){ if(!filter_var($mail, FILTER_VALIDATE_EMAIL)){
header('Location: inscription.php?error=1'); header('Location: inscription.php?error=1');
exit();
} }
elseif(!isLoginUnique($db, $mail)){ elseif(!isMailUnique($mail)){
header('Location: inscription.php?error=2'); header('Location: inscription.php?error=2');
exit();
}
elseif(!isLoginUnique($login)){
header('Location: inscription.php?error=3');
exit();
} }
else{ else{
$result = creerUtilisateur($db, $mail, $password, $prenom, $nom, $login, $phone, $dateN); uploadAvatar($mail);
$result = creerUtilisateur($mail, $password, $prenom, $nom, $login, $phone, $dateN);
if($result){ if($result){
header('Location: index.php'); header('Location: index.php');
} }
else{ else{
header('Location: inscription.php?error=3'); header('Location: inscription.php?error=6');
} }
} }
@ -87,9 +123,6 @@ function init(){
} }
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr"> <html lang="fr">
<head> <head>
@ -99,9 +132,9 @@ function init(){
<script src="inscription.js"></script> <script src="inscription.js"></script>
</head> </head>
<body> <body>
<div id="formulaire"> <div id="formulaire">
<h1>Inscription</h1> <h1>Inscription</h1>
<form method="post" action="inscription.php"> <form method="post" enctype="multipart/form-data" action="inscription.php">
<div class="line"> <div class="line">
<label for="mail_field">Adresse mail : </label> <label for="mail_field">Adresse mail : </label>
<input id="mail_field" class="form" name="mail_field" type="email" maxlength="100" required> <input id="mail_field" class="form" name="mail_field" type="email" maxlength="100" required>
@ -134,12 +167,16 @@ function init(){
<label for="phone_field">Numéro de téléphone : </label> <label for="phone_field">Numéro de téléphone : </label>
<input id="phone_field" class="form" name="phone" type="tel" pattern="[0-9]{10}" maxlength="10" required> <input id="phone_field" class="form" name="phone" type="tel" pattern="[0-9]{10}" maxlength="10" required>
</div> </div>
<div class="line">
<label for="avatar">Image du Profil :</label>
<input type="file" id="avatar" class="form" name="avatar" accept="image/png">
</div>
<?php <?php
printError(); printError();
?> ?>
<input id="submit" class="button" type="submit" value="S'inscrire"> <input id="submit" class="button" type="submit" value="S'inscrire">
</form> </form>
<p id="enregistrer">Si vous avez déjà un compte <a href="index.php" title="S'identifier">cliquez ici</a>.</p> <p id="enregistrer">Si vous avez déjà un compte <a href="index.php" title="S'identifier">cliquez ici</a>.</p>
</div> </div>
</body> </body>
</html> </html>

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="485.211px" height="485.211px" viewBox="0 0 485.211 485.211" style="enable-background:new 0 0 485.211 485.211;"
xml:space="preserve">
<g>
<path d="M485.211,363.906c0,10.637-2.992,20.498-7.785,29.174L324.225,221.67l151.54-132.584
c5.895,9.355,9.446,20.344,9.446,32.219V363.906z M242.606,252.793l210.863-184.5c-8.653-4.737-18.397-7.642-28.908-7.642H60.651
c-10.524,0-20.271,2.905-28.889,7.642L242.606,252.793z M301.393,241.631l-48.809,42.734c-2.855,2.487-6.41,3.729-9.978,3.729
c-3.57,0-7.125-1.242-9.98-3.729l-48.82-42.736L28.667,415.23c9.299,5.834,20.197,9.329,31.983,9.329h363.911
c11.784,0,22.687-3.495,31.983-9.329L301.393,241.631z M9.448,89.085C3.554,98.44,0,109.429,0,121.305v242.602
c0,10.637,2.978,20.498,7.789,29.174l153.183-171.44L9.448,89.085z"/>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

@ -4,14 +4,25 @@
font-family: "Calibri Light"; font-family: "Calibri Light";
} }
h1{
font-size: 3em;
text-align: center;
text-decoration: underline;
}
#content{ #content{
margin-top: 8vh; min-width: 320px;
background-color: aqua; width: 100%;
margin-left: 50vw; display: flex;
border-radius: 10px; flex-wrap: nowrap;
padding: 4em; justify-content: center;
width: 84%; align-items: center;
transform: translate(-50%); }
#tableauBord{
margin: 2em;
padding: 1em;
width: 100%;
} }
.menu { .menu {
@ -23,6 +34,10 @@
} }
.menuItem { .menuItem {
display: flex;
flex-wrap: nowrap;
align-items: center;
justify-content: center;
color: white; color: white;
width: 10%; width: 10%;
min-width: 5em; min-width: 5em;
@ -39,11 +54,75 @@
border-bottom: 4px solid orange; border-bottom: 4px solid orange;
} }
#divImgProfil{
width: 100%;
display: flex;
flex-wrap: nowrap;
justify-content: center;
}
#imgProfil{ #imgProfil{
margin-top: 30px; background-color: white;
margin-top: 2.5em;
width: 60%;
height: 60%;
max-width: 210px;
max-height: 210px;
border-radius: 10px;
}
#trajet{
margin-top: 2em;
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: center;
text-align: center;
width: 100%;
}
.btnTrajet{
display: flex;
flex-wrap: nowrap;
justify-content: center;
align-items: center;
text-decoration: none;
padding: 0.4em;
color: black;
background-color: lightgray;
border: 1px solid black;
}
.btnTrajet:hover{
background-color: grey;
}
#btnTrajet2{
margin-left: 10%;
}
#recap{
margin-top: 2.5em;
width: 50%;
margin-left: 50%; margin-left: 50%;
transform: translate(-50%); transform: translate(-50%);
max-width: 300px; }
max-height: 300px;
border-radius: 10px; .recapLine{
margin-bottom: 1.5em;
display: flex;
flex-wrap: nowrap;
justify-content: left;
align-items: center;
width: 100%;
}
.recapIcon{
width: 50px;
height: 50px;
}
p{
margin-left: 10%;
} }

@ -1,10 +0,0 @@
window.onload = init;
function init(){
let button = document.getElementById('btnDeco');
button.onclick = deconnexion;
}
function deconnexion() {
document.getElementById('formDeco').submit();
}

@ -6,32 +6,85 @@
init(); init();
function init(){ function init(){
global $mail;
session_start(); session_start();
global $mail;
//Si on est pas connecté redirection vers la page de connexion //Si on est pas connecté redirection vers la page de connexion
if(!isset($_SESSION['mail'])){ if(!isset($_SESSION['mail'])){
header('Location: ../index.php'); header('Location: ../index.php');
exit();
} }
else{ else{
$mail = $_SESSION['mail']; $mail = $_SESSION['mail'];
//Si clic sur le bouton de déconnexion détruire la session et rediriger l'utilisateur
if(isset($_POST['deco'])){
session_unset();
session_destroy();
header('Location: ../index.php');
}
} }
} }
function getPrenom($db, $mail){ function getPrenom($mail){
global $db;
$result = pg_query_params($db, "SELECT prenom from Utilisateur WHERE mail = $1;", array($mail)); $result = pg_query_params($db, "SELECT prenom from Utilisateur WHERE mail = $1;", array($mail));
if($result){ if($result){
$row = pg_fetch_array($result); $row = pg_fetch_array($result);
$prenom = $row[0]; $prenom = $row[0];
return " $prenom"; return $prenom;
}
return null;
}
function getLogin($mail){
global $db;
$result = pg_query_params($db, "SELECT login from Utilisateur WHERE mail = $1;", array($mail));
if($result){
$row = pg_fetch_array($result);
$login = $row[0];
return $login;
}
return null;
}
function getTrajetsProposes($mail){
global $db;
$result = pg_query_params($db, "SELECT COUNT(*) from Trajet WHERE mailProposition = $1 AND estAnnule = false AND datedepart >= current_date;", array($mail));
if($result){
$row = pg_fetch_array($result);
return $row[0];
}
return 0;
}
function getTrajetsReserves($mail){
global $db;
$result = pg_query_params($db, "SELECT COUNT(*) FROM trajet tr, reserver r WHERE r.codetrajet = tr.codetrajet AND mailutilisateur = $1 AND etatres != 'Annulée' AND estAnnule = false AND datedepart >= current_date;", array($mail));
if($result){
$row = pg_fetch_array($result);
return $row[0];
} }
return ""; return 0;
}
function getMessagesNonLus($mail){
global $db;
$result = pg_query_params($db, "SELECT COUNT(*) from Message WHERE mailRecepteur = $1 AND estLu = FALSE;", array($mail));
if($result){
$row = pg_fetch_array($result);
$login = $row[0];
return $login;
}
}
function getAvisNonLus($mail){
global $db;
$result = pg_query_params($db, "SELECT COUNT(tr.mailProposition) FROM Trajet tr, Avis av WHERE tr.codeTrajet = av.codeTrajet AND av.estLu = false AND tr.mailProposition = $1;", array($mail));
if($result){
$row = pg_fetch_array($result);
$login = $row[0];
return $login;
}
}
function getPathImgProfil($mail){
if (file_exists("../imageProfil/$mail.png")){
return "../imageProfil/$mail.png";
}
return "../imageProfil/default.svg";
} }
?> ?>
@ -41,8 +94,8 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<link rel="stylesheet" href="tableauBord.css"> <link rel="stylesheet" href="tableauBord.css">
<link rel="icon" type="image/png" href="" />
<title>Tableau de bord</title> <title>Tableau de bord</title>
<script src="tableauBord.js"></script>
</head> </head>
<body> <body>
<nav class="menu"> <nav class="menu">
@ -53,18 +106,36 @@
<a class="menuItem" href="../inscription.php">Avis reçus</a> <a class="menuItem" href="../inscription.php">Avis reçus</a>
<a class="menuItem" href="../inscription.php">Avis laissés</a> <a class="menuItem" href="../inscription.php">Avis laissés</a>
<a class="menuItem" href="../inscription.php">Profil</a> <a class="menuItem" href="../inscription.php">Profil</a>
<a id="btnDeco" class="menuItem">Se déconnecter</a> <a class="menuItem" href="../deconnexion.php">Se déconnecter</a>
<form id="formDeco" method="post" action="tableauBord.php">
<input type="hidden" value="true" name="deco">
</form>
</nav> </nav>
<div id="content"> <div id="content">
<h1>Bonjour<?php <div id="tableauBord">
echo getPrenom($db,$mail); <h1>Bienvenue <?php echo getLogin($mail); ?></h1>
?> <div id="divImgProfil">
</h1> <img id="imgProfil" src="<?php echo getPathImgProfil($mail); ?>">
<div id="cotent"> </div>
<img id="imgProfil" src="../wallpaper.jpg"> <div id="trajet">
<a class="btnTrajet" href="../ah.php">Déposer un trajet</a>
<a id="btnTrajet2" class="btnTrajet" href="../ah.php">Rechercher un trajet</a>
</div>
<div id="recap">
<div class="recapLine">
<img class="recapIcon" src="../car.png">
<p>Vous avez <?php echo getTrajetsProposes($mail); ?> trajets proposés à effectuer.</p>
</div>
<div class="recapLine">
<img class="recapIcon" src="../car.png">
<p>Vous avez <?php echo getTrajetsReserves($mail); ?> trajets réservés à effectuer.</p>
</div>
<div class="recapLine">
<img class="recapIcon" src="../mail.svg">
<p>Vous avez <?php echo getMessagesNonLus($mail); ?> messages non lus.</p>
</div>
<div class="recapLine">
<img class="recapIcon" src="../star.png">
<p>Vous avez <?php echo getAvisNonLus($mail); ?> avis non lus.</p>
</div>
</div>
</div> </div>
</div> </div>
</body> </body>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 131 KiB

Loading…
Cancel
Save