-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprofile.php
More file actions
executable file
·272 lines (245 loc) · 9.68 KB
/
Copy pathprofile.php
File metadata and controls
executable file
·272 lines (245 loc) · 9.68 KB
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
<?php
require_once('access.php');
require_once('dal.php');
require_once('utils.php');
require_once('email.php');
$error = null;
$message = null;
$user = null;
$person = null;
$dal = new DAL($opts['hn'], $opts['db'], $opts['un'], $opts['pw']);
try {
$dal->beginTransaction();
if (isset($_GET['verify'])) {
if (!$dal->loginWithEmailSharedSecret($_GET['person_id'], $_GET['person_email_shared_secret'])) throw new UserException('Login failed.');
}
$user = $dal->selectUser();
if ($user === null) throw new UserException('Login required.');
if (isset($_GET['person_id'])) {
$person = $dal->selectPersonById($_GET['person_id']);
if ($person === null) throw new UserException('Profile not found.');
} else {
$person = $user;
}
if ($user['person_id'] !== $person['person_id'] && $user['person_is_moderator'] !== 'y') throw new UserException('Moderator login required.');
if (isset($_POST['save'])) {
$person['person_first_name'] = $_POST['person_first_name'];
$person['person_last_name'] = $_POST['person_last_name'];
$person['person_organization'] = $_POST['person_organization'];
if ($user['person_is_moderator'] === 'y') {
$person['person_is_moderator'] = $_POST['person_is_moderator'];
}
$dal->updatePerson($person);
$message = 'Saved.';
} else if (isset($_POST['subscribe'])) {
$person['person_subscribe'] = 'y';
$dal->updatePerson($person);
$message = 'Subscribed.';
} else if (isset($_POST['unsubscribe'])) {
$person['person_subscribe'] = 'n';
$dal->updatePerson($person);
$message = 'Unsubscribed.';
} else if (isset($_POST['delete'])) {
if (count($dal->selectUniqueIdsByPersonId($person['person_id'])) > 0) throw new UserException('Delete unique id ranges first.');
$dal->deletePerson($person['person_id']);
if ($user['person_is_moderator'] === 'y') {
header('Location: people');
} else {
header('Location: .');
}
exit;
} else if (isset($_POST['send_verification_email'])) {
$url = "https://" . $_SERVER['HTTP_HOST'] . "/profile?person_id=" . $person['person_id'] . "&person_email_shared_secret=" . $person['person_email_shared_secret'] . '&verify';
$name = formatPersonName($person);
$email = formatPersonEmail($person);
$subject = "Register as OpenLCB User";
$body = "Hi $name,
You can verify your email address with the link below.
$url
The OpenLCB Group";
mail_abstraction(array( $email ), $subject, $body);
$message = 'Verification email sent.';
} else if (isset($_GET['verify'])) {
$person['person_email_verified'] = 'y';
$dal->updatePerson($person);
$message = 'Email address verified.';
}
$dal->commit();
} catch (UserException $e) {
$dal->rollback();
$error = $e->getMessage();
} catch (Exception $e) {
$dal->rollback();
throw $e;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="OpenLCB ID Registry"/>
<link rel="icon" href="../../favicon.ico"/>
<title>View OpenLCB Profile</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"/>
<!-- Custom styles for this template -->
<link href="theme.css" rel="stylesheet"/>
</head>
<body>
<?php
include('navbar.php');
?>
<div class="container-fluid">
<h2>View OpenLCB Profile</h2>
<?php
if ($error !== null) {
?>
<div class="alert alert-danger">
<a href="profile<?php if ($user['person_id'] !== $person['person_id']) echo '?person_id=' . $person['person_id']; ?>" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></a>
<?php echo htmlspecialchars($error); ?>
</div>
<?php
} else if ($message !== null) {
?>
<div class="alert alert-info">
<a href="profile<?php if ($user['person_id'] !== $person['person_id']) echo '?person_id=' . $person['person_id']; ?>" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></a>
<?php echo htmlspecialchars($message); ?>
</div>
<?php
} else {
?>
<form method="POST">
<h3><?php echo htmlspecialchars(formatPersonName($person)); ?></h3>
<table class="table table-condensed">
<tbody>
<tr>
<th>First name</th>
<?php
if (isset($_POST['edit'])) {
?>
<td><input name="person_first_name" class="form-control input-sm" value="<?php echo htmlspecialchars($person['person_first_name']); ?>"/></td>
<?php
} else {
?>
<td><?php echo htmlspecialchars($person['person_first_name']); ?></td>
<?php
}
?>
</tr>
<tr>
<th>Last name</th>
<?php
if (isset($_POST['edit'])) {
?>
<td><input name="person_last_name" class="form-control input-sm" value="<?php echo htmlspecialchars($person['person_last_name']); ?>"/></td>
<?php
} else {
?>
<td><?php echo htmlspecialchars($person['person_last_name']); ?></td>
<?php
}
?>
</tr>
<tr>
<th>Organization</th>
<?php
if (isset($_POST['edit'])) {
?>
<td><input name="person_organization" class="form-control input-sm" value="<?php echo htmlspecialchars($person['person_organization']); ?>"/></td>
<?php
} else {
?>
<td><?php echo htmlspecialchars($person['person_organization']); ?></td>
<?php
}
?>
</tr>
<tr>
<th>Email address</th>
<td><a href="<?php echo htmlspecialchars('mailto:' . rawurlencode(formatPersonEmail($person))); ?>"><?php echo htmlspecialchars($person['person_email']); ?></a></td>
</tr>
<tr>
<th>Email address verified</th>
<td><?php echo htmlspecialchars($person['person_email_verified']); ?></td>
</tr>
<tr>
<th>Subscribed</th>
<td><?php echo htmlspecialchars($person['person_subscribe']); ?></td>
</tr>
<tr>
<th>Moderator</th>
<?php
if (isset($_POST['edit']) && $user['person_is_moderator'] === 'y') {
?>
<td>
<label><input type="radio" name="person_is_moderator" value="y"<?php if ($person['person_is_moderator'] === 'y') echo " checked" ?>/> y</label><br/>
<label><input type="radio" name="person_is_moderator" value="n"<?php if ($person['person_is_moderator'] === 'n') echo " checked" ?>/> n</label>
</td>
<?php
} else {
?>
<td><?php echo htmlspecialchars($person['person_is_moderator']); ?></td>
<?php
}
?>
</tr>
<tr>
<th>Created</th>
<td><?php echo htmlspecialchars($person['person_created']); ?></td>
</tr>
<tr>
<th>Updated</th>
<td><?php echo htmlspecialchars($person['last_updated']); ?></td>
</tr>
<tr>
<th>Unique ID ranges</th>
<td><?php echo htmlspecialchars($person['person_uniqueid_count']); ?></td>
</tr>
</tbody>
</table>
<?php
if (isset($_POST['edit'])) {
?>
<button type="submit" name="save" class="btn btn-sm btn-success"><span class="glyphicon glyphicon-floppy-saved"></span> Save</button>
<button type="submit" name="cancel" class="btn btn-sm btn-danger"><span class="glyphicon glyphicon-floppy-remove"></span> Cancel</button>
<?php
} else {
?>
<a href="uniqueidranges<?php echo '?person_id=' . $person['person_id']; ?>" class="btn btn-sm btn-primary"><span class="glyphicon glyphicon-erase"></span> Show unique ID ranges</a>
<button type="submit" name="edit" class="btn btn-sm btn-warning"><span class="glyphicon glyphicon-edit"></span> Edit</button>
<?php
if ($user['person_id'] === $person['person_id'] || $user['person_is_moderator'] === 'y') {
?>
<a href="updateemailaddress<?php if ($user['person_id'] !== $person['person_id']) echo '?person_id=' . $person['person_id']; ?>" class="btn btn-sm btn-warning"><span class="glyphicon glyphicon-erase"></span> Update email address</a>
<a href="updatepassword<?php if ($user['person_id'] !== $person['person_id']) echo '?person_id=' . $person['person_id']; ?>" class="btn btn-sm btn-warning"><span class="glyphicon glyphicon-erase"></span> Update password</a>
<?php
}
if ($person['person_email_verified'] !== 'y') {
?>
<button type="submit" name="send_verification_email" class="btn btn-sm btn-warning"><span class="glyphicon glyphicon-send"></span> Send verification email</button>
<?php
}
if ($person['person_subscribe'] !== 'y') {
?>
<button type="submit" name="subscribe" class="btn btn-sm btn-success"><span class="glyphicon glyphicon-envelope"></span> Subscribe</button>
<?php
} else {
?>
<button type="submit" name="unsubscribe" class="btn btn-sm btn-danger"><span class="glyphicon glyphicon-envelope"></span> Unsubscribe</button>
<?php
}
?>
<button type="submit" name="delete" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this profile?');"><span class="glyphicon glyphicon-trash"></span> Delete</button>
<?php
}
?>
</form>
<?php
}
?>
</div>
</body>
</html>