-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew-user.php
108 lines (97 loc) · 3.45 KB
/
new-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
<?php
session_start();
require "class/db.php";
$db = new Database();
if ( $_SERVER["REQUEST_METHOD"] == "POST") {
$password = $_POST["password"];
$username = htmlspecialchars($_POST["username"]);
$email = $_POST["email"];
$givenname = htmlspecialchars($_POST["givenname"]);
$homeaddress = htmlspecialchars($_POST["homeaddress"]);
$surname = htmlspecialchars($_POST["surname"]);
if ( empty($password) || empty($username) || empty($givenname) ||
empty($email) || empty($surname) || empty($homeaddress)) {
$status = "Please fill in every field";
} else if ( !validEmail($email)) {
$status = "Please enter a valid email. ";
} else if (!preg_match("%^[A-Za-z0-9-_]{1,100}$%", $_POST["username"])) {
$status = "The username can only consist of letters, numbers, - and _.";
} else if(strlen($_POST["password"]) < 2) {
$status = "The password should be at least 3 charachers long.";
} else {
//Register user
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$result = $db->createUser($username, $email, $hashed_password, $givenname,
$surname, $homeaddress);
if ($result) {
// User created successfully.
$status = "Thanks for registering with $username and $homeaddress.";
} else {
$status = "Username or email already exists. ";
}
}
}
?>
<?php require("inc/header.php") ?>
<h1>Register</h1>
<div class="center-text">
<p>
<form action="" method="post">
<table class="table-register" >
<tr>
<td>
<label for="username">Username :</label>
</td>
<td>
<input type="text" name="username"/><br />
</td>
</tr>
<tr>
<td>
<label for="password">Password :</label>
</td>
<td>
<input type="password" name="password"/><br/>
</td>
</tr>
<tr>
<td>
<label for="homeaddress">Home address :</label>
</td>
<td>
<input type="text" name="homeaddress"/><br/>
</td>
</tr>
<tr>
<td>
<label for="givenname">Given name :</label>
</td>
<td>
<input type="text" name="givenname"/><br/>
</td>
</tr>
<tr>
<td>
<label for="surname">Surname :</label>
</td>
<td>
<input type="text" name="surname"/><br/>
</td>
</tr>
<tr>
<td>
<label for="email">Email :</label>
</td>
<td>
<input type="text" name="email"/><br/>
</td>
</tr>
</table>
<input type="submit" value=" Register "/><br />
<?php if ( isset($status) ) : ?>
<?= $status ;?>
<?php endif ?>
</form>
</p>
</div>
<?php require("inc/footer.php");?>