-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchange_username.php
More file actions
64 lines (53 loc) · 1.85 KB
/
change_username.php
File metadata and controls
64 lines (53 loc) · 1.85 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
<?php
$pageTitle = 'Change username';
require_once("db.inc.php");
refreshUser();
$errors = [];
if (@$_POST) {
if (@$_POST['changeUsername']) {
$username = strtoupper($_POST['username']);
if (!preg_match("/^[A-Z0-9-]{3,16}$/", $username)) {
$errors[] = "The username may only consist of the letters A-Z, 0-9 and -, and must be between 3 and 16 characters long.";
}
if (!isUsernameAvailable($username)) {
$errors[] = "This username is alredy taken.";
}
if (!$errors) {
changeUsername($username);
session_destroy();
$changeUsernameOk = true;
}
}
}
?>
<?php include('settings_begin.inc.php') ?>
<h1 class="page-header">Change username</h1>
<?php foreach ($errors as $error): ?>
<div class="alert alert-danger" role="alert">
<?php echo $error ?>
</div>
<?php endforeach; ?>
<?php if (@$changeUsernameOk): ?>
<div class="alert alert-info alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
Your username has been changed successfully. You have been logged out.
<p><a href="/login">Login again</a></p>
</div>
<?php else: ?>
<fieldset>
<div class="form-group">
<form class="limit-width" method="post" action="" autocomplete="off">
<div class="form-group">
<label for="username">Username</label>
<?php if (@$_POST['username']): ?>
<input type="text" class="form-control" id="username" name="username" value="<?php echo htmlspecialchars(@$_POST['username']) ?>">
<?php else: ?>
<input type="text" class="form-control" id="username" name="username" value="<?php echo htmlspecialchars(@$_SESSION['user']['username']) ?>">
<?php endif; ?>
</div>
<button type="submit" name="changeUsername" value="1" class="btn btn-primary">Save</button>
</form>
</div>
</fieldset>
<?php endif; ?>
<?php include('settings_end.inc.php') ?>