-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
240 lines (197 loc) · 9.76 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
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
231
232
233
234
235
236
237
238
239
240
<?php
require "assets/db.php";
require "assets/varnames.php";
require 'assets/sharedComponents.php';
$components = new SharedComponents();
session_start();
$loggedin = false;
// Check if the user is already logged in, if yes then redirect him to welcome page
if (isset($_SESSION["blunt_blog_user_loggedin_"])){
header("location: index.php");
exit;
}
// Define variables and initialize with empty values
$username = $email = $password = $confrimpassword = "";
$username_err = $email_err = $password_err = $confrimpassword_err = $agreement_err = $agreed ="";
$_SESSION["main_err"] = $_SESSION["username"] = $_SESSION["email"] = $_SESSION["password"] = "";
// Processing form data when form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Check if username is empty
if (empty(trim($_POST["username"]))) {
$username_err = "Enter your Username.";
}
else {
$username = trim($_POST["username"]);
$_SESSION["username"] = $username;
}
// Check if email is empty
if (empty(trim($_POST["email"]))) {
$email_err = "Enter your Email.";
}
else {
$email = trim($_POST["email"]);
$_SESSION["email"] = $email;
}
// Check if all password is empty
if (empty(trim($_POST["password"]))) {
$password_err = "Enter your Password.";
}
else if (empty(trim($_POST["confrimpassword"]))) {
$_SESSION["password"] = trim($_POST["password"]);
$confrimpassword_err = "Confrim your Password.";
}
else if ($_POST["confrimpassword"] != $_POST["password"]){
$confrimpassword_err = "Passwords does not Match.";
}
else {
$password = trim($_POST["password"]);
}
// Check if agreement is checked
if (isset($_POST["terms"]) == "check")
{
$agreed = "agreed";
// Validate credentials
if (empty($username_err) && empty($email_err) && empty($password_err) && empty($confrimpassword_err)) {
// Prepare a select statement
$sql = "SELECT * FROM users WHERE email = :email";
if ($stmt = $pdo->prepare($sql)) {
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":email", $param_email, PDO::PARAM_STR);
// Set parameters
$param_email = trim($_POST["email"]);
// Attempt to execute the prepared statement
if ($stmt->execute()) {
// Check if username exists, if yes then verify password
if ($stmt->rowCount() == 1) {
// Display an error message if email exist
$email_err = "There is an account with that Email.";
}
else {
$set = 'EYO1BLUNT2AKAK3';
$code = substr(str_shuffle($set), 0, 12);
//hash password
$hashpassword = password_hash($password, PASSWORD_DEFAULT);
$data = array(
"email" => $components->test_input($_POST["email"]),
"username" => $components->test_input($_POST["username"]),
"password" => $components->test_input($hashpassword),
"code" => $components->test_input($code)
);
// Get keys string from data array
$columns = $components->implodeArray(array_keys($data));
// Get values string from data array with prefix (:) added
$prefixed_array = preg_filter('/^/', ':', array_keys($data));
$values = $components->implodeArray($prefixed_array);
try {
$sql = "INSERT INTO users ($columns) VALUES ($values); SELECT LAST_INSERT_ID();";
$stmt = $pdo->prepare($sql);
$stmt->execute($data);
$userid = $pdo->lastInsertId();
require 'assets/sendmail.php';
$model = new send_Mail();
$mailresult = $model->sendUsersMail($_POST["email"], $password, $_POST["username"], $code, $userid);
json_encode($result);
if($mailresult["response"] == true)
{
header("Location: login.php?admsg=active");
exit;
}
else
$_SESSION["main_err"] = $mailresult["message"];
} catch (PDOException $error) {
$_SESSION["main_err"] = "Error: ".$error;
}
}
} else {
$_SESSION["main_err"] = "Oops! Something went wrong. Please try again later.";
}
// Close statement
unset($stmt);
}
}
}
else
{
$agreement_err = "Our Terms & Agreement has not been accepted.";
}
// Close connection
unset($pdo);
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Meta -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- favicon -->
<link rel="icon" sizes="16x16" href="assets/img/favicon.png">
<!-- Title -->
<title> Signup </title>
<!-- CSS Plugins -->
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/owl.carousel.css">
<link rel="stylesheet" href="assets/css/line-awesome.min.css">
<link rel="stylesheet" href="assets/css/fontawesome.css">
<!-- main style -->
<link rel="stylesheet" href="assets/css/style.css">
<link rel="stylesheet" href="assets/css/custom.css">
<?php require "includes/metatags.php"; ?>
</head>
<body>
<?php require "includes/navbar.php"; ?>
<!--Login-->
<section class="container" style="margin-bottom:20px">
<br>
<div class="section-heading">
<div class="row">
<div class="col-lg-6 col-md-8 m-auto">
<div class="login-content">
<h4>Sign up</h4>
<!--form-->
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" class="sign-form widget-form" method="POST">
<p style="color:darkred;">
<?= (!empty($_SESSION["main_err"])) ? $_SESSION["main_err"] : ''; ?>
</p>
<hr>
<div class="form-group">
<input type="text" class="form-control <?= (!empty($username_err)) ? 'is-invalid' : ''; ?>" placeholder="Username*" name="username" value="<?= (!empty($_SESSION["username"])) ? $_SESSION["username"] : ''; ?>">
<span class="invalid-feedback"><?= $username_err; ?></span>
</div>
<div class="form-group">
<input type="email" class="form-control <?= (!empty($email_err)) ? 'is-invalid' : ''; ?>" placeholder="Email Address*" name="email" value="<?= (!empty($_SESSION["email"])) ? $_SESSION["email"] : ''; ?>">
<span class="invalid-feedback"><?= $email_err; ?></span>
</div>
<div class="form-group">
<input type="password" class="form-control <?= (!empty($password_err)) ? 'is-invalid' : ''; ?>" placeholder="Password*" name="password" value="<?= (!empty($_SESSION["password"])) ? $_SESSION["password"] : ''; ?>">
<span class="invalid-feedback"><?= $password_err; ?></span>
</div>
<div class="form-group">
<input type="password" class="form-control <?= (!empty($confrimpassword_err)) ? 'is-invalid' : ''; ?>" placeholder="Confrim Password*" name="confrimpassword" value="">
<span class="invalid-feedback"><?= $confrimpassword_err; ?></span>
</div>
<div class="sign-controls form-group">
<div class="custom-control custom-checkbox">
<input type="checkbox" name="terms" class="custom-control-input <?= (!empty($agreement_err)) ? 'is-invalid' : ''; ?>" id="rememberMe" value="check" <?= (!empty($agreed)) ? 'checked' : ''; ?>>
<label class="custom-control-label" for="rememberMe">
I Agree to Blunt <a href="privacy.php" class="btn-link">terms & conditions</a>
</label>
<span class="invalid-feedback"><?= $agreement_err; ?></span>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn-custom">Sign Up</button>
</div>
<p class="form-group text-center">Already have an account? <a href="login.php" class="btn-link">Login</a> </p>
</form>
<!--/-->
</div>
</div>
</div>
</div>
</section>
<?php
include 'includes/footer.php';
include 'includes/scripts.php';
?>