This repository was archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoauth.php
More file actions
51 lines (42 loc) · 1.63 KB
/
oauth.php
File metadata and controls
51 lines (42 loc) · 1.63 KB
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
<?php
require 'includes/master.inc.php';
$user_token = TwitterToken::getTwitterToken();
if (is_array($user_token)) {
$token = $user_token;
$Twitter->setToken($token['oauth_token'], $token['oauth_token_secret']);
$Twitter->setAuthenticated(true);
$Smarty->assign('twitterAuthenticated', $Twitter->isAuthenticated());
} else {
if (isset($_GET['oauth_token'])) {
$Twitter->setToken($_GET['oauth_token']);
$token = $Twitter->getAccessToken();
TwitterToken::setTwittertoken(array('oauth_token' => $token->oauth_token, 'oauth_token_secret' => $token->oauth_token_secret));
$Twitter->setToken($token->oauth_token, $token->oauth_token_secret);
$Twitter->setAuthenticated(true);
} else {
$Smarty->assign('authorizeUrl', $Twitter->getAuthorizeUrl() );
$Twitter->setAuthenticated(false);
}
$Smarty->assign('twitterAuthenticated', $Twitter->isAuthenticated());
}
if ($Twitter->isAuthenticated() == true):
// Get User Information
$userInfo = $Twitter->get('/account/verify_credentials.json');
$Smarty->assign('userInfo', $userInfo->response);
// Add database row if not already set
$check = $DB->getRows("SELECT * FROM users WHERE UPPER(twitter_screenname) = UPPER('{$userInfo->screen_name}'); ");
if (count($check) == 0):
$record = new User();
$record->twitter_screenname = $userInfo->screen_name;
$record->is_admin = 0;
$_SESSION['user_id'] = $user_id = $record->insert();
else:
$_SESSION['user_id'] = $check[0]['id'];
$_SESSION['is_admin'] =$check[0]['is_admin'];
endif;
endif;
// Redirect if already logged in
if($Twitter->isAuthenticated())
header('Location: ' . BASE_URL);
// Render
$Smarty->display('authenticate.tpl');