-
Notifications
You must be signed in to change notification settings - Fork 23
/
signup-login.php
422 lines (360 loc) · 10.4 KB
/
signup-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
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
<?php
require 'connect.php';
$errorMsg = "";
$errors = array("name" => "", "username" => "", "email" => "", "password" => "", "cPassword" => "", "signup" => '');
if(isset($_POST['register'])) {
if (empty($_POST['name'])) {
$errors['name'] = "required <br/>";
} else {
$name = $_POST['name'];
if(!preg_match("/^[a-zA-Z\s]+$/", $name)){
$errors['name'] = "Name can only contain letters and spaces <br/>";
}
}
if (empty($_POST['username'])) {
$errors['username'] = "required <br/>";
} else {
$username = $_POST['username'];
if(!preg_match("/^[a-zA-Z\s]+$/", $username)){
$errors['username'] = "Username can only contain letters and spaces <br/>";
}
}
if (empty($_POST['email'])) {
$errors['email'] = "email is required <br/>";
} else {
$email = $_POST['email'];
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors['email'] = "email must be valid address <br/>";
}
}
if (empty($_POST['pwd'])) {
$errors['password'] = " <br/> required ";
} else {
$password = htmlspecialchars($_POST['pwd']);
$cPassword = htmlspecialchars($_POST['cpwd']);
if($password != $cPassword) {
$errors["cPassword"] = "password does not match <br/>";
}
}
if(!array_filter($errors) ) {
$name = mysqli_real_escape_string($conn, $_POST["name"]);
$username = mysqli_real_escape_string($conn, $_POST["username"]);
$email = mysqli_real_escape_string($conn, $_POST["email"]);
$password = mysqli_real_escape_string($conn, $_POST["pwd"]);
//check if account exist
$query = "SELECT * FROM users WHERE email = '$email'";
$query_result = mysqli_query($conn, $query);
$user = mysqli_fetch_all($query_result, MYSQLI_ASSOC);
if(!$user) {
$sql = "INSERT INTO users(username, password_hash, email) VALUES('$username','$password', '$email')";
$add_user = mysqli_query($conn, $sql);
session_start();
$_SESSION['name'] = $username;
$_SESSION['email'] = $email;
header("Location: userpage.php?=$username");
} else{
$errors['signup'] = "This email address already exists. Switch tab to log in";
}
}
}
if(isset($_POST["login"])) {
$email = $_POST['email'];
$password = $_POST['password'];
$username = '';
if(empty($_POST['email']) && empty($_POST['password'])) {
$errorMsg = "All fields required";
}
if(!empty($_POST['email']) && !empty($_POST['password'])) {
$errorMsg = "The email does not exist, please sign up";
}
if(empty($_POST['email']) && !empty($_POST['password'])) {
$errorMsg = "Enter an email address and try again";
}
if(!empty($_POST['email']) && empty($_POST['password'])) {
$errorMsg = "Enter an password and try again";
}
$query = "SELECT * FROM users WHERE email = '$email'";
$query_result = mysqli_query($conn, $query);
$user = mysqli_fetch_all($query_result, MYSQLI_ASSOC);
if($user) {
session_start();
$_SESSION['email'] = $email;
foreach($user as $cred => $values) {
$_SESSION['name'] = $values['username'];
}
header("Location: userpage.php?login=sucess");
} else{
header("Locaiton: index.html");
}
}
?>
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<meta name="theme-color" content="#333" />
<title>SpendLess - Home</title>
<link rel="stylesheet" href="css/index.css" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
/>
<link
href="https://fonts.googleapis.com/css?family=Nunito&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="css/style.css" />
<!-- <link rel="stylesheet" href="css/signup.css"> -->
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="css/danstyles.css" />
<!-- css file for sign up button pulse animation-->
<link rel="stylesheet" type="text/css" href="css/animate.css" />
<link rel="stylesheet" href="./css/signuplogin.css" />
<link rel="manifest" href="/manifest.json" />
<style>
.card-box{
padding: 15px;
box-shadow: 0 0 10px #CDCDCD;
text-align: center;
}
.card-box-text{
text-align: justify
}
.get-started{
display: flex;
flex-direction: row;
justify-content: center;
}
index-sign-up{
background-color: orange; !important
}
.index-sign-up:hover{
background-color: orangered;
color: white;
border: none;
}
.animatedPulse {
animation: pulse 1s infinite;
}
.center {
text-align: center;
font-size: 10px;
padding: 15px;
color: red;
}
</style>
</head>
<body>
<nav class="flex">
<figure>
<a href=""><img
src="https://res.cloudinary.com/angelae/image/upload/v1569493481/Start-ng-Pre-internship/n2mmwn3pvnbjuaqjjkj3.png"
alt="Logo"
style="width: 63px; height: 63px; padding: 10px;"
/></a>
</figure>
<div class="big-nav hidden">
<ul>
<a href="" class="toplinks"><li></li></a>
<a href="" class="toplinks"><li></li></a>
<a href="" class="toplinks"><li></li></a>
<a href="" class="toplinks"><li></li></a>
<a href="" class="toplinks"><li></li></a>
</ul>
<div>
<a
href="signup-login.html"
class="toplinks-signup"
data-toggle="modal"
data-target="#signup"
>SIGN UP / LOG IN</a
>
</div>
</div>
<i class="fa fa-bars"></i>
<div class="small-nav hidden">
<a href="" class="toplinks">Why SpendLess?</a>
<a href="" class="toplinks">Solutions</a>
<a href="" class="toplinks">Resources</a>
<a href="" class="toplinks">How it Works</a>
<a href="" class="toplinks">Support</a>
</div>
</nav>
<div class="container container1">
<header>
<p>Welcome</p>
</header>
<div class="signup-login-container">
<button class="signup">SIGNUP</button>
<button class="login">LOGIN</button>
</div>
<form action="signup-login.php" method="POST">
<table class="signup-form1">
<tr>
<td>
<label for="name">Name</label>
</td>
</tr>
<tr>
<td>
<input
type="text"
name="name"
id="name"
placeholder="Enter your name"
/>
<br><span><?php echo $errors["name"]; ?></span>
</td>
</tr>
<tr>
<td>
<label for="Username">Username</label>
</td>
</tr>
<tr>
<td>
<input
type="text"
name="username"
id="username"
placeholder="Enter username"
/>
<br><span><?php echo $errors["username"]; ?></span>
</td>
</tr>
<tr>
<td>
<label for="name">Email</label>
</td>
</tr>
<tr>
<td>
<input
type="email"
name="email"
id="email"
placeholder="Enter your email addresss"
/>
<br><span><?php echo $errors["email"]; ?></span>
</td>
</tr>
<tr>
<td>
<label for="Pass1">Password</label>
</td>
</tr>
<tr>
<td>
<input
type="password"
name="pwd"
id="pass1"
placeholder="Enter password"
value="<?php echo ""?>"
/>
<br><span><?php echo $errors["password"]; ?></span>
</td>
</tr>
<tr>
<td>
<label for="cpwd">Confirm Password</label>
</td>
</tr>
<tr>
<td>
<input
type="password"
name="cpwd"
id="pass2"
placeholder="Confirm password"
/>
<br><span><?php echo $errors["cPassword"]; ?></span>
</td>
</tr>
<tr>
<td>
<input type="submit" value="sign up" name='register' />
</td>
</tr>
</table>
<small style="text-align: center"><?php echo $errors['signup']; ?></small>
<small class="center"><?php echo $errorMsg ?></small>
</form>
<a href="#login"><form action="signup-login.php" method="POST" id="log_in">
<table class="login-form1">
<tr>
<td>
<label for="email/username">Email / Username</label>
</td>
</tr>
<tr>
<td>
<input
type="text"
name="email"
id="email/username"
placeholder="Enter email or username"
/>
</td>
</tr>
<tr>
<td>
<label for="password">Password</label>
</td>
</tr>
<tr>
<td>
<input
type="password"
name="password"
id="password"
placeholder="Enter your password"
/>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Log in" name="login" />
</td>
</tr>
</table>
<small></small>
</form></a>
</div>
<footer style="padding-top: 1.5%;">
Team Ganymede - HNGi6 © 2019.
<a href="#"><i class="fa fa-angle-double-up"></i></a>
</footer>
<!-- Scripts should come below here -->
<script src="./js/signup-login.js"></script>
<script src="./js/menu-action.js"></script>
<script
src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"
></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"
></script>
<script>
$('.popover-dismiss').popover({
trigger: 'focus'
});
</script>
</body>
</html>