-
Notifications
You must be signed in to change notification settings - Fork 7
/
social-login.php
198 lines (190 loc) · 8.72 KB
/
social-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
<?php
// +------------------------------------------------------------------------+
// | @author Deen Doughouz (DoughouzForest)
// | @author_url 1: http://www.playtubescript.com
// | @author_url 2: http://codecanyon.net/user/doughouzforest
// | @author_email: wowondersocial@gmail.com
// +------------------------------------------------------------------------+
// | PlayTube - The Ultimate Video Sharing Platform
// | Copyright (c) 2017 PlayTube. All rights reserved.
// +------------------------------------------------------------------------+
require_once('./assets/init.php');
$provider = "";
$types = array(
'Google',
'Facebook',
'Twitter',
'LinkedIn',
'Vkontakte',
'Instagram'
);
if (isset($_GET['provider']) && in_array($_GET['provider'], $types)) {
$provider = PT_Secure($_GET['provider']);
}
require_once('./assets/import/social-login/config.php');
require_once('./assets/import/social-login/autoload.php');
use Hybridauth\Hybridauth;
use Hybridauth\HttpClient;
if (isset($_GET['provider']) && in_array($_GET['provider'], $types)) {
try {
$hybridauth = new Hybridauth($LoginWithConfig);
$authProvider = $hybridauth->authenticate($provider);
$tokens = $authProvider->getAccessToken();
$user_profile = $authProvider->getUserProfile();
if ($user_profile && isset($user_profile->identifier)) {
$name = $user_profile->firstName;
if ($provider == 'Google') {
$notfound_email = 'go_';
$notfound_email_com = '@google.com';
} else if ($provider == 'Facebook') {
$notfound_email = 'fa_';
$notfound_email_com = '@facebook.com';
} else if ($provider == 'Twitter') {
$notfound_email = 'tw_';
$notfound_email_com = '@twitter.com';
}
$user_name = $notfound_email . $user_profile->identifier;
$user_email = $user_name . $notfound_email_com;
if (!empty($user_profile->email)) {
$user_email = $user_profile->email;
}
if (PT_UserEmailExists($user_email) === true) {
$db->where('email', $user_email);
$login = $db->getOne(T_USERS);
$session_id = sha1(rand(11111, 99999)) . time() . md5(microtime());
$insert_data = array(
'user_id' => $login->id,
'session_id' => $session_id,
'time' => time()
);
$insert = $db->insert(T_SESSIONS, $insert_data);
$_SESSION['user_id'] = $session_id;
setcookie("user_id", $session_id, time() + (10 * 365 * 24 * 60 * 60), "/");
header("Location: $site_url");
exit();
} else {
$str = md5(microtime());
$id = substr($str, 0, 9);
$password = substr(md5(time()), 0, 9);
$user_uniq_id = (empty($db->where('username', $id)->getValue(T_USERS, 'id'))) ? $id : 'u_' . $id;
$social_url = substr($user_profile->profileURL, strrpos($user_profile->profileURL, '/') + 1);
$re_data = array(
'username' => PT_Secure($user_uniq_id, 0),
'email' => PT_Secure($user_email, 0),
'password' => PT_Secure(sha1($password), 0),
'email_code' => PT_Secure(sha1($user_uniq_id), 0),
'first_name' => PT_Secure($name),
'last_name' => PT_Secure($user_profile->lastName),
'avatar' => PT_Secure(PT_ImportImageFromLogin($user_profile->photoURL)),
'src' => PT_Secure($provider),
'active' => '1'
);
$re_data['language'] = $pt->config->language;
if (!empty($_SESSION['lang'])) {
if (in_array($_SESSION['lang'], $langs)) {
$re_data['language'] = $_SESSION['lang'];
}
}
if ($provider == 'Google') {
$re_data['about'] = PT_Secure($user_profile->description);
$re_data['google'] = PT_Secure($social_url);
}
if ($provider == 'Facebook') {
$fa_social_url = @explode('/', $user_profile->profileURL);
$re_data['facebook'] = PT_Secure($fa_social_url[4]);
$re_data['gender'] = 'male';
if (!empty($user_profile->gender)) {
if ($user_profile->gender == 'male') {
$re_data['gender'] = 'male';
} else if ($user_profile->gender == 'female') {
$re_data['gender'] = 'female';
}
}
}
if ($provider == 'Twitter') {
$re_data['twitter'] = PT_Secure($social_url);
}
$insert_id = $db->insert(T_USERS, $re_data);
if ($insert_id) {
if (!empty($pt->config->auto_subscribe)) {
$get_users = explode(',', $pt->config->auto_subscribe);
foreach ($get_users as $key => $username) {
$user = $db->where('username', $username)->getOne(T_USERS);
if (!empty($user)) {
$insert_data = array(
'user_id' => $user->id,
'subscriber_id' => $insert_id,
'time' => time(),
'active' => 1
);
$create_subscription = $db->insert(T_SUBSCRIPTIONS, $insert_data);
if ($create_subscription) {
$current_user = $db->where('id', $insert_id)->getOne(T_USERS);
$data = array(
'status' => 200
);
$notif_data = array(
'notifier_id' => $insert_id,
'recipient_id' => $user->id,
'type' => 'subscribed_u',
'url' => ('@' . $current_user->username),
'time' => time()
);
pt_notify($notif_data);
}
}
}
}
$session_id = sha1(rand(11111, 99999)) . time() . md5(microtime());
$insert_data = array(
'user_id' => $insert_id,
'session_id' => $session_id,
'time' => time()
);
$insert = $db->insert(T_SESSIONS, $insert_data);
$_SESSION['user_id'] = $session_id;
setcookie("user_id", $session_id, time() + (10 * 365 * 24 * 60 * 60), "/");
header("Location: $site_url");
exit();
}
}
}
}
catch (Exception $e) {
exit($e->getMessage());
switch ($e->getCode()) {
case 0:
echo "Unspecified error.";
break;
case 1:
echo "Hybridauth configuration error.";
break;
case 2:
echo "Provider not properly configured.";
break;
case 3:
echo "Unknown or disabled provider.";
break;
case 4:
echo "Missing provider application credentials.";
break;
case 5:
echo "Authentication failed The user has canceled the authentication or the provider refused the connection.";
break;
case 6:
echo "User profile request failed. Most likely the user is not connected to the provider and he should to authenticate again.";
break;
case 7:
echo "User not connected to the provider.";
break;
case 8:
echo "Provider does not support this feature.";
break;
}
echo " an error found while processing your request!";
echo " <b><a href='" . PT_Link('') . "'>Try again<a></b>";
}
} else {
header("Location: " . PT_Link(''));
exit();
}