-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
executable file
·49 lines (35 loc) · 1.3 KB
/
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
<?php
require_once 'core/init.php';
$user = new User();
if($user->isLoggedIn()) {
Redirect::to('index.php');
}
if(Input::exists()) { //if input exists
if(Token::check(Input::get('token'))) { //check session token against form token
$validate = new Validate();
$validation = $validate->check($_POST, array( //validate inputs
'username' => array(
'required' => true
),
'password' => array(
'required' => true
)
));
if($validation->passed()) { //if validation passed
$remember = (Input::get('remember') === 'on') ? true : false; //if remember was checked, set remember to true
$login = $user->login(Input::get('username'), Input::get('password'), true); //login user based on username and password
if($login) { //if login is true
Redirect::to('index.php'); //redirect to index
}
else {
echo 'Bad login'; //tell user it was bad login (should probably style this nicely and template it)
}
}
else {
foreach($validation->errors() as $error) { //for each error, display error
echo $error . '<br />';
}
}
}
}
require_once 'includes/templates/login_page.php'; //require login page