-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuser_signup.php
More file actions
159 lines (148 loc) · 6.21 KB
/
user_signup.php
File metadata and controls
159 lines (148 loc) · 6.21 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
include("includes/connection.php");
include("includes/header.php");
$message = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$key = trim($_POST['secret_key']);
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$password = trim($_POST['password']);
// Check if secret key is valid
$stmt = mysqli_prepare($conn, "SELECT shop_id FROM secret_keys WHERE secret_key = ? AND expires_at > NOW()");
mysqli_stmt_bind_param($stmt, "s", $key);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
if (mysqli_stmt_num_rows($stmt) === 1) {
mysqli_stmt_bind_result($stmt, $shop_id);
mysqli_stmt_fetch($stmt);
// Check if email already exists
$check_email = mysqli_prepare($conn, "SELECT id FROM users WHERE email = ?");
mysqli_stmt_bind_param($check_email, "s", $email);
mysqli_stmt_execute($check_email);
mysqli_stmt_store_result($check_email);
if (mysqli_stmt_num_rows($check_email) > 0) {
$message = "This email is already registered. Please login or use another email.";
} else {
$_SESSION['name'] = $name;
$_SESSION['email'] = $email;
$_SESSION['password'] = password_hash($password, PASSWORD_DEFAULT);
$_SESSION['shop_id'] = $shop_id;
header("Location: user_mail_test.php");
exit();
}
} else {
$message = "Invalid or expired secret key.";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>User Signup</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/css2?family=Comfortaa:[email protected]&family=Dosis:[email protected]&family=IBM+Plex+Mono:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700&family=Inspiration&family=Italiana&family=Montserrat:ital,wght@0,100..900;1,100..900&family=Playwrite+IN:[email protected]&family=Poiret+One&family=Rubik:ital,wght@0,300..900;1,300..900&display=swap" rel="stylesheet">
<style>
body {
background:rgba(202, 144, 134, 0.7);
min-height: 100vh;
font-family:Rubik;
}
.container{
background:rgba(202, 93, 74, 0.4);
padding: 40px;
border-radius: 15px;
box-shadow: 0 0 30px rgba(0,0,0,0.1);
width: 100%;
max-width: 400px;
margin: 0 auto;
margin-top:50px;
}
</style>
</head>
<body>
<div class="container">
<h2 class="mb-4 text-center text-dark">User Signup</h2>
<?php if ($message): ?>
<div class="alert alert-warning text-center" style="color: #111; background-color: #e9ecef; border-color: #bfc1c2;">
<?= htmlspecialchars($message) ?>
</div>
<?php endif; ?>
<form method="post" action="" onsubmit="return validateUserSignup();">
<div class="mb-3">
<label class="form-label">Secret Key</label>
<input type="text" name="secret_key" id="secret_key" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Name</label>
<input type="text" name="name" id="name" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Email</label>
<input type="email" name="email" id="email" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Password</label>
<input type="password" name="password" id="password" class="form-control" required>
</div>
<div id="formError" class="alert alert-danger text-center" style="color: #111; background-color: #e9ecef; border-color: #bfc1c2; display: none;"></div>
<button type="submit" class="btn" style="background-color:rgba(202, 93, 74, 0.9)">Send OTP</button>
<br><br>
<div class="text-center">
<small>Already have an account? <a href="login.php" style="color:black">Login</a></small>
</div>
</form>
</div>
<script>
function validateUserSignup() {
var key = document.getElementById('secret_key').value.trim();
var name = document.getElementById('name').value.trim();
var email = document.getElementById('email').value.trim();
var password = document.getElementById('password').value.trim();
var formError = document.getElementById('formError');
formError.style.display = 'none';
formError.textContent = '';
if (!key || !name || !email || !password) {
formError.textContent = "All fields are required.";
formError.style.display = 'block';
return false;
}
var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailPattern.test(email)) {
formError.textContent = "Please enter a valid email address.";
formError.style.display = 'block';
return false;
}
if (password.length < 6) {
formError.textContent = "Password must be at least 6 characters.";
formError.style.display = 'block';
return false;
}
var upperCasePattern = /[A-Z]/;
var lowerCasePattern = /[a-z]/;
var numberPattern = /[0-9]/;
var specialCharPattern = /[!@#$%^&*(),.?":{}|<>]/;
if (!upperCasePattern.test(password)) {
formError.textContent = "Password must include at least one uppercase letter.";
formError.style.display = 'block';
return false;
}
if (!lowerCasePattern.test(password)) {
formError.textContent = "Password must include at least one lowercase letter.";
formError.style.display = 'block';
return false;
}
if (!numberPattern.test(password)) {
formError.textContent = "Password must include at least one number.";
formError.style.display = 'block';
return false;
}
if (!specialCharPattern.test(password)) {
formError.textContent = "Password must include at least one special character.";
formError.style.display = 'block';
return false;
}
return true;
}
</script>
</body>
</html>