-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_user.php
130 lines (116 loc) · 4.39 KB
/
create_user.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
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<?php require_once 'head.php'; ?>
<script type="text/javascript" src="useful.js"></script>
</head>
<body>
<?php
require_once 'nav.php';
// To represent the type of the error.
$result = -1;
// Only admin users can upload files.
if (!logged_in() || $_SESSION['usertype'] != "admin") {
redirect_no_permission();
} else if ($_POST) {
$password = $_POST['password'];
$confirm = $_POST['confirm'];
if ($password != $confirm) {
$result = 1;
} else {
$uname = $_POST['username'];
$email = $_POST['email'];
$is_random = isset($_POST['random']);
// The value of type here is either 'student' or 'admin'.
$type = $_POST['type'];
$result = create_user($uname, $password, $type, $email, $is_random);
}
}
?>
<h1>Create User<small> (For Admin only)</small></h1>
<br><br>
<div class="container">
<div class="col-xs-12 col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-8 col-lg-offset-2">
<form role="form" method="post" action="create_user.php" onsubmit="confirm_new_user();">
<div id="error_message" class="">
<?php if ($result == 0) {
echo "A new user has been created successfully. A confirmation email has been sent to " . $email . ".";
?>
<script type="text/javascript">add_success_class();</script>
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<?php
} else if ($result > 0) {
if ($result == 1) {
echo "The two passwords you have entered do not match.";
} else if ($result == 2) {
echo "There is an existing user with the same username. Please change.";
} else if ($result == 3) {
echo "Your password is too simple. Guideline for a good password: " .
"1) It has to be at least 8 characters long; " .
"2) It has to contain both numeric and alphabetic digits.";
} else if ($result == 4) {
echo "The account has been created. " .
"However, it seems that the confirmation email has not been sent successfully.";
} else {
echo "Unknown error: Please contact the system admin.";
}
?>
<script type="text/javascript">add_alert_class();</script>
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<?php
} ?>
</div>
<br>
<div class="form-group">
<label for="username">Username</label>
<input type="text" name="username" class="form-control" id="username" placeholder="Type username" accesskey="u" tabindex="1" required autofocus>
</div>
<div class="form-group">
<label for="type">User type</label>
<br>
<div class="radio-inline">
<label><input type="radio" name="type" value="admin" id="type_admin" accesskey="a" tabindex="2" required>Admin</label>
</div>
<div class="radio-inline">
<label><input type="radio" name="type" value="student" id="type_student" accesskey="s" tabindex="3" required>Student</label>
</div>
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" name="email" class="form-control" id="email" placeholder="[email protected]" accesskey="e" tabindex="4">
<p id="email_help" class="form-text text-muted" style="color: #34495E;">
We will send an email to this address for acknowledgement if a new user has been created successfully.
</p>
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox" name="random" id="random" accesskey="r" tabindex="5" onchange="generate_random_password();">
<b>Generate random password</b>
</label>
</div>
</div>
<div id="manual-password-group" class="">
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" class="form-control" id="password" placeholder="Type password" accesskey="p" tabindex="6" required>
</div>
<div class="form-group">
<label for="confirm">Confirm password again</label>
<input type="password" name="confirm" class="form-control" id="confirm" placeholder="Type password again" accesskey="c" tabindex="7" required>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success">Submit</button>
<button type="button" class="btn btn-primary" onclick="window.location.href='index.php'">Cancel</button>
</div>
</form>
</div>
</div>
<br><br><br><br>
<?php
require_once 'footer.php';
?>
</body>
</html>