-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_user.php
213 lines (189 loc) · 11.1 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
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
<!DOCTYPE html>
<html lang="en" class="gr__preview_uideck_com">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" type="text/css" href="./assets/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="./assets/css/line-icons.css">
<link rel="stylesheet" type="text/css" href="./assets/css/slicknav.css">
<link rel="stylesheet" type="text/css" href="./assets/css/nivo-lightbox.css">
<link rel="stylesheet" type="text/css" href="./assets/css/animate.css">
<link rel="stylesheet" type="text/css" href="./assets/css/owl.carousel.css">
<link rel="stylesheet" type="text/css" href="./assets/css/main.css">
<link rel="stylesheet" type="text/css" href="./assets/css/responsive.css">
<link rel="stylesheet" id="colors" href="./assets/css/green.css" type="text/css">
</head>
<?php
session_start();
include "connect.php";
if (!isset($_SESSION['key'])) {
header("Location: ./login.php");
} elseif (isset($_POST['item_form'])) {
$username = pg_escape_string($connection, $_POST['username']);
$fullname = pg_escape_string($connection, $_POST['fullname']);
$email = pg_escape_string($connection, $_POST['email']);
$phonenumber = (int)pg_escape_string($connection, $_POST['phonenumber']);
$role = $_POST['role'];
$password = pg_escape_string($connection, $_POST['password']);
$username_query = "SELECT username FROM account where username='" . $username . "'";
$email_query = "SELECT email FROM account where email='" . $email . "'";
$username_result = pg_query($connection, $username_query);
$username_num_results = pg_num_rows($username_result);
$email_result = pg_query($connection, $email_query);
$email_num_results = pg_num_rows($email_result);
if ($username_num_results >= 1) {
$display = "<div class='alert alert-danger text-center'><strong>The username (" . $username . ") has already been taken</strong></div>";
unset($username);
} elseif ($email_num_results >= 1) {
$display = "<div class='alert alert-danger text-center'><strong>The email (" . $email . ") has already been taken</strong></div>";
unset($username);
} else {
$signup_query = "insert into account( username, password, role, full_name, phone, email) values('" . $username . "','" . hash(sha256, $password) . "','". $role . "','" . $fullname . "','" . $phonenumber . "', '" . $email . "')";
$signup_result = pg_query($connection, $signup_query);
if ($signup_result) {
// Sign up successful
$display = "<div class='alert alert-success text-center'><strong>Account Created Successfully!</strong></div>";
header("refresh:2; url=./view_users.php");
} else {
$display = "<div class='alert alert-danger text-center'><strong>Something seems to be wrong, please try later</strong></div>";
unset($username);
}
}
}
?>
<div class="page-header" style="background: url(assets/img/banner1.jpg);">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="breadcrumb-wrapper">
<h2 class="product-title">Create User</h2>
<ol class="breadcrumb">
<li><a href="admin_dashboard.php#">Home /</a></li>
<li class="current">Create User</li>
</ol>
</div>
</div>
</div>
</div>
</div>
<?php echo $display ?>
<div id="content" class="section-padding">
<div class="container">
<div class="row">
<?php
include "admin_sidebar.php";
?>
<div class="col-sm-12 col-md-8 col-lg-9">
<div class="row page-content">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-7">
<div class="inner-box">
<?php echo $success_message; ?>
<div class="dashboard-box">
<h2 class="dashbord-title">Create a User</h2>
</div>
<div class="dashboard-wrapper">
<form name='item_form' class="login-form" enctype='multipart/form-data' method="post" >
<div class="form-group has-feedback">
<div class="form-group">
<div class="input-icon">
<label class="control-label">Username</label>
<input type="text" id="username" name="username" class="form-control"
placeholder="Username" required>
</div>
<div class="help-block with-errors">
<?php echo "<span style='color:red;'>$username_message</span>" ?>
</div>
</div>
<div class="form-group">
<div class="input-icon">
<label class="control-label">Full Name</label>
<input type="text" id="full_name" name="fullname" class="form-control"
placeholder="Full Name" required>
</div>
<div class="help-block with-errors">
</div>
</div>
<div class="form-group">
<div class="input-icon">
<label class="control-label">Email Address</label>
<input type="email" id="email" name="email" class="form-control"
placeholder="Email Address" data-error="Bruh, that email address is invalid"
required>
</div>
<div class="help-block with-errors">
<?php echo "<span style='color:red;'>$email_message</span>" ?>
</div>
</div>
<div class="form-group">
<div class="input-icon">
<label class="control-label">Phone Number</label>
<input type="text" pattern="\d{8}" id="phonenumber" name="phonenumber"
class="form-control" placeholder="Phone Number" required>
</div>
<div class="help-block with-errors">
</div>
</div>
<div class="form-group mb-3 tg-inputwithicon">
<label class="control-label">Role</label>
<div class="tg-select form-control">
<select name="role" required="">
<option value="" hidden disabled selected>Select Role</option>
<option value="user">User</option>
<option value="admin">Admin</option>
</select>
</div>
</div>
<div class="form-group">
<div class="input-icon">
<label class="control-label">Password</label>
<input type="password" class="form-control" id="password" name="password"
placeholder="Password" required>
</div>
<div class="help-block with-errors">
</div>
</div>
<div class="form-group">
<div class="input-icon">
<label class="control-label">Confirm Password</label>
<input type="password" class="form-control" id="confirm_password"
data-match="#password" data-match-error="Whoops, these don't match"
placeholder="Retype Password" required>
</div>
<div class="help-block with-errors">
</div>
</div>
<div class="form-group mb-3">
</div>
<div class="text-center">
<button class="btn btn-common log-btn" name="item_form" type="submit">Create
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="create_user.php##" class="back-to-top" style="display: none;">
<i class="lni-chevron-up"></i>
</a>
<div id="preloader" style="display: none;">
<div class="loader" id="loader-1"></div>
</div>
<script src="./assets/js/jquery-min.js"></script>
<script src="./assets/js/popper.min.js"></script>
<script src="./assets/js/bootstrap.min.js"></script>
<script src="./assets/js/jquery.counterup.min.js"></script>
<script src="./assets/js/waypoints.min.js"></script>
<script src="./assets/js/wow.js"></script>
<script src="./assets/js/owl.carousel.min.js"></script>
<script src="./assets/js/nivo-lightbox.js"></script>
<script src="./assets/js/jquery.slicknav.js"></script>
<script src="./assets/js/main.js"></script>
<script src="./assets/js/form-validator.min.js"></script>
<script src="./assets/js/contact-form-script.min.js"></script>
<script src="./assets/js/summernote.js"></script>