-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
88 lines (71 loc) · 2.7 KB
/
register.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
require 'vendor/autoload.php';
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseACL;
use Parse\ParsePush;
use Parse\ParseUser;
use Parse\ParseException;
use Parse\ParseFile;
use Parse\ParseCloud;
use Parse\ParseClient;
use Parse\ParseSessionStorage;
/* 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"]) && isset($_POST["friendly"]) && $_POST["username"] != "" && $_POST["password"] != "" && $_POST["friendly"] != "") {
$email = $_POST["username"];
$pass = $_POST["password"];
$suffix = substr($email, strpos($email, '@'));
if(strtolower($suffix) != "@gcc.edu") {
setcookie("regError","Must be a gcc.edu email");
header("Location: index.php"); /* Redirect browser */
exit();
}
if(strlen($pass) < 8) {
setcookie("regError","Password must be at least 8 characters");
header("Location: index.php"); /* Redirect browser */
exit();
}
//Will remove any numbers, thus if no numbers exist it will match the length
if(preg_match('/\d/',$string) == 0) {
setcookie("regError","Password must contain numbers");
header("Location: index.php"); /* Redirect browser */
exit();
}
//Will remove any numbers, thus if it is all numbers the length will be 0
if(preg_match('/[a-zA-Z]/',$pass) == 0) {
setcookie("regError","Password must contain letters");
header("Location: index.php"); /* Redirect browser */
exit();
}
/* set session storage */
ParseClient::setStorage( new ParseSessionStorage() );
try {
$user->setUsername($_POST["username"]);
$user->setEmail($_POST["username"]);
$user->setPassword($_POST["password"]);
$user->set("friendlyName",$_POST["friendly"]);
$user->set("isAdmin",TRUE);
$user->signUp();
$_SESSION["username"] = ParseUser::getCurrentUser()->get("username");
$_SESSION["friendlyName"] = ParseUser::getCurrentUser()->get("friendlyName");
} catch (ParseException $ex) {
// error in $ex->getMessage();
setcookie("regError",$ex->getMessage());
}
}
else {
setcookie("regError","Username, Password, and Chat Name are required");
}
header("Location: index.php"); /* Redirect browser */
exit();
?>