Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

Commit

Permalink
ajout login/logout
Browse files Browse the repository at this point in the history
  • Loading branch information
lduboeuf committed Jun 22, 2017
1 parent 55248df commit 5ac9e09
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 10 deletions.
17 changes: 11 additions & 6 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
Expand All @@ -24,7 +19,7 @@
display:inline-block;
text-align: center;
margin:0;
width: 80%;
width: 70%;
}


Expand Down Expand Up @@ -79,10 +74,20 @@

</style>
</head>
<?php
session_start();
?>
<body>
<header>
<a href="index.php"><img src="images/afpa_logotb.png" alt="logo"/></a>
<h1>afpa-bay</h1>
<?php
if (!isset($_SESSION['user_id'])){
echo '<a href="index.php?page=login">login</a>';
}else{
echo 'bonjour '. $_SESSION['current_user']. ' <a href="index.php?page=logout">logout</a>';
}
?>
</header>
<main>
<?php
Expand Down
37 changes: 37 additions & 0 deletions login-handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

$login = filter_input(INPUT_POST, 'login', FILTER_SANITIZE_STRING);
$mdp = filter_input(INPUT_POST, 'mdp', FILTER_SANITIZE_STRING);



if ($login && $mdp){

$bdd = new PDO('mysql:host=localhost;dbname=afpa-bay;charset=utf8', 'root', 'admin');
$stmt = $bdd->prepare('SELECT * FROM utilisateur WHERE login = :login');
$stmt->bindValue(':login', $login);
$stmt->execute();
$utilisateur = $stmt->fetch();
if (!$utilisateur){
echo '<p class="alert">humm, pas trouvé d\'utilisateur </p>'.$login;
require('login.php');
}else{
if (!password_verify($mdp, $utilisateur['mdp'])){
echo '<p class="alert">humm, le mot de passe est pas bon</p>';
require('login.php');
}else{
//ça semble ok, on mlet des choses dans la variable de session
$_SESSION['user_id'] = $utilisateur['id'];
$_SESSION['current_user'] = $utilisateur['login'];
//on redirige
header("Location: index.php",true,303);
}
}



}else{
echo '<p class="alert">humm bah si tu saisi pas ton login +mdp comment je peux savoir si tu es membre ?</p>';
require('login.php');
}

15 changes: 15 additions & 0 deletions login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

<form id="film-form" action="index.php?page=login-handler" method="post">

<label for="titre">login :</label>
<input type="text" name="login" placeholder="login" required/>
<label for="titre">mot de passe :</label>
<input type="text" name="mdp" placeholder="mot de passe" required/>
<input type="submit" name="ok" value="ok"/>

</form>

<?php



5 changes: 5 additions & 0 deletions logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

session_destroy();

header('Location: index.php');
42 changes: 38 additions & 4 deletions resources/film.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Generation Time: Jun 22, 2017 at 08:54 AM
-- Generation Time: Jun 22, 2017 at 11:32 AM
-- Server version: 5.7.18-0ubuntu0.17.04.1
-- PHP Version: 7.0.18-0ubuntu0.17.04.1

Expand Down Expand Up @@ -46,7 +46,30 @@ INSERT INTO `film` (`id`, `titre`, `auteur`, `acteurs`, `date_sortie`, `thumbnai
(4, 'sdcsd', 'sdc', 'sdc', 2015, NULL),
(5, 'rturtu', 'rtutru', 'rtutr', 2005, NULL),
(6, 'kikou des bois', 'zonote', 'talui', 2005, NULL),
(7, 'sdcsdsdcsd', 'sdcsdcsdc', 'sdcsdcsdcdc', 2004, NULL);
(7, 'sdcsdsdcsd', 'sdcsdcsdc', 'sdcsdcsdcdc', 2004, NULL),
(8, 'taliu', 'zonote', 'pikatchou', 2005, NULL),
(9, 'hgfj', 'gfj', 'fgjf', 2014, NULL),
(10, 'ddg', 'dfgdfg', 'dfgdfg', 1986, NULL);

-- --------------------------------------------------------

--
-- Table structure for table `utilisateur`
--

CREATE TABLE `utilisateur` (
`id` int(11) NOT NULL,
`login` varchar(20) NOT NULL,
`mdp` varchar(256) NOT NULL,
`email` varchar(256) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `utilisateur`
--

INSERT INTO `utilisateur` (`id`, `login`, `mdp`, `email`) VALUES
(1, 'lionel', '$2y$10$jd3m6moA6rQ.p8OUuwO.UO3XAxml/Z6GW/.WxK1qzTnnK6py38sbS', '[email protected]');

--
-- Indexes for dumped tables
Expand All @@ -58,6 +81,12 @@ INSERT INTO `film` (`id`, `titre`, `auteur`, `acteurs`, `date_sortie`, `thumbnai
ALTER TABLE `film`
ADD PRIMARY KEY (`id`);

--
-- Indexes for table `utilisateur`
--
ALTER TABLE `utilisateur`
ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--
Expand All @@ -66,7 +95,12 @@ ALTER TABLE `film`
-- AUTO_INCREMENT for table `film`
--
ALTER TABLE `film`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
--
-- AUTO_INCREMENT for table `utilisateur`
--
ALTER TABLE `utilisateur`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

0 comments on commit 5ac9e09

Please sign in to comment.