forked from mholt/ysaward
-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
298 lines (244 loc) · 7.87 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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php
require_once "lib/init.php";
// Springboard if logged in
if (Member::IsLoggedIn())
header("Location: /directory");
// If user hasn't entered a ward password yet, prompt for it.
// This keeps the creepers out.
if (!isset($_SESSION['ward_id'])):
?>
<!DOCTYPE html>
<html>
<head>
<title>Register — <?php echo SITE_NAME; ?></title>
<?php include "includes/head.php"; ?>
</head>
<body class="narrow">
<form method="post" action="api/wardpwd.php">
<div class="text-center">
<a href="/">
<img src="<?php echo SITE_LARGE_IMG; ?>" alt="<?php echo SITE_NAME; ?>" class="logo-big">
</a>
<h1>Register</h1>
<hr>
<?php require "includes/controls/wardpicker.php"; ?>
<input type="password" name="pwd" placeholder="Ward password" required>
</div>
<div class="text-right">
<button type="submit">Continue</button><br>
<br>
</div>
</form>
<?php include "includes/footer.php"; ?>
<script>
$(function()
{
$('select').prop('required', true).focus();
$('select').change(function()
{
$('input[type=password]').focus();
});
$('form').ajaxForm({
complete: function(xhr)
{
if (xhr.status == 200)
// Correct ward/password combination; proceed to registration form.
window.location = '/register';
else
$.sticky(xhr.responseText || "There was a problem. (Maybe the Internet is really slow right now?) Please try again, or check your connection.", { classList: "error" });
}
});
});
</script>
</body>
</html>
<?php
else:
// User has chosen his/her ward and typed the correct password.
$wid = $_SESSION['ward_id'];
$ward = Ward::Load($wid);
if ($ward->Deleted)
fail("Sorry, for whatever reason, that ward is no longer available on this site.");
// Get a list of residences in the ward so the user can conveniently pick one
$residences = $ward->Residences();
?>
<!DOCTYPE html>
<html>
<head>
<title>Register — <?php echo SITE_NAME; ?></title>
<?php include "includes/head.php"; ?>
</head>
<body class="narrow">
<form method="post" action="/api/register.php">
<div class="text-center">
<a href="/">
<img src="<?php echo SITE_LARGE_IMG; ?>" alt="<?php echo SITE_NAME; ?>" class="logo-big">
</a>
<h1>Register</h1>
<mark>
<b>Ward:</b> <?php echo $ward->Name; ?>
</mark>
<hr>
<input type="email" name="email" placeholder="Email address" required>
<input type="password" name="pwd1" placeholder="Password" required>
<input type="password" name="pwd2" placeholder="Password again" required>
<br>
<input type="text" name="fname" placeholder="First name" required>
<input type="text" name="mname" placeholder="Middle name or initial">
<input type="text" name="lname" placeholder="Last name" required>
<hr>
<input type="radio" name="gender" data-label="I'm a guy" value="<?php echo Gender::Male; ?>">
<input type="radio" name="gender" data-label="I'm a girl" value="<?php echo Gender::Female; ?>"9>
<hr>
<div class="text-left" style="line-height: 18px;">
<hr class="line">
<b>Profile picture:</b>
<br><br>
<small class="clr-red">
<i>
<b>This is very important!</b><br>
Please choose a picture with just you in it.<br>
Max size: 5 MB
</i>
</small>
<br><br>
<input type="file" name="profilepic" accept="image/jpeg" style="font-size: 16px;">
<hr class="line">
</div>
<hr>
<!-- HOUSING -->
<select size="1" name="resID" id="bldg" required>
<option value="" selected>Housing...</option>
<?php foreach ($residences as $residence): ?>
<option value="<?php echo $residence->ID(); ?>"><?php echo $residence->Name; if (!$residence->NameUnique()) echo ' ('.$residence->Address.')'; ?></option>
<?php endforeach; ?>
<option value="-">(Other)</option>
</select>
<span id="usualapt" style="display: none;">
<input type="text" name="aptnum" maxlength="4" placeholder="Unit #">
</span>
<span id="otherapt" style="display: none;">
<input type="text" id="address" placeholder="Your full address" name="address" size="45" maxlength="255">
</span>
<input type="hidden" name="streetAddress" id="streetAddress" value="">
<input type="hidden" name="city" id="city" value="">
<input type="hidden" name="state" id="state" value="">
<input type="hidden" name="zipcode" id="zipcode" value="">
<!-- END HOUSING -->
<hr>
<input type="text" name="dob" id="dob" placeholder="Date of birth" required>
<input type="tel" name="phone" placeholder="Phone number">
<hr>
<div class="text-left">
<input type="checkbox" data-label="Keep birth year private" checked disabled>
<input type="checkbox" name="hideBirthday" data-label="Keep birth month and day private">
<input type="checkbox" name="hidePhone" data-label="Keep phone number private">
<input type="checkbox" name="hideEmail" data-label="Keep email address private">
</div>
<hr>
</div>
<div class="text-right">
<button type="submit">Continue</button><br>
<br>
</div>
</form>
<?php include "includes/footer.php"; ?>
<script src="//d79i1fxsrar4t.cloudfront.net/jquery.liveaddress/2.4/jquery.liveaddress.min.js"></script>
<script>
$(function()
{
// Stores a custom address in case the user hides then displays it again (cross-browserness)
var addrCache = $('#address').val();
$('input[type=radio], input[type=checkbox]').prettyCheckable();
$('input').first().focus();
$('#dob').change(function()
{
$.get('/api/tryparsedate.php', {
input: $(this).val(),
strictMonthDayYear: '1'
})
.success(function()
{
$(this).css('color', '');
$('[type=submit]').prop('disabled', false);
})
.fail(function(jqxhr)
{
$(this).css('color', '#CC0000');
$('[type=submit]').prop('disabled', false);
$.sticky(jqxhr.responseText || "Please type a better date, for example: July 3, 1990.", { classList: "error" });
});
});
$('#bldg').change(function()
{
if ($(this).val() == "-")
{
// Show the "full address" field
$('#usualapt input').prop('required', false);
$('#address').val(addrCache);
$('#usualapt').hide();
$('#otherapt').show();
$('#otherapt input').prop('required', true).focus();
liveaddress.mapFields('auto');
}
else if ($(this).val() != "")
{
// Show the "unit number" field
$('#otherapt input').prop('required', false);
$('#otherapt').hide();
addrCache = $('#address').val();
$('#address').val();
$('#usualapt').show();
$('#usualapt input').prop('required', true).focus();
liveaddress.deactivate();
}
else
{
$('#usualapt input, #otherapt input').prop('required', false);
$('#usualapt, #otherapt').hide();
liveaddress.deactivate();
}
});
$('form').ajaxForm({
complete: function(xhr)
{
if (xhr.status == 200)
{
// They've been logged in, so take them to the answers page
window.location = '/survey?new';
}
else
$.sticky(xhr.responseText || "Something's not quite right. Check your Internet connection, try again, then open a new tab and try logging in.", { classList: "error", autoclose: 7500 });
}
});
});
var liveaddress = $.LiveAddress({
key: "<?php echo SMARTYSTREETS_HTML_KEY; ?>",
autoMap: false
});
liveaddress.on("AddressAccepted", function(event, data, previousHandler)
{
if (data.response.isMissingSecondary())
{
data.address.abort(event);
alert("Don't forget your apartment number!");
}
else
{
if (data.response.chosen)
fillOutAddressFields(data.response.chosen);
previousHandler(event, data);
}
});
function fillOutAddressFields(responseAddr)
{
$('#streetAddress').val(responseAddr.delivery_line_1);
$('#city').val(responseAddr.components.city_name);
$('#state').val(responseAddr.components.state_abbreviation);
$('#zipcode').val(responseAddr.components.zipcode); // 5-digit only; this is on purpose
}
</script>
</body>
</html>
<?php endif; ?>