-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
61 lines (49 loc) · 1.77 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
50
51
52
53
54
55
56
57
58
59
60
61
<?php
require 'vendor/autoload.php';
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseACL;
use Parse\ParsePush;
use Parse\ParseUser;
//use Parse\ParseInstallation;
use Parse\ParseException;
//use Parse\ParseCloud;
use Parse\ParseClient;
use Parse\ParseSessionStorage;
class AdminException extends Exception { }
/* Start session MUST be between autoload and intialization. */
session_start();
$app_id = "kddcodGlyJ6DmGI7FihXt8BsXyOTS09Dgpj8UA49";
$rest_key = "ryU6g6D37JtDqIAnPbTq4SLNmihEIy8kSNPZxlhj";
$master_key = "Fm9X40ewplSIEDTOmYxVdCEN7ge31vgfFwScYr3y";
ParseClient::initialize( $app_id, $rest_key, $master_key );
/* Backup logout info goes here */
// if(isset($_SESSION["username"])) {
// unset($_SESSION["username"]);
// }
$user = new ParseUser();
if(isset($_POST["username"]) && isset($_POST["password"]) && $_POST["username"] != "" && $_POST["password"] != "") {
/* set session storage */
ParseClient::setStorage( new ParseSessionStorage() );
try {
$user = ParseUser::logIn($_POST["username"], $_POST["password"]);
if(ParseUser::getCurrentUser()->get("isAdmin") != TRUE) {
ParseUser::logOut();
throw new AdminException("User is not an admin");
}
$_SESSION["username"] = ParseUser::getCurrentUser()->get("username");
$_SESSION["friendlyName"] = ParseUser::getCurrentUser()->get("friendlyName");
// Do stuff after successful login.
} catch (ParseException $ex) {
// The login failed. Check error to see why.
setcookie("loginError",$ex->getMessage());
} catch (AdminException $aex) {
setcookie("loginError",$aex->getMessage());
}
}
else {
setcookie("loginError","Failed to login");
}
header("Location: index.php"); /* Redirect browser */
exit();
?>