index inscription tableauBord premier jet

pull/1/head
remi.biette 6 years ago
parent 77ee0fb2fe
commit 4c6537f4d3

@ -0,0 +1,23 @@
<?php
/**
* Created by PhpStorm.
* User: REMI
* Date: 16/04/2019
* Time: 14:46
*/
function connexionBD(){
$host = "localhost";
$dbname = "projetWeb";
$user = "postgres";
$pass = "0000";
$db = pg_connect("host=$host port=5432 dbname=$dbname user=$user password=$pass");
if($db == false){
echo "Erreur lors de la connexion à la base de données.";
}
return $db;
}

@ -0,0 +1,74 @@
<?php
require("connectionBD.php");
$db = connexionBD();
init();
function authentification($db, $mail, $password){
$result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail));
if ($result){
$row = pg_fetch_array($result);
return (!strcmp($row["passwd"], $password));
}
return false;
}
function init(){
session_start();
if(!isset($_SESSION['mail'])){
if (isset($_POST['mail_field'])){
$mail = htmlentities(pg_escape_string ($_POST['mail_field']));
$password = htmlentities(pg_escape_string($_POST['password']));
$result = authentification($db, $mail, $password);
if($result) {
$_SESSION['mail'] = $mail;
header('Location: tableauBord/tableauBord.php');
}
else {
header('Location: index.php?error=Adresse mail ou mot de passe invalide.');
}
}
}
else{
header('Location: tableauBord/tableauBord.php');
}
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="index_inscription.css">
<title>Bienvenue sur Upssi'Covoit</title>
</head>
<body>
<div id="formulaireMail">
<h1>Bienvenue sur Upssi'Covoit</h1>
<form method="post" action="index.php">
<div class="line">
<label for="mail_field">Adresse mail : </label>
<input id="mail_field" class="form" name="mail_field" type="email" maxlength="150" required>
</div>
<div class="line">
<label for="password_field">Mot de passe : </label>
<input id="password_field" class="form" id="password" name="password" type="password" maxlength="16" required>
</div>
<?php
if(isset($_GET['error'])){
$erreur = $_GET['error'];
echo "<p class = 'error'>$erreur</p>";
}
?>
<input id="submit" class="button" type="submit" value="Se connecter">
</form>
<p id="enregistrer">Si vous n'avez pas de compte <a href="inscription.php" title="Créer un compte">cliquez ici</a>.</p>
</div>
</body>
</html>

@ -0,0 +1,115 @@
*{
margin: 0;
padding: 0;
font-family: "Arial";
font-size: 1em;
}
body{
background-image: url("wallpaper.jpg");
background-attachment: fixed;
padding-top: 5%;
padding-bottom: 5%;
}
#formulaireMail{
margin-top: 50vh;
transform: translate(-50%, -50%);
}
#formulaire{
transform: translate(-50%);
}
#formulaire, #formulaireMail{
background-color: white;
margin-left: 50vw;
border-radius: 10px;
padding: 4em;
width: 40%;
}
#enregistrer{
margin-top: 1em;
text-align: center;
}
h1{
text-align: center;
}
form{
margin-top: 3em;
}
.form{
width: 55%;
box-sizing: border-box;
border: 1px solid grey;
margin-bottom: 0.7em;
}
.button{
cursor: pointer;
font-weight: bold;
padding: 8px;
color: white;
background-color: rgb(65, 154, 28);
border-radius: 5em;
border: none;
}
.button:hover{
background-color: rgb(48, 112, 20);
border-color: rgb(48, 112, 20);
}
.button:disabled{
cursor: not-allowed;
background-color: grey;
}
#submit{
margin-top: 1em;
margin-left: 50%;
transform: translate(-50%);
}
.line{
display: flex;
flex-wrap: wrap;
flex-direction: row;
width: 100%;
}
#error{
margin-bottom: 1em;
}
.error{
color: red;
text-align: center;
}
label{
font-size: 1.1em;
word-break: break-all;
box-sizing: border-box;
display: block;
width: 43%;
}
input{
margin-left: 2%;
font-size: 1em;
}
h1{
font-size: 2em;
}
button{
color: forestgreen;
border-color: forestgreen;
border-radius: 5em;
}

@ -0,0 +1,25 @@
let messageAffiche = false;
window.onload = init;
function init(){
let password = document.getElementById("password");
let confirmation = document.getElementById("confirmation");
password.oninput = verifPassword;
confirmation.oninput = verifPassword;
}
function verifPassword() {
let message = "Les mots de passe ne correspondent pas.";
if( !messageAffiche && password.value != "" && confirmation.value!="" && password.value != confirmation.value ){
confirmation.insertAdjacentHTML("afterend", "<p id='error' class='error'>" + message + "</p>");
document.getElementById("submit").disabled = true;
messageAffiche = true;
}
else if ( messageAffiche && password.value == confirmation.value ) {
let child = document.getElementById("error");
child.parentNode.removeChild(child);
document.getElementById("submit").disabled = false;
messageAffiche = false;
}
}

@ -0,0 +1,144 @@
<?php
require ('connectionBD.php');
$db = connexionBD();
init();
function printError(){
if(isset($_GET['error'])){
$erreur = getError($_GET['error']);
echo "<p class = 'error'>$erreur</p>";
}
}
function getError($code){
switch ($code){
case 1:
return "Cette adresse est déjà associée à un compte.";
case 2:
return "Ce login est déjà associé à un compte.";
case 3:
return "Erreur lors de la création du compte.";
case 4:
return "Erreur lors de la vérification de l'unicité de l'adresse mail.";
}
}
function isMailUnique($db, $mail){
$result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail));
if($result){
$row = pg_fetch_array($result);
return strcmp($row['mail'], $mail);
}
return false;
}
function isLoginUnique($db, $login){
$result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE login = $1;", array($login));
if($result){
$row = pg_fetch_array($result);
return strcmp($row['login'], $login);
}
return false;
}
function creerUtilisateur($db, $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;
}
function init(){
session_start();
if(!isset($_SESSION['mail'])){
if(isset($_POST['mail_field'])){
$login = htmlentities(pg_escape_string ($_POST['login_field']));
$password = htmlentities(pg_escape_string ($_POST['password']));
$prenom = htmlentities(pg_escape_string ($_POST['prenom']));
$nom = htmlentities(pg_escape_string ($_POST['nom']));
$dateN = htmlentities(pg_escape_string ($_POST['dateN']));
$mail = htmlentities(pg_escape_string ($_POST['mail_field']));
$phone = htmlentities(pg_escape_string ($_POST['phone']));
if(!isMailUnique($db, $mail)){
header('Location: inscription.php?error=1');
}
elseif(!isLoginUnique($db, $mail)){
header('Location: inscription.php?error=2');
}
else{
$result = creerUtilisateur($db, $mail, $password, $prenom, $nom, $login, $phone, $dateN);
if($result){
header('Location: index.php');
}
else{
header('Location: inscription.php?error=3');
}
}
}
}
else{
header('Location: tableauBord/tableauBord.php');
}
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="index_inscription.css">
<title>Inscription</title>
<script src="inscription.js"></script>
</head>
<body>
<div id="formulaire">
<h1>Inscription</h1>
<form method="post" action="inscription.php">
<div class="line">
<label for="mail_field">Adresse mail : </label>
<input id="mail_field" class="form" name="mail_field" type="email" maxlength="100" required>
</div>
<div class="line">
<label for="login_field">Login : </label>
<input id="login_field" class="form" name="login_field" type="text" maxlength="50" required>
</div>
<div class="line">
<label for="password">Mot de passe : </label>
<input class="form" id="password" name="password" type="password" maxlength="50" required>
</div>
<div class="line">
<label for="confirmation">Confirmation : </label>
<input class="form" id="confirmation" name="confirmation" type="password" maxlength="16">
</div>
<div class="line">
<label for="prenom_field">Prénom : </label>
<input id="prenom_field" class="form" name="prenom" type="text" maxlength="50" required>
</div>
<div class="line">
<label for="nom_field">Nom : </label>
<input id="nom_field" class="form" name="nom" type="text" maxlength="50" required>
</div>
<div class="line">
<label for="dateN_field">Date de naissance : </label>
<input id="dateN_field" class="form" name="dateN" type="date" required>
</div>
<div class="line">
<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>
</div>
<?php
printError();
?>
<input id="submit" class="button" type="submit" value="S'inscrire">
</form>
<p id="enregistrer">Si vous avez déjà un compte <a href="index.php" title="S'identifier">cliquez ici</a>.</p>
</div>
</body>
</html>

@ -0,0 +1,49 @@
*{
margin: 0;
padding: 0;
font-family: "Calibri Light";
}
#content{
margin-top: 8vh;
background-color: aqua;
margin-left: 50vw;
border-radius: 10px;
padding: 4em;
width: 84%;
transform: translate(-50%);
}
.menu {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
background-color: rgb(65, 154, 28);
}
.menuItem {
color: white;
width: 10%;
min-width: 5em;
font-weight: bold;
text-decoration: none;
padding: 0.8em;
border-bottom: 4px solid rgb(65, 154, 28);
font-size: 1.1em;
text-align: center;
}
.menuItem:hover{
cursor: pointer;
border-bottom: 4px solid orange;
}
#imgProfil{
margin-top: 30px;
margin-left: 50%;
transform: translate(-50%);
max-width: 300px;
max-height: 300px;
border-radius: 10px;
}

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

@ -0,0 +1,70 @@
<?php
require ('../connectionBD.php');
$mail = null;
$db = connexionBD();
init($mail);
function init(&$mail){
session_start();
//Si on est pas connecté redirection vers la page de connexion
if(!isset($_SESSION['mail'])){
header('Location: ../index.php');
}
else{
$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){
$result = pg_query_params($db, "SELECT prenom from Utilisateur WHERE mail = $1;", array($mail));
if($result){
$row = pg_fetch_array($result);
$prenom = $row[0];
return " $prenom";
}
return "";
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="tableauBord.css">
<title>Tableau de bord</title>
<script src="tableauBord.js"></script>
</head>
<body>
<nav class="menu">
<a class="menuItem" href="./../inscription.php">Tableau de bord</a>
<a class="menuItem" href="../inscription.php">Trajets publiés</a>
<a class="menuItem" href="../inscription.php">Trajets réservés</a>
<a class="menuItem" href="../inscription.php">Messagerie</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">Profil</a>
<a id="btnDeco" class="menuItem">Se déconnecter</a>
<form id="formDeco" method="post" action="tableauBord.php">
<input type="hidden" value="true" name="deco">
</form>
</nav>
<div id="content">
<h1>Bonjour<?php
echo getPrenom($db,$mail);
?>
</h1>
<div id="cotent">
<img id="imgProfil" src="../wallpaper.jpg">
</div>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Loading…
Cancel
Save