forked from StartupAPI/users
/
register.php
274 lines (232 loc) · 5.42 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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<?php
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/User.php');
require_once(dirname(__FILE__).'/Invitation.php');
$errors = array();
$user_exists = false;
if (UserConfig::$enableRegistration && array_key_exists('register', $_POST))
{
$module = AuthenticationModule::get($_GET['module']);
if (is_null($module))
{
throw new Exception('Wrong module specified');
}
$invitation = null;
if (UserConfig::$enableInvitations)
{
if (!array_key_exists('invite', $_GET))
{
throw new Exception('Invitation code is not submitted');
}
$invitation = Invitation::getByCode($_GET['invite']);
if (is_null($invitation) || $invitation->getStatus())
{
throw new Exception('Invitation code is invalid');
}
}
try
{
$remember = false;
$user = $module->processRegistration($_POST, $remember);
if (is_null($user))
{
header('Location: '.UserConfig::$USERSROOTURL.'/register.php?module='.$_GET['module'].'&error=failed');
exit;
}
if (!is_null($invitation))
{
$invitation->setUser($user);
$invitation->save();
}
$user->setSession($remember);
$return = User::getReturn();
User::clearReturn();
if (!is_null($return))
{
header('Location: '.$return);
}
else
{
header('Location: '.UserConfig::$DEFAULTREGISTERRETURN);
}
exit;
}
catch(InputValidationException $ex)
{
$errors[$module->getID()] = $ex->getErrors();
}
catch(ExistingUserException $ex)
{
$user_exists = true;
$errors[$module->getID()] = $ex->getErrors();
}
}
require_once(UserConfig::$header);
?>
<style>
.userbase-errorbox {
background: #f7dfb9;
font: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
padding: 0.4em 1em;
margin: 1em 0;
width: 465px;
border: 4px solid #f77;
border-radius: 7px;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
font-size: 1.2em;
color: #500;
font-weight: bold;
}
.userbase-errorbox ul {
margin: 0;
padding-left: 1em;
}
#userbase-authlist {
font: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
background: white;
padding: 0 1em;
margin: 0 auto;
width: 480px;
}
#userbase-authlist h2 {
font-weight: bold;
font-size: 2.5em;
}
#userbase-authlist h3 {
font-weight: bold;
font-size: 1.5em;
}
</style>
<div id="userbase-authlist">
<h2>Sign up</h2>
<?php
if (UserConfig::$enableRegistration)
{
$show_registration_form = true;
$invitation_used = null;
if (UserConfig::$enableInvitations)
{
$message = UserConfig::$invitationRequiredMessage;
$show_registration_form = false;
if (array_key_exists('invite', $_GET))
{
$invitation = Invitation::getByCode($_GET['invite']);
if (is_null($invitation) || $invitation->getStatus())
{
$message = 'Invitation code you entered is not valid';
}
else
{
$invitation_used = $invitation;
$show_registration_form = true;
}
}
if (!$show_registration_form) {
?>
<style>
#userbase-invitation-form {
font: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
padding: 0.4em 1em;
margin: 0;
width: 382px;
border: 4px solid #ccc;
border-radius: 7px;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
}
#userbase-invitation-form p {
font-size: 1.2em;
line-height: 1.5;
clear: both;
margin: 0 0 .75em;
padding: 0;
}
#userbase-invitation-form fieldset {
border: 0;
padding: 0;
margin: 0;
}
#userbase-invitation-form legend {
border: 0;
padding: 0;
margin: 0;
font-size: 1.8em;
line-height: 1.8;
padding-bottom: .6em;
}
#userbase-invitation-button {
padding: 0.3em 25px;
cursor: pointer;
}
#userbase-invitation-form input {
background: #f6f6f6;
border: 2px solid #888;
border-radius: 2px;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
padding: 4px;
}
#userbase-invitation-form input:focus {
background: #fff;
}
#userbase-invitation-form abbr {
cursor: help;
font-style: normal;
border: 0;
color: red;
font-size: 1.2em;
font-weight: bold;
}
#userbase-invite-code {
width: 290px;
}
</style>
<form id="userbase-invitation-form" action="" method="GET">
<fieldset>
<legend><?php echo $message?></legend>
<p>
<input id="userbase-invite-code" name="invite" size="30" value="<?php echo UserTools::escape($_GET['invite'])?>"/>
<button id="userbase-invitation-button" type="submit">>></button>
</p>
</fieldset>
</form>
<?php
}
}
if ($show_registration_form)
{
foreach (UserConfig::$authentication_modules as $module)
{
$id = $module->getID();
?>
<div style="margin-bottom: 2em">
<h3 name="<?php echo $id?>"><?php echo $module->getTitle()?></h3>
<?php
if (array_key_exists($id, $errors) && is_array($errors[$id]) && count($errors[$id]) > 0)
{
?><div class="userbase-errorbox"><ul><?php
foreach ($errors[$id] as $field => $errorset)
{
foreach ($errorset as $error)
{
?><li><?php echo $error?></li><?php
}
}
?></ul></div><?php
}
$module->renderRegistrationForm(true, "?module=$id&invite=".(is_null($invitation_used) ? '' : $invitation_used->getCode()), array_key_exists($id, $errors) ? $errors[$id] : array(), $_POST);
?></div>
<?php
}
}
}
else
{
?>
<p><?php echo UserConfig::$registrationDisabledMessage?></p>
<p>If you already have an account, you can <a href="<?php echo UserConfig::$USERSROOTURL?>/login.php">log in here</a>.</p>
<?php
}
?></div><?php
require_once(UserConfig::$footer);