-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·51 lines (44 loc) · 1.26 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
<?php
require_once 'config.php';
//Add the date formater to the filters
$Mustache_Engine->addHelper('date', [
'format' => function($value) { return date('m/d/Y', strtotime($value)); },
]);
if (isset($_POST) && array_key_exists('username', $_POST)) {
$username = $_POST['username'];
$password = $_POST['password'];
$User = new Models\User($DBH);
$params = Array(
'username' => $username,
'password' => hash('sha256', $password)
);
$user = $User->filter($params);
if ((count($user)) == 1 && array_key_exists('username', $user[0])) {
$_SESSION['username'] = $user[0]['username'];
$_SESSION['userid'] = $user[0]['id'];
} else {
$errorMsg = "Incorrect username/password combination.";
}
}
if (isset($_SESSION['username'])) {
$Task = new Models\Task($DBH);
$params = Array(
'user' => $_SESSION['userid'],
'completed' => null
);
$Tasks = $Task->filter($params);
$template = 'index';
$context = Array(
'tasks' => $Tasks,
'title' => 'DoIt',
'userid' => $_SESSION['userid']
);
} else {
$template = 'login';
$context = Array(
'error' => $errorMsg,
'title' => 'Login'
);
}
echo $Mustache_Engine->render($template, $context);
?>