-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
230 lines (208 loc) · 10.4 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Webchat</title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<script src="js/jquery211.js" type="text/javascript"></script>
<link href="css/style.css" type="text/css" rel="stylesheet"/>
<?php
session_start();
if(isset($_SESSION['UserID'])) {
header("Location: Home.php");
}
include_once "fb/autoload.php";
include 'pages/class.php';
?>
<script type="text/javascript">
$(document).ready(function(){
$("#SignUpDiv").hide();
$("#resetDiv").hide();
$("#AccNotUsed, #createAcc").click(function(){
$("#SignUpDiv").fadeIn();
$("#LoginDiv").fadeOut();
$("#resetDiv").fadeOut();
});
$("#AccUsed, #loginAcc").click(function(){
$("#LoginDiv").fadeIn();
$("#SignUpDiv").fadeOut();
$("#resetDiv").fadeOut();
});
$("#ForgotPW, #ForgotPW1").click(function(){
$("#resetDiv").fadeIn();
$("#SignUpDiv").fadeOut();
$("#LoginDiv").fadeOut();
});
});
</script>
</head>
<body>
<?php
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\GraphUser;
use Facebook\GraphLocation;
use Facebook\GraphSessionInfo;
use Facebook\FacebookHttpable;
use Facebook\FacebookCurl;
use Facebook\FacebookCurlHttpClient;
$id = '1426129404321538';
$secret = 'c282f609eeaecc35914427b8c2920769';
FacebookSession::setDefaultApplication($id, $secret);
$helper = new FacebookRedirectLoginHelper('http://vps1.marefx.com/webchat/index.php');
try{
$session = $helper->getSessionFromRedirect();
}catch(Exception $e){
echo $e->getMessage();
}
if(isset($_SESSION['token'])){
$session = new FacebookSession($_SESSION['token']);
try{
$session->Validate($id, $secret);
}catch(FacebookAuthorizationException $e){
$session = '';
}
}
if(isset($session)){
try {
$_SESSION['token'] = $session->getToken();
echo "Login Successful<br>";
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
$graphObject = $response->getGraphObject(GraphUser::className());
if(checkFBexist($graphObject->getProperty('id'))){
$ins = new user();
$ins->setEmail($graphObject->getProperty('id'));
$ins->UserLoginFB();
$_SESSION['UserID'] = $ins->getUserID();
$_SESSION['Username'] = $ins->getUsername();
$_SESSION['Email'] = $ins->getEmail();
$_SESSION['Type'] = $ins->getType();
echo "exists";
} else {
$ins = new user();
$ins->setUsername($graphObject->getName());
$ins->setEmail($graphObject->getProperty('id'));
$ins->setIP($_SERVER['REMOTE_ADDR']);
$ins->InsertUserFB();
$ins->UserLoginFB();
$_SESSION['UserID'] = $ins->getUserID();
$_SESSION['Username'] = $ins->getUsername();
$_SESSION['Email'] = $ins->getEmail();
$_SESSION['Type'] = $ins->getType();
echo "new";
}
/*echo "ID: " . $graphObject->getProperty('id');
echo "<br/>Name: " . $graphObject->getName();
echo "<br/>Gender: " . $graphObject->getProperty('gender');
echo "<br/>Link: " . $graphObject->getProperty('link');
echo "<br/>Locale: " . $graphObject->getProperty('locale');*/
//echo '<pre>' . print_r( $graphObject, 1 ) . '</pre>';
echo "<a href = " . $helper->getLogoutUrl( $session , 'http://vps1.marefx.com/webchat/fb/logout.php' ) . ">Logout</a>";
}catch(FacebookRequestException $e) {
echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage();
}
}else{
?>
<div id="LoginDiv">
<h1>LOGIN</h1>
<form method="post" action="pages/UserLogin.php" class="login">
<p>
<label>Email:</label>
<input type="text" name="UserMailLogin" placeholder="[email protected]">
</p>
<p>
<label>Password:</label>
<input type="password" name="UserPasswordLogin" value="">
</p>
<p class="login-submit">
<button type="submit" class="login-button">Login</button>
</p>
<p class="CreatingLogin">
<button type="button" id="AccNotUsed"><span>Create new account</span></button>
<button type="button" id="ForgotPW"><span>Forgotten password?</span></button>
<?php echo "<a href = '" . str_replace("&","&",$helper->getLoginUrl()) . "'><img style='position:relative; top: 4px;' width='55' alt='fblogin' src='img/fblogin.png'/></a>"; ?>
<!--<button type="button" id =FBLogin><span><img src="http://d2fnoh68uhxcn9.cloudfront.net/ND/img/fb-login-button.png" alt="fblogin" width="20" height="20"/></span></button>-->
</p>
<?php
if(isset($_GET['error']) && $_GET['error'] == 1){
echo '<p><span style="color:red">Login error: Email or password does not match</span></p>';
}elseif(isset($_GET['error']) && $_GET['error'] == 2){
echo '<p><span style="color:red">Error creating account: Passwords do not match</span><p>';
}elseif(isset($_GET['error']) && $_GET['error'] == 3){
echo '<p><span style="color:red">No matching accounts found</span></p>';
}elseif(isset($_GET['error']) && $_GET['error'] == 4){
echo '<p><span style="color:red">Empty fields</span></p>';
}elseif(isset($_GET['error']) && $_GET['error'] == 5){
echo '<p><span style="color:red">Email already in use!</span></p>';
}elseif(isset($_GET['error']) && $_GET['error'] == 6){
echo '<p><span style="color:red">Username already in use!</span></p>';
}elseif(isset($_GET['error']) && $_GET['error'] == 7){
echo '<p><span style="color:red">Invalid email</span></p>';
}elseif(isset($_GET['success']) && $_GET['success'] == 1){
echo '<p><span style="color:green">Registration successfull, you can now login</span></p>';
}elseif(isset($_GET['success']) && $_GET['success'] == 2){
echo '<p><span style="color:green">Password reset successfull, please check your Inbox and Junk folder</span></p>';
}
?>
</form>
</div>
<br/><br/><br/>
<div id="SignUpDiv">
<h1>REGISTER</h1>
<form method="post" action="pages/InsertUser.php" class="login">
<p>
<label>Username:</label>
<input type="text" name="Username" placeholder="John">
</p>
<p>
<label>Email:</label>
<input type="text" name="Email" placeholder="[email protected]">
</p>
<p>
<label>Password:</label>
<input type="password" name="Password" value="">
</p>
<p>
<label>Re-type:</label>
<input type="password" name="Password1" value="">
</p>
<p class="login-submit">
<button type="submit" class="login-button">Login</button>
</p>
<p class="CreatingLogin">
<button type="button" id="AccUsed"><span>Login with existing user</span></button>
<button type="button" id="ForgotPW1"><span>Forgotten password?</span></button>
</p>
</form>
</div>
<div id="resetDiv">
<h1>RESET PASSWORD</h1>
<form method="post" action="pages/ForgotPassword.php" class="login">
<p>
<label>Username:</label>
<input type="text" name="myUser" placeholder="John">
</p>
<p>
<label>or Email:</label>
<input type="text" name="myEmail" placeholder="[email protected]">
</p>
<p class="login-submit">
<button type="submit" class="login-button">Reset</button>
</p>
<p class="CreatingLogin">
<button type="button" id="createAcc"><span>Create new account</span></button>
<button type="button" id="loginAcc"><span>Login with existing user</span></button>
</p>
</form>
</div>
<?php } ?>
</body>
</html>