-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignUp.php
135 lines (104 loc) · 4.52 KB
/
signUp.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sign Up</title>
<link rel="stylesheet" href="css/signUp.css">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;500;600&display=swap" rel="stylesheet">
<!--Stylesheet-->
<?php
require('templates/header.inc.php');
?>
</head>
<body style="background-color: #080710">
<div class="background">
<div class="shape"></div>
<div class="shape"></div>
</div>
<form method="post" style="height: auto">
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$password = $_POST['password'];
$confPassword = $_POST['confPassword'];
$email = $_POST['email'];
$username = $_POST['username'];
$role = $_POST['role'];
include('database/db_connection.php');
try {
$UserExists = $conn->prepare("select username from php_db.user where username = :username");
$UserExists->bindParam(':username', $username);
$UserExists->execute();
$EmailExists = $conn->prepare('select email from php_db.user where email = :email');
$EmailExists->bindParam(':email', $email);
$EmailExists->execute();
} catch (PDOException $e) {
echo 'Something bad happened';
}
if ($password != $confPassword) {
echo "<p style='color: red; font-size: small; text-align: center' >
Oops! Password did not match! Try again.
</p> ";
} elseif ($UserExists->rowCount() > 0) {
echo "<p style='color: red; font-size: small; text-align: center' >
The username already exist.
</p> ";
} elseif ($EmailExists->rowCount() > 0) {
echo "<p style='color: red; font-size: small; text-align: center' >
The email already exist.
</p> ";
} else {
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
try {
$stm = $conn->prepare("insert into php_db.user(username, email, role, password)
values (:username, :email, :role, :hashedPassword)");
$stm->bindParam(':username', $username);
$stm->bindParam(':email', $email);
$stm->bindParam(':role', $role);
$stm->bindParam(':hashedPassword', $hashedPassword);
$stm->execute();
echo " <h3> The sign up was successful now you can log in </h3>";
$conn = null;
exit();
} catch (PDOException $e) {
echo 'Something bad happened';
}
}
}
?>
<h3>Sign Up Here</h3>
<label for="email">Email</label>
<input type="email" name="email" placeholder="email" id="email" required
value="<?php if (isset($email)) {
echo $email;
} ?>">
<label for="username">Username</label>
<input type="text" name="username" placeholder="username" id="username" required
value="<?php if (isset($username)) {
echo $username;
} ?>">
<label for="password" style="font-size: small; color: #ff512f">Password: The password mast contain one upper case
and one lower case
character
a symbol and a number. The length mast be more than 10 characters.</label>
<input type="password" name="password" placeholder="Password" id="password" required minlength="10"
pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*_=+-]).{8,24}$">
<label for="confPassword">Confirm Password</label>
<input type="password" name="confPassword" placeholder="Confirm Password" id="confPassword" required minlength="10"
pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*_=+-]).{8,24}$">
<label for="role">Role:</label>
<select type="text" id="role" name="role" required>
<option value="" disabled selected hidden>Please choose a Role</option>
<option value="Student" <?php if (isset($role) and $role = "Student") {
echo 'selected';
} ?>>Student
</option>
<option value="Teacher" <?php if (isset($role) and $role = "Teacher") {
echo 'selected';
} ?>>Teacher
</option>
</select>
<button>Sign Up</button>
</form>
</body>
</html>