forked from chuushi/CoreProtect-Lookup-Web-Interface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
41 lines (35 loc) · 1.03 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
<?php
/**
* Login JSON
*
* Returns login success as a JSON file
* Redirects to index.php if login details are not defined in $_POST
*
* CoreProtect Lookup Web Interface
* @author Simon Chuu
* @copyright 2015-2020 Simon Chuu
* @license MIT License
* @link https://github.com/chuushi/CoreProtect-Lookup-Web-Interface
* @since 1.0.0
*/
require_once 'res/php/Session.class.php';
$config = require_once 'config.php';
$session = new Session($config);
$logout = array_key_exists('logout', $_POST);
if (!(array_key_exists('username', $_POST) && array_key_exists('password', $_POST))
&& !$logout) {
header("Location: index.php", true, 303);
exit();
}
$out = [];
if ($logout) {
$session->logout();
$out["success"] = true;
} elseif ($session->login($_POST['username'], $_POST['password'], array_key_exists('remember', $_POST))) {
$out["success"] = true;
$out["username"] = $session->getUsername();
} else {
$out["success"] = false;
}
header('Content-type:application/json;charset=utf-8');
echo json_encode($out);