Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

92 lines (77 sloc) 3.074 kB
<?php
include('inc.php');
require_once('EpiCurl.php');
require_once('EpiOAuth.php');
require_once('EpiTwitter.php');
if(get('login_token') && session('noLoginRedirect') != 1) {
// Login will have already happened in inc.php at this point
header('Location: /list');
die();
}
if(get('getLoginURL')) {
$_SESSION['noLoginRedirect'] = 1;
header('Location: /login?login_token=' . $user->loginToken);
die();
}
include('templates/header.php');
$twitter = new EpiTwitter(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
if(get('oauth_token'))
{
// Returned from the Twitter approval screen
$twitter->setToken(get('oauth_token'));
try
{
$token = $twitter->getAccessToken(array('oauth_verifier'=>get('oauth_verifier')));
if($token->oauth_token && $token->oauth_token_secret)
{
$twitter = new EpiTwitter(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, $token->oauth_token, $token->oauth_token_secret);
// User successfully authenticated to Twitter.
$account = $twitter->get_accountVerify_credentials();
// Look up this user in the DB, and create an account if one doesn't exist yet
$entity = Model_User::create($account->id, 'twitterID');
if($entity) {
header('Location: /login?login_token=' . $entity->loginToken);
die();
} else {
irc_debug('Someone tried to log in from Twitter before creating an acct by email: ' . $account->screen_name);
// Haven't created an account yet, show a nice message
echo '<div style="width: 540px; margin: 40px auto; text-align: center;">';
echo '<div style="font-size: 18pt;">Sorry, you don\'t have an account yet.</div>';
echo '<div style="margin-top: 10px;">Send an email to your-graph@graphthis.me to create a graph, you\'ll get an email with instructions on how to set up your account.</div>';
echo '<div style="margin-top: 10px; font-size: 10pt;">You can make more graphs by changing the part before the "@" sign!</div>';
echo '</div>';
}
}
else
login_error('Twitter Error', 'No tokens were provided in the response from Twitter.');
}
catch(EpiOAuthException $e)
{
login_error('Twitter Error', 'Unable to get an access token. Probably your request token has expired. Try logging in again.');
}
} else {
if(session('noLoginRedirect')) {
echo '<div style="text-align: center;">';
echo '<div style="padding: 15px; text-align: center;">Bookmark this page to automatically log in!</div>';
echo '</div>';
unset($_SESSION['noLoginRedirect']);
}
else {
// Authorize URL makes the user approve the app every time, authenticate redirects seamlessly after the initial connection is made
try
{
$auth_url = $twitter->getAuthenticateUrl(null, array('oauth_callback' => https() . $_SERVER['SERVER_NAME'] . '/login'));
}
catch(EpiOAuthException $e)
{
login_error('Twitter Error', 'Unable to get the authentication URL from Twitter: ' . $e->getMessage());
}
header('Location: ' . $auth_url);
die();
}
}
include('templates/footer.php');
function login_error($title, $message) {
echo $title . ' ' . $message;
die();
}
Jump to Line
Something went wrong with that request. Please try again.