forked from seanlebeck/site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fbReg.php
156 lines (125 loc) · 4.41 KB
/
fbReg.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
<?php
ob_start();
session_start();
// Include required files.
require "accounts/includes/config.php";
require "accounts/includes/database.php";
require "accounts/includes/src/facebook.php";
require "accounts/includes/language.php";
$ck_username = 'username';
$ck_session = 'session';
$ck_userid = 'userid';
$cookie_path = '/';
//Cookie Domain/ Leave out the http://www and start with a dot.
$cookie_domain = '.shufflebuy.com';
// init database object
$db = new database();
$db->connect();
// Create Facebook connect object
$facebook = new Facebook(array(
'appId' => $fb_app_api,
'secret' => $fb_app_secret,
'cookie' => true
));
// Get User ID
$user = $facebook->getUser();
// If a session exists, proceed to check details against database
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
// check to see if user is in the database
$where = "oauth_uid = '{$user}'";
$db->select('*','vivaru_acc_users',$where);
$rows = $db->getRows();
$result = $db->getResult();
if($rows == 0) {
if ( $username_login_only == 1 )
{
$u_not_empty = (!empty($username)) ? '1' : '0';
$u_success = ($username == $row['username']) ? '1' : '0';
$u_sql = "username = '$username'";
}
else
{
$u_not_empty = (!empty($update_email)) ? '1' : '0';
$u_success = ($update_email == $row['email']) ? '1' : '0';
$u_sql = "email = '$update_email'";
}
// user not in db, insert details
if(!empty($user)){
$user_ip = $_SERVER['REMOTE_ADDR'];
// insert details
$iString = "oauth_provider, oauth_uid, username, email, joined, last_login, user_ip, active";
$iArray = array();
array_push($iArray,'facebook');
array_push($iArray,$user);
array_push($iArray,$user_profile['name']);
array_push($iArray,$user_profile['email']);
array_push($iArray,time());
array_push($iArray,time());
array_push($iArray,$user_ip);
array_push($iArray,"1");
$db->insert('vivaru_acc_users',$iArray,$iString);
$where = "oauth_uid = '{$user}'";
$db->select('*','vivaru_acc_users',$where);
$result = $db->getResult();
// create profile page
// echo "user : ",$result['username'];
//createProfile($result['username']);
// set session vars
validate_user($result['username'],$result['userType']);
$target_id = $user;
$title = FACEBOOK_POST_TITLE;
$name = FACEBOOK_POST_NAME;
$caption = FACEBOOK_POST_CAPTION;
$description = FACEBOOK_POST_DESCRIPTION;
$image = FACEBOOK_POST_IMAGE;
$url = FACEBOOK_POST_URL;
try {
$facebook->api('/'.$target_id.'/feed', 'post', array(
'message' => $title,
'name' => $name,
'description' => $description,
'caption' => $caption,
'picture' => $image,
'link' => $url
));
}
catch (Exception $e){ echo $output = '<li>'.$e.'</li>'; }
// divert to profile
}
} else {
validate_user($user['name'],$result['userType']);
// user exists, redirect to profile page
//header('location: ../account.html');
}
// $where = "oauth_uid = '{$uid}'";
// $db->select('*','vivaru_acc_users',$where);
// $result = $db->getResult();
print_r($user);
$sql = "SELECT user_id, username, email, password, active, user_ip FROM vivaru_acc_users
WHERE oauth_uid = '".$user."' LIMIT 1";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$sql = "SELECT user_id, username, email, password, active, user_ip FROM vivaru_acc_users
WHERE oauth_uid = '".$user."' LIMIT 1";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$md5_password = md5($password . SALT);
$cookie_expire_time = 86400;
setcookie($ck_username, $row['username'], time() + $cookie_expire_time, $cookie_path, $cookie_domain);
setcookie($ck_session, $md5_password, time() + $cookie_expire_time, $cookie_path, $cookie_domain);
setcookie($ck_userid, $row['user_id'], time() + $cookie_expire_time, $cookie_path, $cookie_domain);
$update_empty_ip = ($row['user_ip'] <= 0) ? ", user_ip = '$user_ip'" : "";
$sql = "UPDATE vivaru_acc_users SET last_login = '".time()."' $update_empty_ip WHERE user_id ='".$row['user_id']."'";
mysql_query($sql);
header('location: ../account.html');
}
ob_flush();
header('location: ../login.html');
?>