-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfbconnectuser.php
75 lines (63 loc) · 1.47 KB
/
fbconnectuser.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
<?php
require_once 'config.inc.php';
if (empty($_POST['username']) || empty($_POST['pass'] ))
{
echo $VGA_CONTENT['enter_user_pwd_txt'];
exit();
}
if (empty($_POST['fbuserid'] ))
{
echo $VGA_CONTENT['fbid_prob_txt'];
exit();
}
$username = GetMySQLEscapedPostParam('username');
$fb_userid = GetMySQLEscapedPostParam('fbuserid');
// checks it against the database
$sql = "SELECT * FROM users WHERE username = '$username'";
$check = mysql_query($sql);
if (!$check)
{
handle_db_error($check);
echo "0";
exit();
}
//Gives error if user dosen't exist
if (mysql_num_rows($check) == 0)
{
$format = $VGA_CONTENT['user_not_reg_txt'];
$str = sprintf($format, $username);
echo $str;
exit();
}
$info = mysql_fetch_assoc($check);
$userid = $info['id'];
$password = $_POST['pass'];
//gives error if the password is wrong
if (!checkUserPassword($info['id'], $password, $info['password']))
{
//echo "Incorrect password for $username";
$format = $VGA_CONTENT['wrong_user_pwd_txt'];
$str = sprintf($format, $username);
echo $str;
exit();
}
else
{
// Add FB User ID to user record
$sql = "UPDATE `users` SET `fb_userid` = '$fb_userid' WHERE `id` = $userid";
$result = mysql_query($sql);
if (!$result)
{
handle_db_error($result);
echo "0";
exit();
}
// log user in
$_SESSION[USER_LOGIN_ID] = $info['id'];
$_SESSION[USER_LOGIN_MODE] = 'FB';
// log time
setlogintime($info['id']);
echo '1';
exit();
}
?>