-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
337 lines (290 loc) · 14.6 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?php
// Include config file
require_once 'include/db_connect.php';
require_once 'functions/functions.php';
require_once ('vendor/autoload.php');
use \Statickidz\GoogleTranslate;
$content["login__err_first_name"] = "Please enter your first name.";
$content["login__err_last_name"] = "Please enter your last name.";
$content["login__err_enter_email"] = "Please enter an email.";
$content["login__err_email_taken"] = "This email is already taken.";
$content["login__err_exe_email_failed"] = "Execution email failed";
$content["login__err_prep_email_fail"] = "Prepare email failed";
$content["login__err_enter_password"] = "Please enter a password.";
$content["login__err_password_len6"] = "Password must have at least 6 characters.";
$content["login__err_confirm_password"] = "Please confirm password.";
$content["login__err_passwords_ dont_match"] = "Password did not match.";
$content["login__err_something_wrong"] = "Something went wrong. Please try again later.";
$content["login__fname"] = "first name";
$content["login__lname"] = "last name";
$content["login__email"] = "email";
// Define variables and initialize with empty values
$userFirstName = $userLastName = $type = $password = $confirmPassword = $email = "";
$userFirstNameErr = $userLastNameErr = $userTypeErr = $passwordErr = $confirmPasswordErr = $emailErr = "";
// Processing form data when form is submitted
if(isset($_POST['signup_submit'])){
// Validate first name
if(empty(trim($_POST["fname"]))){
$userFirstNameErr = "Please enter your first name.";
} else{
$userFirstName = trim($_POST['fname']);
}
//Validate last name
if(empty(trim($_POST["lname"]))){
$userLastNameErr = "Please enter your last name.";
} else{
$userLastName = trim($_POST['lname']);
}
$type = trim($_POST["user-type"]);
// Validate email
if(empty(trim($_POST["email"]))){
$emailErr = "Please enter an email.";
} else{
// Prepare a select statement
$sql = "SELECT user_email FROM users WHERE user_email = ?";
if($stmt = mysqli_prepare($conn, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $paramEmail);
$paramEmail = trim($_POST["email"]);
if(mysqli_stmt_execute($stmt)){
// store result
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 1){
$emailErr = "This email is already taken.";
} else{
$email = trim($_POST["email"]);
}
} else{
echo "Execution email failed";
}
}
else{
echo "Prepare email failed";
}
}
// Validate password
if(empty(trim($_POST['password']))){
$passwordErr = "Please enter a password.";
} elseif(strlen(trim($_POST['password'])) < 6){
$passwordErr = "Password must have at least 6 characters.";
} else{
$password = trim($_POST['password']);
}
// Validate confirm password
if(empty(trim($_POST["confirm_password"]))){
$confirmPasswordErr = 'Please confirm password.';
} else{
$confirmPassword = trim($_POST['confirm_password']);
if($password != $confirmPassword){
$confirmPasswordErr = 'Password did not match.';
}
}
// Check input errors before inserting in database
if(empty($userFirstNameErr) && empty($userLastNameErr) && empty($userTypeErr) && empty($emailErr) && empty($passwordErr) && empty($confirmPasswordErr)){
// Prepare an insert statement
$sql = "INSERT INTO users (user_id, user_first_name, user_last_name, user_email, user_type, user_password) VALUES (default,?, ?, ?, ?, ?)";
if($stmt = mysqli_prepare($conn, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "sssis", $paramFirstName, $paramLastName, $paramEmail, $paramType, $paramPassword);
// Set parameters
$paramFirstName = $userFirstName;
$paramLastName = $userLastName;
$paramEmail = $email;
$paramType = $type;
$paramPassword = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Redirect to login page
$insert_id = mysqli_stmt_insert_id($stmt);
session_start();
$_SESSION['user_id'] = $insert_id;
$_SESSION['user_email'] = $email;
setcookie("insert_id", $insert_id , time() + (86400 * 30), "/");
if($type == 1){
header("location: migrantForm.php?id=".$_SESSION['user_id']);
}else{
header("location: guideForm.php?id=".$_SESSION['user_id']);
}
} else{
echo "Something went wrong. Please try again later.";
}
}
}
}
if (isset($_COOKIE['type'])) {
unset($_COOKIE['type']);
setcookie('type', null, -1, '/');
}
if(isset($_POST["language"])){
$language = $_POST["language"];
setcookie("language", $language, time() + (60 * 5), "/");
}elseif(!isset($_COOKIE["language"])) {
$language = "en";
setcookie("language", $language, time() + (60 * 5), "/");
}else{
$language=$_COOKIE["language"];
}
$content["login__sign_in_account"]="If you have previously created a profile and are a registered guide, please sign in below";
$content["login__login_general_use_description"]= "This website creates a personal account so you can resume your search for the perfect guide anytime. Don't worry, your information is confidential and secure";
$content["login__sign_in_header_text_bold"]= "Sign up";
$content["login__login"] = "Login";
$content["login__create_account_button"]= "Create Account";
$content["login__sign_in_header_text"]= "for your personal account";
$content["login__create_account"]="If you are new to this website, click the button below to get started on your personal profile and make one step closer to finding your future guide";
$content["login__sign_up_button"]="continue";
$content["login__sign_up_grade"]="sign up";
$content["login__spersonal_acc"]="personal account";
$content["login__citz_stat"]="citizenship status";
$content["login__password"]="password";
$content["login__retype_password"]="retype password";
$content["login__retype_password"]="Account";
$trans = new GoogleTranslate();
foreach($content as $key => $text){
$content["$key"] = $trans->translate("en", $language, $text);
}
$user_type = get_user_type($conn);
mysqli_close($conn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title><?php $content["login__login"]; ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="css/theme.css">
<script src="js/main.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin="anonymous">
<style>
.box-container {
background-color: white;
margin-bottom: 25px;
margin: auto;
margin-top: 10px;
width: 50%;
box-shadow: 0px 0px 15px lightgray;
}
.card-row-header {
font-size: 13px;
color: gray;
margin-bottom: 25px;
overflow: auto;
padding: 0px 20px;
display: flex;
flex-wrap: wrap;
text-align: center;
text-align-last: center;
}
.card-row-header input::placeholder {
font-family: 'Open Sans', sans-serif;
text-transform: uppercase;
color: lightgray;
}
.card-field {
padding-bottom: 20px;
width: 50%;
text-transform: lowercase;
font-size: 12px;
text-align-last: left;
}
.card-row-header input {
border: none;
border-bottom: 1px solid black;
background-color: #fff;
color: black;
font-weight: 700;
width: 95%;
font-size: 16px;
}
.card-row-header select {
border: none;
text-transform: uppercase;
background-color: #fff;
padding: 0px;
color: lightgray;
font-weight: 700;
width: 100%;
}
.divider {
width: 50%;
margin: 0 auto;
}
button {
cursor: pointer;
}
button:focus {
outline:0;
}
.small-nav {
width: 30px;
}
</style>
</head>
<body>
<header>
<nav>
<ul>
<li style="float: left; font-size: 20px;"><a href="index.php"><b>Jump</b>Start</a></li>
<li style="float: right; font-size: 20px;"><a href=""><i class="fas fa-map-marked-alt"></i></a></li>
<li style="float: right; font-size: 20px;"><a href="browse.php"><i class="fas fa-list"></i></a></li>
<li style="float: right; font-size: 20px;" class="dropdown"><a href="javascript:void(0)" class="dropbtn"><i class="fas fa-user-cog"></i></a>
<div class="dropdown-content">
<a href="#">Account</a>
<a href="#">Sign Out</a>
</div>
</li>
</ul>
</nav>
<div class="title"><b><?php echo $content["login__sign_in_header_text_bold"]; ?></b> <?php echo $content["login__sign_in_header_text"]; ?></div>
<div class="sub-title"><?php echo $content["login__login_general_use_description"]; ?></div>
</header>
<main>
<div class="divider">
<div class="grade"><?php echo $content["login__sign_up_grade"]; ?></div>
<div class="date"><?php echo $content["login__spersonal_acc"]; ?></div>
</div>
<div class="box-container">
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="card-row-header" style="padding-top: 20px;">
<div class="card-field"><input type="text" name="fname"><?php echo $userFirstNameErr; ?><br><?php echo $content["login__fname"]; ?></div>
<div class="card-field"><input type="text" name="lname"><?php echo $userLastNameErr; ?><br><?php echo $content["login__lname"]; ?></div>
</div>
<div class="card-row-header">
<div class="card-field"><input type="text" name="email"><?php echo $content["login__err_enter_email"]; ?><br> <?php echo $content["login__email"]; ?></div>
<div class="card-field">
<select name="user-type">
<?php
foreach($user_type as $data)
{
echo '<option value="'. $data->id.'">'. $trans->translate("en", $language, $data->user_type) .'</option>';
}
?>
</select><br><?php echo $content["login__citz_stat"];?></div>
</div>
<div class="card-row-header">
<div class="card-field"><input type="password" name="password"><?php echo $passwordErr; ?><br><?php echo $content["login__password"]; ?></div>
<div class="card-field"><input type="password" name="confirm_password"><?php echo $confirmPasswordErr; ?><br> <?php echo $content["login__retype_password"]; ?></div>
</div>
<div class="card-row-header">
<div class="card-field"><button type="submit" name="signup_submit"><?php echo $content["login__sign_up_button"]; ?></button></div>
</div>
</form>
</div>
</main>
</body>
<footer>
<div id="language-footer">
<ul style="list-style: none;">
<li><div class="card-field;"><img class="small-nav" id="flag-india" src="images/flag-india.png" alt="Indian Flag" data="hi" onclick="languageRestOfTheStuff('flag-india')"></div></li>
<li><div class="card-field;"><img class="small-nav" id="flag-vietnam" src="images/flag-vietnam.png" alt="Vietnam Flag" data="vi" onclick="languageRestOfTheStuff('flag-vietnam')"></div></li>
<li><div class="card-field;"><img class="small-nav" id="flag-arabic" src="images/flag-arabic.png" alt="Arabic Flag" data="ar" onclick="languageRestOfTheStuff('flag-arabic')"></div></li>
<li><div class="card-field;"><img class="small-nav" id="flag-usa" src="images/flag-usa.png" alt="USA Flag" data="en" onclick="languageRestOfTheStuff('flag-usa')"></div></li>
<li><div class="card-field;"><img class="small-nav" id="flag-spanish" src="images/flag-spanish.png" alt="Spanish Flag" data="es" onclick="languageRestOfTheStuff('flag-spanish')"></div></li>
<li><div class="card-field;"><img class="small-nav" id="flag-ethiopia" src="images/flag-ethiopia.png" alt="Ethiopia Flag" data="am" onclick="languageRestOfTheStuff('flag-ethiopia')"></div></li>
<li><div class="card-field;"><img class="small-nav" id="flag-bulgaria" src="images/flag-bulgaria.png" alt="Bulgaria Flag" data="bg" onclick="languageRestOfTheStuff('flag-bulgaria')"></div></li>
<li><div class="card-field;"><img class="small-nav" id="flag-france" src="images/flag-france.png" alt="France Flag" data="fr" onclick="languageRestOfTheStuff('flag-france')"></div></li>
<li><div class="card-field;"><img class="small-nav" id="flag-turkey" src="images/flag-turkey.png" alt="Turkey Flag" data="tr" onclick="languageRestOfTheStuff('flag-turkey')"></div></li>
<li><div class="card-field;"><img class="small-nav" id="flag-filipino" src="images/flag-filipino.png" alt="Filipino Flag" data="tr" onclick="languageRestOfTheStuff('flag-filipino')"></div></li>
</ul>
</div>
</footer>
</html>