-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapprove.php
48 lines (34 loc) · 1.43 KB
/
approve.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
<?php
/*
* We process the admin login form here
*/
// Start from getting the hader which contains some settings we need
require_once 'includes/headx.php';
// require the admins class which containes most functions applied to admins
require_once "includes/classes/admin-class.php";
$admins = new Admins($dbh);
// Let's process the form now
// Starting by checking if the forme has been submitted
if (!isset($_POST) || sizeof($_POST) == 0 )
{
session::set('error', 'Submit the form first.');
$commons->redirectTo(SITE_PATH.'login.php');
}
// If the form is submitted, let's check if the fields are not empty
if ($commons->isFieldEmpty($_POST['username']) || $commons->isFieldEmpty($_POST['password']) )
{
session::set('error', 'All fields are required.');
$commons->redirectTo(SITE_PATH.'login.php');
}
// Now let's check if the the username and password match a line in our table
$user_name = htmlspecialchars( $_POST['username'], ENT_QUOTES, 'UTF-8' );
$user_pwd = htmlspecialchars( $_POST['password'], ENT_QUOTES, 'UTF-8' );
if (!$admins->loginAdmin($user_name, $user_pwd))
{
session::set('error', 'Cannot connect you. Check your credentials.');
$commons->redirectTo(SITE_PATH.'login.php');
}
// Otherwise we can set a session to the admin and send him to the dashboard
// The session will hold only the username.
session::set('admin_session', $user_name);
$commons->redirectTo(SITE_PATH.'index.php');