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
| <?php
if(!empty($_POST) && !empty($_POST['username']) && !empty($_POST['password'])){
require_once 'inc/db.php';
$req = $pdo->prepare('SELECT * FROM users WHERE (username = :username OR email = :username) AND confirmed_at IS NOT NULL');
$req->execute(['username' => $_POST['username']]);
$user = $req->fetch();
if(password_verify($_POST['password'], $user->password)){
session_start();
$_SESSION['auth'] = $user;
$_SESSION['flash']['success'] = 'Vous êtes maintenant connecté';
header('location: account.php');
exit();
}elseif{
$_SESSION['flash']['danger'] = 'Identifiant ou mot de passe incorrecte';
}
}
?>
<?php require 'inc/header.php'; ?>
<h1>Se connecter</h1>
<form action="" method="POST">
<div class="form-group">
<label for="">Pseudo ou Email</label>
<input type="text" name="username" class="form-control"/>
</div>
<div class="form-group">
<label for="">Mot de passe</label>
<input type="password" name="password" class="form-control"/>
</div>
<button type="submit" class="btn btn-primary" >Se connecter</button>
</form>
<?php require 'inc/footer.php'; ?> |
Partager