-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
98 lines (96 loc) · 5 KB
/
index.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
require_once 'include/DBContract.php';
require_once 'include/AccountManager.php';
require_once 'include/DBManager.php';
require_once 'include/InputValidator.php';
require_once 'include/utils.php';
//TODO:: fix the login scenario
$am=AccountManager::getInstance();
$db_manager=DBManager::getInstance();
if($am->isLoggedIn()){
header('location:dashboard.php');
}
if($_SERVER['REQUEST_METHOD']=='POST' AND isset($_POST[DBContract::$Users_Col_Email]) AND isset($_POST[DBContract::$Users_Password])){
//let's process submitted info
$email = $_POST[DBContract::$Users_Col_Email];
$pass = $_POST[DBContract::$Users_Password];
$user = null;
if (InputValidator::validateEmail($email) and InputValidator::validatePassword($pass) ) {
if($user = $db_manager->getUserByEmail($email) AND password_verify($pass,$user->getPasswordHash())){
if(isset($_POST[DBContract::$Users_RememberMe]))
saveLoginDataInACookie();
else
deleteLoginDataInCookie();
$am->login($user->getId());
header('location:dashboard.php');
$redirect=1;
}else{
$user_error=1;
}
}
}
loadLoggingDataFromACookie();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/login.css">
</head>
<body>
<main class="container-lg w-100 h-100 d-flex justify-content-center align-items-center">
<div class="row w-100">
<div class="card offset-md-3 col-md-6 shadow">
<div class="card-body p-5">
<h1 class="card-title border-start border-primary mb-4 text-left font-weight-bold ps-3">E-classe</h1>
<div class="card-text">
<h2 class="text-center">SIGN IN</h2>
<p class="text-center text-gray">
Enter your credentials to access your account
</p>
<?php if(isset($user_error)){ ?>
<div class="alert alert-danger">
Invalid credentials check your spelling and try again !
</div>
<?php }?>
<form action="index.php" method="POST">
<?php if(InputValidator::error(InputValidator::EMAIL_ERROR_KEY)):?>
<div class="alert alert-danger">
<?=InputValidator::error(InputValidator::EMAIL_ERROR_KEY) ?>
</div>
<?php endif;?>
<div class="form-group">
<label for="<?= DBContract::$Users_Col_Email ?>">Email</label>
<input type="email" class="form-control <?= InputValidator::error(InputValidator::EMAIL_ERROR_KEY)?'border-danger border':'' ?> " value="<?= $_POST[DBContract::$Users_Col_Email]??$GLOBALS[DBContract::$Users_RememberMe_Email]??'' ?>" id="<?= DBContract::$Users_Col_Email ?>" name="<?= DBContract::$Users_Col_Email ?>" placeholder="Enter your email">
</div>
<?php if(InputValidator::error(InputValidator::PASSWORD_ERROR_KEY)):?>
<div class="alert alert-danger">
<?=InputValidator::error(InputValidator::PASSWORD_ERROR_KEY) ?>
</div>
<?php endif;?>
<div class="form-group">
<label for="<?= DBContract::$Users_Password ?>">Password</label>
<input type="password" class="<?= InputValidator::error(InputValidator::PASSWORD_ERROR_KEY)?'border-danger border':'' ?> form-control" value="<?= $_POST[DBContract::$Users_Password]??$GLOBALS[DBContract::$Users_RememberMe_Pass]??'' ?>" name="<?= DBContract::$Users_Password ?>" id="<?= DBContract::$Users_Password ?>" placeholder="Enter your password">
</div>
<div class="form-check">
<label for="<?= DBContract::$Users_RememberMe ?>" class="form-check-label">Remember me</label>
<input type="checkbox" class="form-check-input" <?= (isset($_POST[DBContract::$Users_RememberMe]) OR $GLOBALS[DBContract::$Users_RememberMe]) ?'checked':'' ?> name="<?= DBContract::$Users_RememberMe ?>" id="<?= DBContract::$Users_RememberMe ?>">
</div>
<input type="submit" class="form-control btn bg-primary text-light py-2" value="SIGN IN">
</form>
<p class="text-gray mt-3 mb-0 text-center">
Forgot your password? <a href="#" class="text-color-primary text-decoration-none"> Reset Password</a>
</p>
</div>
</div>
</div>
</div>
</main>
<?php if(isset($redirect)) redirect_with_js('dashboard.php');?>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<?php include 'footer.php'?></body>
</html>