-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
173 lines (163 loc) · 5.99 KB
/
index.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
<?php
session_start();
include('config/Secret/secret.php');
include('config/config.php');
include('config/database.php');
include('Helpers/user.php');
$user = new User($con);
$loginSuccessful = false;
$signUp = false;
function recaptcha(){
$response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.SECRET_KEY.'&response='.$_POST['recaptcha-response']);
$response = json_decode($response);
if($response->success && $response->score > 0.5){
return true;
}
else {
return false;
}
}
if(isset($_POST['signup'])){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$username = $_POST['username'];
$password = $_POST['password'];
$conpass = $_POST['confirm'];
if(recaptcha()){
$signUp = $user->signUp($fname,$lname,$username,$password,$conpass);
}
else {
echo '<script>alert("Try Again")</script>';
}
}
if(isset($_POST['signin'])){
$username = $_POST['userlogin'];
$password = $_POST['passwordlogin'];
$loginSuccessful = $user->signIn($username,$password);
if($loginSuccessful){
$_SESSION['userLoggedIn'] = $user->getUserId($username);
$_SESSION['name'] = $username;
header('location: home.php');
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Pigeons: Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://www.google.com/recaptcha/api.js?render=<?php echo SITE_KEY; ?>"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/css?family=Rubik:400,500,700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css">
<link rel="stylesheet" type="text/css" href="public/Stylesheets/index.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" id="headMain" href="index.php"><span><i class="fas fa-project-diagram"></i></span>Pigeons</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="dropdown"><a class="dropdown-toggle btn" href="#" data-toggle="dropdown"><span class="glyphicon glyphicon-log-in"></span> Login</a>
<div class="dropdown-menu dropdown-menu-right">
<form action="index.php" method="POST">
<div class="form-group">
<label for="userLogin">Username</label>
<input type="text" id="userLogin" class="form-control" placeholder="username" name="userlogin">
</div>
<div class="form-group">
<label for="passwordlogin">Password</label>
<input type="password" id="passwordlogin" class="form-control" placeholder="password" name="passwordlogin">
</div>
<button type='submit' class="btn" id='login' name='signin'>Login</button>
</form>
</div>
</li>
</ul>
</div>
</nav>
<div class="container main">
<div class="row">
<div class="col-sm-6">
<h2>REGISTER</h2>
<form action="index.php" method="POST">
<?php
if($signUp){
echo 'Successfully Registered';
}
?>
<?php echo $user->getError('Invalid First Name'); ?>
<?php echo $user->getError('Invalid Last Name'); ?>
<div class="row">
<div class="col">
<label for="name">First Name:</label>
<input type="text" id="name" class="form-control" placeholder="3-20 char" name="fname" required>
</div>
<div class="col">
<label for="name">Last Name:</label>
<input type="text" id="name" class="form-control" placeholder="max 20 char" name="lname">
</div>
</div>
<div class="form-group">
<?php echo $user->getError('Invalid Username'); ?>
<?php echo $user->getError('Username Exists'); ?>
<label for="username">Username</label>
<input type="text" name="username" id="username" class="form-control" required>
</div>
<div class="form-group">
<?php echo $user->getError('Longer Password required'); ?>
<label for="password">Password</label>
<input type="password" name="password" class="form-control" required>
<small>Password must be minimum 8 characters</small>
</div>
<div class="form-group">
<?php echo $user->getError( "Passwords don't match"); ?>
<label for="confirmPass">Confirm Password</label>
<input type="password" name="confirm" class="form-control" required>
</div>
<input type="submit" class="btn form-control" name="signup" value="Sign Up">
<input type="hidden" name="recaptcha-response">
</form>
</div>
<div class="col-sm-4 title">
<h2><span><i class="fas fa-project-diagram"></i></span>PIGEONS</h2>
<div>Place to share your messages</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('<?php echo SITE_KEY; ?>', {action: 'homepage'}).then(function(token) {
console.log(token);
document.querySelector('input[name="recaptcha-response"]').value = token;
});
});
var username = document.getElementById('username');
username.addEventListener('input',function(){
$.ajax({
type:'GET',
url:'user/checkUser.php?username='+username.value,
success:function(response){
console.log(response);
if(response == 'yes'){
username.style.boxShadow = '0 0 4px #00FF00';
username.style.border = '1px solid #00FF00';
}
else {
username.style.boxShadow = '0 0 4px #FF0000';
username.style.border = '2px #FF0000';
}
},
error: function(){
console.log('error occured');
}
})
})
</script>
</body>
</html>