-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
240 lines (209 loc) · 9.57 KB
/
login.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_once 'include/db_connect.php';
$email = $password = "";
$emailErr = $passwordErr = "";
$content["login__err_valid_email"] = "enter a valid email";
$content["login__err_incorrect_password"] = "incorrect password";
$content["login__err_valid_password"] = "The password you entered was not valid.";
$content["login__err_no_account_email"] = "No account found with that email.";
$content["login__err_oops"] = "Oops! Something went wrong. Please try again later.";
if(isset($_POST['login_submit'])){
// Check if username is empty
if(empty(trim($_POST["email"]))){
$emailErr = $content["login__err_valid_email"];
} else{
$email = trim($_POST["email"]);
}
// Check if password is empty
if(empty(trim($_POST['password']))){
$passwordErr = $content["login__err_incorrect_password"];
} else{
$password = trim($_POST['password']);
}
// Validate credentials
if(empty($emailErr) && empty($passwordErr)){
// Prepare a select statement
$sql = "SELECT user_email, user_password 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);
// Set parameters
$paramEmail = $email;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Store result
mysqli_stmt_store_result($stmt);
// Check if username exists, if yes then verify password
if(mysqli_stmt_num_rows($stmt) == 1){
// Bind result variables
mysqli_stmt_bind_result($stmt, $email, $hashedPassword);
if(mysqli_stmt_fetch($stmt)){
if(password_verify($password, $hashedPassword)){
/* Password is correct, so start a new session and
save the username to the session */
session_start();
$_SESSION['user_id'] = $email;
header("location: browse.php");
} else{
// Display an error message if password is not valid
$passwordErr = $content["login__err_no_account_email"];
}
}
} else{
// Display an error message if username doesn't exist
$emailErr = $content["login__err_no_account_email"];
}
} else{
echo $content["login__err_oops"];
}
}
}
}
if(isset($_POST["language"])){
$language = $_POST["language"];
setcookie("language", $language, time() + (86400 * 30), "/");
}elseif(!isset($_COOKIE["language"])) {
$language = "en";
setcookie("language", $language, time() + (86400 * 30), "/");
}else{
$language=$_COOKIE["language"];
}
require_once ('vendor/autoload.php');
use \Statickidz\GoogleTranslate;
$content["login__grade_sign_up"] = "sign up";
$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 will allow you to either help guide an immagrant family or if you are an immagrant family you can find a resdient family to help make your transtion to your new home smoother. we ensure a smooth and safe transition into your new friendship family, so don't worry, your information is confidential and secure";
$content["login__sign_in_header_text_bold"]= "choose";
$content["login__login"] = "Login";
$content["login__create_account_button"]= "Create Account";
$content["login__sign_in_header_text"]= "your account";
$content["login__sign_in_button"]= "sign in";
$content["login__create_account"]="If you are new to this website, click the button below to get started on your personal profile and become one step closer to finding your future friendship family";
$content["login__grade_log_in"] = "log in";
$content["login__log_personal_acct"] = "personal account";
$content["login__email"] = "email";
$content["login__password"] = "password";
$content["login__grade_sign_up"] = "sign up";
$content["login__sign_personal_acct"] = "personal account";
$trans = new GoogleTranslate();
foreach($content as $key => $text){
$content["$key"] = $trans->translate("en", $language, $text);
}
// Close connection
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 {
margin: 0 auto;
padding-bottom: 20px;
width: 33.33%;
flex-grow: 1;
}
.card-row-header input {
border: none;
background-color: #fff;
padding: 0px;
color: black;
font-weight: 700;
width: 100%;
}
.divider {
width: 50%;
margin: 0 auto;
}
button {
cursor: pointer;
}
button:focus {
outline: 0;
}
</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__grade_log_in"]; ?></div>
<div class="date"><?php echo $content["login__log_personal_acct"]; ?></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 id ="input-user" type="text" name="email" placeholder="johnsmith@gmail.com"><?php echo $emailErr; ?><br><?php echo $content["login__email"]; ?></div>
<div class="card-field"><input id="input-lock" type="password" name="password" placeholder="●●●●●●●●●●●"><?php echo $passwordErr; ?><br><?php echo $content["login__password"]; ?></div>
</div>
<div class="card-row-header">
<div class="card-field"><button type="submit" name="login_submit"><?php echo $content["login__sign_in_button"]; ?></button></div>
</div>
</form>
</div>
<div class="divider">
<div class="grade"><?php echo $content["login__grade_sign_up"]; ?></div>
<div class="date"><?php echo $content["login__sign_personal_acct"]; ?></div>
</div>
<div class="box-container">
<div class="card-row-header" style="padding-top: 20px;">
<div class="card-field"><?php echo $content["login__create_account"]; ?></div>
</div>
<div class="card-row-header">
<div class="card-field"> <a href="signup.php"><button><?php echo $content["login__create_account_button"]; ?></button></a></div>
</div>
</div>
</main>
</body>
<footer>
<div id="language-footer">
<div id = "language-display" class="languages"><script>displayLanguage('<?php echo $language?>');</script></div>
<img id ="language-flag" src="" alt="" onclick="languageSelect(id)">
</div>
</footer>
</html>