-
Notifications
You must be signed in to change notification settings - Fork 6
/
process-auth.php
53 lines (38 loc) · 1.24 KB
/
process-auth.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
<?php
include "includes/_process_include.php";
$loginOBJ = new Login();
// structure JSON response
$response = array();
$response['success'] = false;
$response['messages'] = array();
if (!array_key_exists("action", $_POST)) {
$response["messages"][] = 'Invalid action';
echo json_encode($response);
exit();
}
if ( $_SERVER["REQUEST_METHOD"] == "POST" ) {
$action = $_POST['action'];
switch($action) {
case 'login':
$username = htmlspecialchars(trim($_POST['username']));
$password = htmlspecialchars(trim($_POST['password']));
$result = $loginOBJ->login($username,$password);
if($result != false) {
$_SESSION['user'] = $username;
$_SESSION['type'] = $result['type'];
$response['success'] = true;
}
echo json_encode($response);
break; //END login
case 'logout':
$result = $loginOBJ->logout();
if($result == true) {
$response['success'] = true;
}
echo json_encode($response);
break; //END login
default:
break; // END 'default'
} // End Switch
}
?>