-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsign_up.php
229 lines (204 loc) · 11.4 KB
/
sign_up.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
$rootPath = '/ananas/';
require_once './database/DB.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require './PHPMailer/src/Exception.php';
require './PHPMailer/src/PHPMailer.php';
require './PHPMailer/src/SMTP.php';
include_once './helper/sendMail.php';
?>
<?php
require("./validate.php");
$status = "";
$name = '';
$email = '';
$phone = '';
$address = '';
$password = '';
$re_password = '';
if (isset($_POST['register'])) {
$is_validated = true;
$errorName = $errorEmail = $errorPhone = $errorPassword = $errorRePassword = "";
$name = mysqli_real_escape_string($conn, $_POST['name']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$phone = mysqli_real_escape_string($conn, $_POST['phone']);
$address = mysqli_real_escape_string($conn, $_POST['address']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$re_password = mysqli_real_escape_string($conn, $_POST['repeatPassword']);
if($name == "") {
$is_validated = false;
$errorName = "Name không được để trống.";
}
if (checkEmailExist($email) != ""){
$is_validated = false;
$errorEmail = checkEmailExist($email);
}
if (validateEmail($email) != "") {
$is_validated = false;
$errorEmail = validateEmail($email);
}
if (validatePassword($password) != "") {
$is_validated = false;
$errorPassword = validatePassword($password);
}
if (checkPassword($password, $re_password) != "") {
$is_validated = false;
$errorRePassword = "Nhập mật khẩu lần 2 không khớp.";
}
if ($is_validated) {
$hashPassword = password_hash($password, PASSWORD_DEFAULT);
$verifyCode = substr(number_format(time() * rand(), 0, '', ''), 0, 6);
// $verifyCode = isset($_SESSION['generated_otp']) ? $_SESSION['generated_otp'] : '';
$sql = "INSERT INTO user (name, email, phone, address, password, verify_code)
VALUES ('$name', '$email', '$phone', '$address', '$hashPassword', '$verifyCode')";
if ($conn->query($sql) === TRUE) {
// send mail
$receiver = [
'name' => $name,
'email' => $email,
'password' => $password,
];
verifyEmail($mail, $receiver, $verifyCode);
header("Location: ./auth/register.php?email=$email");
} else {
echo "Error: ". $conn->error;
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Đăng ký - Ananas</title>
<link rel="stylesheet" href="<?= $rootPath ?>/public/css/showPassword.css">
<link rel="stylesheet" href="https://site-assets.fontawesome.com/releases/v6.1.2/css/all.css">
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<link rel="stylesheet" href="./public/css/base.css">
<link rel="icon" type="image/x-icon" href="https://brademar.com/wp-content/uploads/2022/09/Ananas-Logo-PNG-1.png">
<!-- <link rel="stylesheet" href="./public/css/home.css"> -->
</head>
<body>
<?php
require './includes/header.php';
?>
<section style="background-color: #eee;" class="py-3">
<div class="container h-100">
<div class="row d-flex justify-content-center align-items-center h-100">
<div class="col-lg-12 col-xl-11">
<div class="card text-black" style="border-radius: 25px;">
<div class="card-body p-md-5">
<div class="row justify-content-center">
<div class="col-md-10 col-lg-6 col-xl-5 order-2 order-lg-1">
<p class="text-center h1 fw-bold mb-5 mx-1 mx-md-4 mt-4">Sign up</p>
<form class="mx-1 mx-md-4" method="post">
<div class="d-flex flex-row align-items-center mb-4">
<i class="fas fa-user fa-lg me-3 fa-fw"></i>
<div class="form-outline flex-fill mb-0 ">
<input type="text" id="nameInput" class="form-control" name="name"
placeholder="Your name" />
<?php if (isset($errorName)) : ?>
<span class="help text-danger form-text mb-2" id="nameHelp">
<?php echo $errorName; ?>
<?php endif; ?>
</span>
</div>
</div>
<div class="d-flex flex-row align-items-center mb-4">
<i class="fas fa-envelope fa-lg me-3 fa-fw"></i>
<div class="form-outline flex-fill mb-0">
<input type="email" id="emailInput" class="form-control" name="email"
placeholder="Your email" />
<?php if (isset($errorEmail)) : ?>
<span class="help text-danger form-text mb-2" id="emailHelp">
<?php echo $errorEmail; ?>
<?php endif; ?>
</span>
</div>
</div>
<div class="d-flex flex-row align-items-center mb-4">
<i class="fas fa-lock fa-lg me-3 fa-fw"></i>
<div class="form-outline flex-fill mb-0">
<input type="password" id="passwordInput" name="password"
class="form-control" placeholder="Your password" />
<div style="max-width: 300px;">
<span class="help text-danger form-text mb-2" id="passwordHelp">
<?php if (isset($errorPassword)) : ?>
<?php echo $errorPassword; ?>
<?php endif; ?>
</span>
</div>
</div>
</div>
<div class="d-flex flex-row align-items-center mb-4">
<i class="fas fa-key fa-lg me-3 fa-fw"></i>
<div class="form-outline flex-fill mb-0">
<input type="password" id="repeatPasswordInput" name="repeatPassword"
class="form-control" placeholder="Repeat your password" />
<?php if (isset($errorRePassword)) : ?>
<span class="help text-danger form-text mb-2" id="repeatPasswordHelp">
<?php echo $errorRePassword; ?>
<?php endif; ?>
</span>
</div>
</div>
<div class="d-flex flex-row align-items-center mb-4">
<i class="fas fa-location-dot fa-lg me-3 fa-fw"></i>
<div class="form-outline flex-fill mb-0">
<input type="text" id="addressInput" class="form-control" name="address" value="<?php echo $address?>"
placeholder="Your address" />
</div>
</div>
<div class="d-flex flex-row align-items-center mb-4">
<i class="fas fa-phone fa-lg me-3 fa-fw"></i>
<div class="form-outline flex-fill mb-0">
<input type="number" id="phoneInput" class="form-control" name="phone" value="<?php echo $phone?>"
placeholder="Your phone number" />
</div>
</div>
<div class="d-flex justify-content-center mx-4 mb-3 mb-lg-4">
<button name="register" type="submit"
class="btn btn-primary btn-lg">Register</button>
</div>
</form>
</div>
<div class="col-md-10 col-lg-6 col-xl-7 d-flex align-items-center order-1 order-lg-2">
<img src="./assets/signup-image.png" class="img-fluid" alt="Sample image">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- JavaScript Bundle with Popper -->
<!-- <script src="./public/javascripts/validate.js"></script> -->
<script src="<?= $rootPath ?>/public/javascripts/showPassword.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js"
integrity="sha512-STof4xm1wgkfm7heWqFJVn58Hm3EtS31XFaagaa8VMReCXAkQnJZ+jEy8PCC/iT18dFy95WcExNHFTqLyp72eQ=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous">
</script>
<script src="./public/javascripts/loadCartHeader.js"></script>
<script>
$(document).ready(function() {
loadCartAjax();
$(window).scroll(function() {
if ($(this).scrollTop() > 114) {
$("#navbar-top").addClass('fix-nav')
} else {
$("#navbar-top").removeClass('fix-nav')
}
})
});
</script>
<script src="./public/javascripts/liveSearch.js"></script>
</body>
</html>