-
Notifications
You must be signed in to change notification settings - Fork 2
/
SignUp.php
70 lines (56 loc) · 1.74 KB
/
SignUp.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
<?php
include 'classes/GlobalErrorHandler.php';
include 'classes/Config.php';
include 'classes/DBConnection.php';
include 'classes/WebResponder.php';
include 'classes/AppArgs.php';
class SignUp {
private $arguments;
private $responder;
private $username;
private $email;
private $password;
function __construct()
{
$this->arguments = new AppArgs(AppArgs::GET);
$this->getResponder();
if (!$this->arguments->isVarExist('username', true) ||
!$this->arguments->isVarExist('email', true) ||
!$this->arguments->isVarExist('password', true)) {
$this->responder->respond("Invalid username or password");
}
$this->performQuery();
$this->responder->respond("success");
}
private function getResponder() {
if ($this->arguments->isVarExist(Config::JSONP_VAR_NAME)) {
$this->responder = new JSONPResponder();
$this->responder->setFunctionName($this->arguments->getVar(Config::JSONP_VAR_NAME));
}
else {
$this->responder = new JSONResponder();
}
}
private function escapeStrings($conn) {
$this->username = $conn->escapeString($this->arguments->getVar('username'));
$this->email = $conn->escapeString($this->arguments->getVar('email'));
$this->password = $conn->escapeString($this->arguments->getVar('password'));
}
private function buildQuery($conn) {
$this->escapeStrings($conn);
$this->password = crypt($this->password);
return "call insert_user('$this->username', '$this->password', '$this->email')";
}
private function performQuery() {
try {
$dbconn = new DBConnection(Config::DB_CONFIG, $this->responder);
$this->queryResult = $dbconn->query($this->buildQuery($dbconn));
$dbconn->close();
}
catch (Exception $e) {
$this->responder->respond($e->getMessage());
}
}
}
new SignUp();
?>