forked from Vimall03/Alimento
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_signup.php
230 lines (186 loc) · 9.41 KB
/
user_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
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
230
<?php
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
$showAlert = false;
$showError = false;
if($_SERVER["REQUEST_METHOD"]=="POST"){
include 'partials/_dbconnect.php';
$name= $_POST["name"];
$email= $_POST["email"];
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
$password = $_POST["password"];
$cpassword = $_POST["cpassword"];
if ($email == '' || $password == '') {
$showError = "Enter valid Email/password";
}
else{
$existSql = "SELECT * FROM `users` WHERE email = '$email' ";
$result = mysqli_query($conn, $existSql);
$numExistRows = mysqli_num_rows($result);
if ($numExistRows > 0){
$showError = "Email already registered. Try logging in.";
}
else {
if ($password == $cpassword){
$hash = password_hash($password, PASSWORD_DEFAULT);
$sql = "INSERT INTO `users` ( `name`, `email`, `password`, `date`, `account_status`, `resetcode`)
VALUES ( '$name', '$email', '$hash', current_timestamp(), 'Not Verified', '0');";
$result = mysqli_query($conn, $sql);
if($result){
$otp = random_int(10000000, 99999999);
$hashotp = password_hash($otp, PASSWORD_DEFAULT);
$sql = "UPDATE `users`
SET `resetcode` = '$hashotp'
WHERE `email` = '$email';";
$result = mysqli_query($conn, $sql);
if($result){
$showAlert = true;
}
// PHP mailer
require 'phpmailer/Exception.php';
require 'phpmailer/PHPMailer.php';
require 'phpmailer/SMTP.php';
//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
//$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = '[email protected]'; //SMTP username
$mail->Password = '#'; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail->setFrom('[email protected]', 'ETIFFY');
$mail->addAddress($email); //Add a recipient
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Verification code from homemade';
$mail->Body = '<h1>'.$email.' </h1><br><h1>'.$otp.' </h1>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
//PHP mailer
session_start();
$_SESSION['email'] = $email;
header("location: email_verify.php");
$showAlert = true;
}
}
else {
$showError = "Passwords do not match.";
}
}
}
}
else {
$showError = "The email address is not valid.";
}
}
?>
<!-- Source html-->
<!DOCTYPE html>
<html lang="en">
<head>
<!-- bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<!-- Google Fonts (aBeeZee) -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=ABeeZee&display=swap" rel="stylesheet">
<style>
@import url('https://fonts.googleapis.com/css2?family=ABeeZee&display=swap');
</style>
<!-- css link -->
<link rel="stylesheet" href="main.css">
<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>AfterEdit • Signup</title>
<link rel="icon" type="image/png" href="css/favicon.png">
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous">
</script>
<?php
if ($showAlert) {
echo ' <div class="alert alert-success alert-dismissible fade show" role="alert">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check-circle-fill" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"/>
</svg>
<strong>Congratulations!</strong> Your account has been created. You can now <a class="col-lg-10 fs-4 text-center desc py-2 text-dark text-decoration-none" href="login.php"><button type="button"
class="btn btn-dark me-2">Login</button></a>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
';
}
if ($showError) {
echo ' <div class="alert alert-danger alert-dismissible fade show" role="alert">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-exclamation-triangle-fill" viewBox="0 0 16 16">
<path d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"/>
</svg>
<strong>Error. </strong> '.$showError.'
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
';
} ?>
<section class="login-signup">
<div class="login-signup__form-container login-signup__big">
<div class="login-signup__back-button u-show-after-tab-port">
<img src="images/favicons/back_50px-red.png"alt="Back Button">
<a href="index.html">Back</a>
</div>
<div class="login-signup__logo">
<a href="index.html">
<img src="images/logo/Logo.png" alt="Logo">
</a>
</div>
<div class="login-signup__form-content">
<h3 class="login-signup__form-heading u-margin-bottom-small">Hello, Friend</h3>
<h5 class="login-signup__form-subheading">Create your account to end the hunder</h5>
<form class="login-signup-form u-margin-top-small" action="user_signup.php" method="post">
<div class="login-signup-form__input-group login-signup-form__input-group--full">
<input type="text" name="name" class="login-signup-form__input" id="name" placeholder="Your good name">
</div>
<div class="login-signup-form__input-group login-signup-form__input-group--full">
<input type="email" name="email" class="login-signup-form__input" id="email-id" placeholder="[email protected]">
</div>
<div class="login-signup-form__input-group login-signup-form__input-group--half">
<input type="password" name="password" class="login-signup-form__input" id="password" placeholder=".......">
<input type="password" name="cpassword" class="login-signup-form__input" id="password" placeholder=".......">
</div>
<button class="login-signup-form__submit u-margin-top-extra-large" type="submit" id="submit-login">Sign Up</button>
</form>
</div>
<div class="login-signup__text-content">
<p class="paragraph paragraph text-algin-center">Already a member?</p>
<a href="user_login.php" class="login-signup__alt-link">Sign In</a>
</div>
</div>
<div class="login-signup__message-container login-signup__small">
<div class="login-signup__back-button">
<img src="images/favicons/back_50px.png"alt="Back Button">
<a href="index.html" style="color:#fff">Back</p>
</div>
<div class="login-signup__message-content">
<h3 class="login-signup__message-heading u-margin-bottom-medium">Welcome Back</h3>
<p class="login-signup__message-para">Glad to see you back here. We are waiting to kill your hunger with our delicious dabbas. Sign in to get delicious food.</p>
<br><br>
<button class="login-signup__button u-margin-top-extra-large" style="display:block; margin: 0 auto;">
<a href="user_login.php">Sign In</a>
</button>
</div>
</div>
</section>
</body>
</html>