-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
executable file
·108 lines (91 loc) · 3.01 KB
/
register.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
require_once 'includes/register-login.php';
require_once 'includes/database.php';
session_start();
if (isset($_SESSION['user_id'])) {
header("Location: /app");
exit;
}
$db = new Database();
$user_error_message = "";
if (isset($_POST['register'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
if (empty($name) || empty($email) || empty($password)) {
$user_error_message = "All fields are required.";
} else {
$result = registerUser($name, $email, $password, $db);
if ($result === true) {
header("Location: /app");
exit;
} else {
$user_error_message = $result;
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flashify | Sign Up</title>
<link rel="icon" type="image/x-icon" href="/assets/flash-card.png">
<link rel="stylesheet" href="/styles/register-login.css">
</head>
<body>
<main>
<img src="assets/flash-card.png">
<h2>Welcome to Flashify!</h2>
<p>Already have an account? <a href="login.php">Sign In</a></p>
<span class="error">
<?php
echo $user_error_message;
?>
</span>
<form method="POST">
<label for="name">Full Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your name" required>
<label for="email">Email Address:</label>
<input type="email" id="email" name="email" placeholder="Enter your email" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter your password"
pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}"
title="Password must be at least 8 characters long, include at least one number, one uppercase letter, and one lowercase letter."
required>
<label for="confirm-password">Confirm Password:</label>
<input type="password" id="confirm-password" name="confirm-password" placeholder="Confirm your password" required>
<button type="submit" name="register">Sign Up</button>
</form>
</main>
<div class="bubbles">
<div class="bubble"></div>
<div class="bubble"></div>
<div class="bubble"></div>
<div class="bubble"></div>
<div class="bubble"></div>
<div class="bubble"></div>
<div class="bubble"></div>
<div class="bubble"></div>
<div class="bubble"></div>
<div class="bubble"></div>
</div>
<script>
const confirmPassword = document.querySelector("#confirm-password");
const password = document.querySelector("#password");
confirmPassword.addEventListener("input", () => {
if (password.value != confirmPassword.value) {
confirmPassword.setCustomValidity("Passwords don't match");
} else {
confirmPassword.setCustomValidity("");
}
});
document.querySelector("button").addEventListener("submit", (e) => {
if (!confirmPassword.checkValidity()) {
e.preventDefault();
}
});
</script>
</body>
</html>