-
Notifications
You must be signed in to change notification settings - Fork 0
/
connexion.php
72 lines (58 loc) · 2.4 KB
/
connexion.php
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
$submitBtn = "Connexion";
$pageTitle = "$submitBtn";
require_once __DIR__ . '/util/index.php';
require_once __DIR__ . '/class_crud/membre.class.php';
require_once __DIR__ . '/middleware/getMember.php';
if($loggedMember) {
header('location: '.webSitePath('/profil.php'));
}
$monMembre = new membre();
$validator = Validator::make();
$loginState = "";
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$validator->addRules([
ValidationRule::required('pseudoMemb')->customError('isRequired', 'Le pseudo est requis'),
ValidationRule::required('passMemb')->customError('isRequired', 'Le mot de passe est requis')->password()
])->bindValues($_POST);
if($validator->success()) {
$pseudoMemb = $validator->verifiedField('pseudoMemb');
// on conserve les caractères spéciaux (d'ou le false)
$passMemb = $validator->verifiedField('passMemb', false);
$loginAttempt = $monMembre->login($pseudoMemb, $passMemb);
if($loginAttempt["error"]) {
$loginState = '<div class="errors"><div class="error">'.$loginAttempt['message'].'</div></div>';
}
}
}
require_once __DIR__ . '/layouts/front/head.php';
?>
<script src="<?= webAssetPath('js/password.js') ?>"></script>
<div class="container container-auth">
<h1>Se connecter</h1>
<?=$validator->echoErrors() ?>
<?=$loginState?>
<form
class="user-form"
method="POST"
action="<?= htmlspecialchars($_SERVER['PHP_SELF']); ?>"
enctype="multipart/form-data"
accept-charset="UTF-8"
>
<div class="field">
<label>Pseudo</label>
<input value="<?=$validator->oldField('pseudoMemb')?>" type="text" name="pseudoMemb">
</div>
<div class="field">
<label> Mot de passe </label>
<input value="<?=$validator->oldField('passMemb')?>" type="password" name="passMemb" id="passMemb">
<label><input type="checkbox" onclick="togglePassword('passMemb')"><i>Afficher le mot de passe</i></label>
</div>
<input class="btn btn-lg" title="<?=$submitBtn?>" type="submit" value="<?=$submitBtn?>" />
<p>Pas de compte? <a href="<?= webSitePath('/inscription.php') ?>">Inscrivez-vous</a></p>
</form>
</div>
<?php if(!IN_PROD):?>
<script src="<?= webAssetPath('js/autofill-form.js') ?>"></script>
<?php endif?>
<?php require_once __DIR__ . '/layouts/front/foot.php';?>