This repository has been archived by the owner on May 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreatenewuser.php
82 lines (69 loc) · 2.09 KB
/
createnewuser.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
<?php
include 'includes/header.php';
require 'includes/config.php';
?>
<body>
<?php
if($_SESSION['status'] == "admin")
{
?>
<div class="container">
<?php
$page='usermanager';
include 'includes/navbar.php';
?>
<div class="box">
<?php
echo "<h3>Create new user</h3>";
echo '<form method="POST">';?>
<div class="inputs">
<?php
echo '<input type="text" name="nick" placeholder="Nickname*"></input><br>';
echo '<select name="role">';
echo '<option value="user">User</option>';
echo '<option value="admin">Admin</option>';
echo '</select>';
echo '<input type="password" name="password" placeholder="Pasword*"></input>';
echo '<input type="text" name="email" placeholder="E-mail"></input>';
echo "<button type='submit' name='createNewUser'>Create</button>"; ?>
</div>
<?php
echo '</form>';
if(isset($_POST['createNewUser']))
{
//Validacija
$canICreateUser = true;
$nick = mysqli_real_escape_string($conn, $_POST['nick']);
$status = mysqli_real_escape_string($conn, $_POST['role']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
$suspended = 0;
$lastLogged = date("0000-00-00 00:00");
$validationErrors = CheckForValidation($nick, $status, $password, $hashedPassword, $suspended, $lastLogged);
if(empty($validationErrors))
{
CreateUser($nick, $status, $hashedPassword, $suspended, $lastLogged, $email); //UserManagement.php
echo "Account with name ".$nick." was created!<br>";
echo '<meta http-equiv="refresh" content="0; url=./usermanager" />';
}
else
{
foreach ($validationErrors as $key => $value)
{
echo "<font color='red'>".$value."</font><br>";
}
}
}?>
</div>
</div>
<?php
}
else
{
echo '<meta http-equiv="refresh" content="0; url=./errorAuthorization.shtml" />';
echo "You are not authorised to view this page!<br>";
}
?>
</body>
</html>