forked from Anderson-Juhasc/bitcoin-point-of-sale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
users-create.php
96 lines (81 loc) · 3.37 KB
/
users-create.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
<?php include 'partials/header.php'; ?>
<?php
if ($_SESSION['auth'] != 1) {
unset($_SESSION['auth']);
header('Location: index.php');
exit();
}
?>
<?php if (isset($_POST["user-create"])) : ?>
<?php
$user_name = $_POST['user-name'];
$user_type = $_POST['user-type'];
$user_password = $_POST['user-password'];
$user_repassword = $_POST['user-repassword'];
$db = new Db();
$user = $db->query("SELECT * FROM users WHERE user_name = '$user_name' LIMIT 1");
if (count($user) == 0) {
if ($user_password == $user_repassword) {
$user_password = md5($user_password);
$db->query("INSERT INTO
users(user_type, user_name, user_password)
VALUES('$user_type', '$user_name', '$user_password')"
);
}
}
header('Location: users.php');
?>
<?php else : ?>
<!-- .wrapper -->
<div class="wrapper">
<!-- .page -->
<div class="page">
<!-- .page__head -->
<header class="page__head">
<h2 class="page__title">New User</h2>
</header>
<!-- /.page__head -->
<!-- .page__body -->
<div class="page__body">
<!-- .user-create -->
<div class="user-create">
<form action="<?php $_SERVER["PHP_SELF"] ?>" method="POST" autocomplete="off">
<!-- .fields -->
<ul class="fields">
<li>
<label for="" class="fields__label">Username:</label>
<input id="" class="fields__input input input--full" name="user-name" required type="text">
</li>
<li>
<label for="" class="fields__label">Password:</label>
<input id="" class="fields__input input input--full" name="user-password" required type="text">
</li>
<li>
<label for="" class="fields__label">Confirm password:</label>
<input id="" class="fields__input input input--full" name="user-repassword" required type="text">
</li>
<li>
<label for="" class="fields__label">Permission:</label>
<select id="" name="user-type">
<option value="admin">Admin</option>
<option value="user">User</option>
</select>
</li>
</ul>
<!-- /.fields -->
<!-- .fields-action -->
<div class="fields-action">
<button type="submit" name="user-create" class="fields-action__btn btn btn--secondary">Create user</button>
</div>
<!-- /.fields-action -->
</form>
</div>
<!-- /.user-create -->
</div>
<!-- /.page__body -->
</div>
<!-- /.page -->
</div>
<!-- /.wrapper -->
<?php endif; ?>
<?php include 'partials/footer.php'; ?>