/
alumni_login.php
executable file
·149 lines (114 loc) · 4.37 KB
/
alumni_login.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* Author: Ahmed-Dinar
* Date: 5/31/17
*/
include 'includes/core.php';
if( isset($_SESSION['user']) ){
header('Location: alumni.php' );
exit(0);
}
include('database/connect.php');
require_once 'libs/Hash.php';
if (!isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = base64_encode(openssl_random_pseudo_bytes(32));
}
require 'libs/FlashMessages.php';
$flashMsg = new \Plasticbrain\FlashMessages\FlashMessages();
/**
* For setting password
*/
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!isset($_POST['csrf_token'])
|| $_POST['csrf_token'] !== $_SESSION['csrf_token']
|| !isset($_POST['password'])
|| !isset($_POST['email']) ) {
echo "Invalid request";
exit(0);
}
$password = $_POST['password'];
$email = $_POST['email'];
if( !strlen($password) || !strlen($email) ){
$flashMsg->error("email or password should not empty", "alumni_login.php");
}
$_query = $db->prepare("SELECT `id`, `salt`, `status`, `password`,`img` FROM `alumnai` WHERE `email` = :email");
$_query->bindValue(':email', $email);
//database error
if( !$_query->execute() ){
$flashMsg->error("Error while processing request", "alumni_login.php");
}
//no token found
if( $_query->rowCount() == 0 ){
$flashMsg->error("Invalid email or password", "alumni_login.php");
}
$result = $_query->fetchAll(PDO::FETCH_OBJ)[0];
//email not confirmed yet
if( $result->status == 0 ){
$flashMsg->error("Please confirm your email.", "alumni_login.php");
}
//password does not match
if( $result->password !== Hash::make($password, $result->salt) ){
$flashMsg->error("Invalid email or password", "alumni_login.php");
}
//admin does not acpprove account yet
if( $result->status == 1 ){
$flashMsg->error("Your account needs admin approval.", "alumni_login.php");
}
$userData = (object) array(
"id" => $result->id,
"img" => $result->img
);
$_SESSION['user'] = $userData;
header('Location: alumni.php' );
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php $active_nav="alumni"; $page_title = "Alumni Members"; include 'includes/head.php' ?>
</head>
<body>
<?php include 'includes/header.php'; ?>
<div class="content container min-body">
<div class="row">
<?php $alumniActive="login"; include "includes/alumni_side_menu.php"; ?>
<div class="col-md-12">
<div class="form-center">
<?php
//show flash messages
if ($flashMsg->hasErrors()) {
$flashMsg->display();
}
if ($flashMsg->hasMessages($flashMsg::SUCCESS)) {
$flashMsg->display();
}
?>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title text-bold text-center">Member Login</h4>
</div>
<div class="panel-body" style="padding: 24px">
<form method="post" action="alumni_login.php" id="logform">
<div class="form-group input-icon">
<i class="fa fa-envelope" aria-hidden="true"></i>
<input type="email" name="email" placeholder="Email" class="form-control">
</div>
<div class="form-group input-icon">
<i class="fa fa-lock" aria-hidden="true"></i>
<input type="password" name="password" placeholder="Password" class="form-control">
</div>
<input type="hidden" value="<?php echo $_SESSION['csrf_token']; ?>" name="csrf_token" />
<div class="form-group text-center" style="margin-top: 10px;">
<button type="submit" data-loading-text="Logging in.." class="btn btn-primary btn-block btn-md">Login</button>
</div>
</form>
<a href="#" class="forgot-password pull-right">Forgot Password?</a>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include 'includes/footer.php' ?>
</body>