This repository has been archived by the owner on Jan 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
SOAPRegistration.php
158 lines (144 loc) · 5.51 KB
/
SOAPRegistration.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
class SOAPRegistration
{
protected $messages = Array();
protected $db;
protected $soap;
protected $showForm = true;
public function __construct()
{
try
{
$this -> dbConnect();
if ($this -> validateInput())
{
$this -> soapConnect();
$this -> showForm = false;
//Enable one or the other account/bnetaccount create lines
//Use double slashes (like these lines) to disable the line, and remove them to enable the line
//account = Classic-WotLK
//bnetaccount = WoD
//Take note the @CHANGEME on WoD, change this and tell users to add it at WoW login screen (so Espionage724 at registration = Espionage724@realmofespionage at WoW login screen)
$this -> soapCommand('account create '.$_POST["accountname"].' '.$_POST["password"]);
//$this -> soapCommand('bnetaccount create '.$_POST["accountname"].'@CHANGEME '.$_POST["password"]);
//Change addon number below if needed, else comment out
$this -> soapCommand('account set addon '.$_POST["accountname"].' 1');
$stmt = $this -> db -> prepare("UPDATE `account` SET `email` = ?, `expansion` = ? WHERE `username` = ?;");
$stmt -> bind_param('sis', $_POST["email"], $_POST["expansion"], $_POST["accountname"]);
$stmt -> execute();
}
}
catch (Exception $e)
{
$this -> addMessage($e -> getMessage());
}
}
protected function validateInput()
{
if (empty($_POST["accountname"]))
{
$this -> addMessage('Please enter your desired Account Name.');
}
elseif (!preg_match('/^[a-z0-9]{5,32}$/i', $_POST["accountname"]))
{
$this -> addMessage('Your Account Name must be between 5 and 32 characters long and may only contain letters and numbers.');
}
else
{
$stmt = $this -> db -> prepare("SELECT `username` FROM `account` WHERE `username` = ?;");
$stmt -> bind_param('s', $_POST["accountname"]);
$stmt -> execute();
$stmt -> store_result();
if ($stmt->num_rows > 0)
{
$this -> addMessage('This Account Name is already in-use. Please choose a different name.');
}
}
if (empty($_POST["password"]))
{
$this -> addMessage('Please enter your desired Password for this account.');
}
else
{
if (!preg_match('/^[a-z0-9!"#$%@]{8,128}$/i', $_POST["password"]))
{
$this -> addMessage('The Password must be between 8 and 128 characters long and may only contain letters, numbers and the following special characters: !"#$%@');
}
if (empty($_POST["password2"]))
{
$this -> addMessage('Please confirm your Password.');
}
elseif ($_POST["password"] !== $_POST["password2"])
{
$this -> addMessage('The two Passwords do not match. Please retype your Passwords.');
}
}
if (empty($_POST["email"]))
{
$this -> addMessage('Please enter the Email Address you would like to associate with this Account Name.');
}
elseif (!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL))
{
$this -> addMessage('The Email Address you have entered is invalid. Please try again.');
}
elseif (strlen($_POST["email"]) > 254)
{
$this -> addMessage('The Email Address can not be longer than 254 characters long.');
}
elseif (CHECK_FOR_DUPLICATE_EMAIL)
{
$stmt = $this -> db -> prepare("SELECT `email` FROM `account` WHERE `email` = ?;");
$stmt -> bind_param('s', $_POST["email"]);
$stmt -> execute();
$stmt -> store_result();
if ($stmt->num_rows > 0)
{
$this -> addMessage('The Email Address entered is already associated with another Account Name. Please use a different address.');
}
}
return empty($this -> messages);
}
protected function dbConnect()
{
$this -> db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (mysqli_connect_errno())
{
throw new Exception("Database connection failed: ". mysqli_connect_error());
}
return true;
}
protected function soapConnect()
{
$this -> soap = new SoapClient(NULL, Array(
'location'=> 'http://'. SOAP_IP .':'. SOAP_PORT .'/',
'uri' => SOAP_URI,
'style' => SOAP_RPC,
'login' => SOAP_USER,
'password' => SOAP_PASS,
'keep_alive' => false //keep_alive only works in php 5.4.
));
}
protected function soapCommand($command)
{
$result = $this -> soap -> executeCommand(new SoapParam($command, 'command'));
$this -> addMessage($result);
return true;
}
protected function addMessage($message)
{
$this -> messages[] = $message;
return true;
}
public function getMessages()
{
return $this -> messages;
}
public function showForm()
{
return $this -> showForm;
}
public function __destruct()
{
$this -> db -> close();
}
}