-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
213 lines (197 loc) · 6.01 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
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
<?php
// This file is part of Music Match.
// Copyright (C) 2022 David P. Anderson
//
// Music Match is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// Music Match is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Music Match. If not, see <http://www.gnu.org/licenses/>.
// --------------------------------------------------------------------
// Music Match registration.
// There are 3 pages (forms).
// For convenience all forms and their handlers are in this file.
//
// page 1:
// form:
// user name, email addr
// handler:
// check if name or addr are taken
// create unverified user record
// send email with code
// send cookie with auth
//
// page 2:
// form:
// code
// handler:
// check code
//
// page 3:
// form:
// password, country, postal code
// handler:
// check code again
// update user record, mark as verified
// show Intro page
$show_home_link = false;
require_once("../inc/util.inc");
require_once("../inc/user_util.inc");
require_once("../inc/boinc_db.inc");
require_once("../inc/account.inc");
function form1() {
page_head("Create account");
form_start("signup.php", "POST", "name=f");
form_input_text("User name<br><font size=-1>Your real name or a pseudonym</font>", 'name');
form_focus("f", "name");
form_input_text("Email address", 'email_addr');
form_submit("OK", 'name=action value=form1');
form_end();
page_tail();
}
function handler1() {
$name = strip_tags(post_str('name'));
$reason = '';
if (!is_valid_user_name($name, $reason)) {
error_page($reason);
}
$email_addr = strip_tags(post_str('email_addr'));
if (!filter_var($email_addr, FILTER_VALIDATE_EMAIL)) {
error_page("Invalid email address");
}
$user = BoincUser::lookup_name(BoincDb::escape_string($name));
if ($user) {
page_head("User name in use");
echo "The user name $name is already taken. Try a different name.";
page_tail();
return;
}
$user = BoincUser::lookup_email_addr(BoincDb::escape_string($email_addr));
if ($user) {
if ($user->email_validated) {
error_page("There's already an account with email address $email_addr.");
}
// otherwise contine
} else {
$user = make_user($email_addr, $name, '');
}
$code = random_int(1000, 9999);
$user->update("seti_id=$code");
send_email($user, 'Music Match registration',
"Your Music Match verification code is $code"
);
send_cookie('auth', "$user->authenticator", true);
form2($user);
}
// come here if mm_get_logged_in_user() found and unverified account
//
function verify() {
$user = get_logged_in_user();
$code = random_int(1000, 9999);
$user->update("seti_id=$code");
send_email($user, 'Music Match registration',
"Your Music Match verification code is $code"
);
form2($user);
}
function form2($user) {
page_head("Enter verification code");
echo "
<p>
We emailed a verification code to $user->email_addr.
Please enter it here:
<p>
";
form_start("signup.php", "POST");
form_input_text("Verification code", 'code');
form_submit('OK', 'name=action value=form2');
form_end();
echo "
If you don't see the email, check your spam folder.
";
page_tail();
}
function handler2() {
$user = get_logged_in_user();
$code = post_int('code');
if ($code != $user->seti_id) {
page_head("Verification code mismatch");
echo "That code doesn't match the one we sent. Please try again.";
page_tail();
return;
}
form3($code);
}
function form3($code) {
global $show_home_link;
page_head("Account setup");
form_start("signup.php", "POST");
form_input_text("Password", "passwd", "", "password", 'id="passwd"', passwd_visible_checkbox("passwd"));
form_select('Country', 'country', country_select_options());
form_input_text('Postal code<br><small>Used for identifying nearby users</small>', 'postal_code');
form_input_hidden('code', $code);
form_submit('OK', 'name=action value=form3');
form_end();
$show_home_link = false;
page_tail();
}
function handler3() {
$user = get_logged_in_user();
$code = post_int('code');
if ($code != $user->seti_id) {
error_page('Bad verification code');
}
$passwd = post_str('passwd');
if (!$passwd) error_page("Password must be nonempty");
if (!is_ascii($passwd)) error_page("Password must be ASCII");
$passwd_hash = md5($passwd.$user->email_addr);
$country = post_str('country', true);
if ($country && !is_valid_country($country)) {
error_page("invalid country");
}
$postal_code = strip_tags(post_str('postal_code'));
$user->update(
sprintf("email_validated=1, passwd_hash='%s', country='%s', postal_code='%s'",
$passwd_hash, BoincDb::escape_string($country),
BoincDb::escape_string($postal_code)
)
);
Header("Location: home.php");
}
$action = post_str('action', true);
if ($action) {
switch($action) {
case 'form1':
handler1();
break;
case 'form2':
handler2();
break;
case 'form3':
handler3();
break;
default:
error_page("unknown post action $action");
}
} else {
$action = get_str('action', true);
if ($action) {
switch($action) {
case 'verify':
verify();
break;
default:
error_page("unknown get action $action");
}
} else {
form1();
}
}
?>