Permalink
Browse files

Fixes twitter integration, first email sent out includes a link to co…

…nnect your twitter account, banner is displayed at the top of the site when you don't have a twitter account connected yet.
  • Loading branch information...
1 parent d55d35a commit 43d17e878454075a65778492df4d57be2851dd41 @aaronpk committed Apr 12, 2011
Showing with 161 additions and 62 deletions.
  1. +2 −2 .htaccess
  2. +17 −1 assets/styles.css
  3. +21 −0 include/Model/User.php
  4. +4 −2 include/inc.php
  5. +14 −0 include/templates/header.php
  6. +6 −1 index.php
  7. +26 −56 login.php
  8. +3 −0 logout.php
  9. +68 −0 twitter_connect.php
View
@@ -1,5 +1,5 @@
Options -MultiViews
RewriteEngine on
-RewriteRule ^([a-z]+)$ $1.php [QSA,L]
-RewriteRule ^([a-z]+)/([0-9]+)/.+ $1.php?id=$2 [QSA,L]
+RewriteRule ^([a-z_]+)$ $1.php [QSA,L]
+RewriteRule ^([a-z_]+)/([0-9]+)/.+ $1.php?id=$2 [QSA,L]
View
@@ -46,4 +46,20 @@ textarea, input {
.note {
font-size: 10pt;
-}
+}
+
+.notification {
+ margin: 6px;
+ text-align: center;
+ font-size: 9pt;
+ background-color: #3597d5;
+ border: 2px #156598 solid;
+ color: white;
+ text-shadow: 1px 1px 0 #156598;
+}
+.notification a {
+ color: white;
+}
+.notification .inside {
+ padding: 5px;
+}
View
@@ -119,6 +119,27 @@ public static function generateLoginToken()
return md5(rand(1000,9999).time());
}
+ public function addTwitterInfo($screen_name, $id, $token, $secret)
+ {
+ // Assume that if they connected this account to Twitter, that any of their other accounts should be disconnected from Twitter.
+ // This will remove the id/token/secret from all other user accounts that had this ID previously.
+ // Allows people to switch which GT account is connected to their Twitter account.
+
+ $sql = 'UPDATE `users` SET `username` = "", twitterID = "", twitterUsername = "", twitterToken = "", twitterSecret = "" WHERE twitterID = :twid';
+ $query = new Model_User();
+ $query->prepare($sql);
+ $query->bind(':twid', $id);
+ $query->execute();
+
+ Model_User::update(array(
+ 'username' => $screen_name,
+ 'twitterID' => $id,
+ 'twitterUsername' => $screen_name,
+ 'twitterToken' => $token,
+ 'twitterSecret' => $secret
+ ), $this->id);
+ }
+
public function addEmail($value)
{
return $this->_addInfo('email', $value);
View
@@ -40,8 +40,10 @@
// Redirect to the page they were trying to get to
$redirect = trim(str_replace('login_token=' . get('login_token'), '', $_SERVER['REQUEST_URI']), '?');
- header('Location: ' . $redirect);
- die();
+ if($redirect != '/login') {
+ header('Location: ' . $redirect);
+ die();
+ }
}
} else {
if(session('userID')) {
@@ -33,3 +33,17 @@
?>
<body>
<div class="content">
+<?php
+if($user) {
+ if($user->twitterID == '') {
+ echo '<div class="notification">
+ <div class="inside">
+ You can <a href="/twitter_connect">connect your Twitter</a> account to sign in faster.
+ </div>
+ </div>';
+ }
+}
+
+if($_SERVER['SCRIPT_NAME'] != '/index.php') {
+ echo '<div style="margin: 10px; font-size: 18pt; text-align: center;">GraphThis.me</div>';
+}
View
@@ -1,6 +1,11 @@
<?php
include('inc.php');
+if($user) {
+ header('Location: /list');
+ die();
+}
+
include('templates/header.php');
?>
@@ -14,7 +19,7 @@
<div style="margin-top: 10px; font-size: 9pt;">You can make more graphs by changing the part before the "@" sign.</div>
<div style="margin-top: 40px;">Been here before?</div>
- <div style="margin-top: 10px;"><a href="/login?go=1"><img src="/assets/images/sign-in-with-twitter-d.png" width="151" height="24" /></a></div>
+ <div style="margin-top: 10px;"><a href="/login"><img src="/assets/images/sign-in-with-twitter-d.png" width="151" height="24" /></a></div>
<div style="font-size: 9pt; margin-top: 60px;">You might also like <a href="http://geoloqi.com">Geoloqi</a></div>
View
@@ -10,7 +10,7 @@
die();
}
-if(get('getURL')) {
+if(get('getLoginURL')) {
$_SESSION['noLoginRedirect'] = 1;
header('Location: /login?login_token=' . $user->loginToken);
die();
@@ -44,26 +44,12 @@
header('Location: /login?login_token=' . $entity->loginToken);
die();
} else {
- // Set up a new user account
-
- $userID = Model_User::insert(array(
- 'username' => $account->screen_name,
- 'name' => $account->name,
- 'createdAt' => date('Y-m-d H:i:s'),
- 'createdBy' => 'twitter',
- 'userLevel' => 1,
- 'loginToken' => Model_User::generateLoginToken(),
- 'twitterID' => $account->id,
- 'twitterUsername' => $account->screen_name,
- 'twitterToken' => $token->oauth_token,
- 'twitterSecret' => $token->oauth_token_secret
- ));
- $user = new Model_User($userID);
-
- $user->addTwitter($account->screen_name);
-
- header('Location: /login?login_token=' . $newLoginToken);
- die();
+ // 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>';
}
}
@@ -74,44 +60,28 @@
{
login_error('Twitter Error', 'Unable to get an access token. Probably your request token has expired. Try logging in again.');
}
-}
-else if(get('go'))
-{
- // 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'));
+} 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']);
}
- catch(EpiOAuthException $e)
- {
- login_error('Twitter Error', 'Unable to get the authentication URL from Twitter: ' . $e->getMessage());
+ 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();
}
-
- header('Location: ' . $auth_url);
- die();
-}
-
-if(session('noLoginRedirect')) {
- echo '<div style="font-size: 22pt; margin-bottom: 10px;"><img src="/assets/tiny-contacts.png" width="282" height="20" /></div>';
- echo '<div style="padding: 15px; text-align: center;">Bookmark this page to automatically log in!</div>';
- unset($_SESSION['noLoginRedirect']);
}
-else {
-?>
-
-<div style="text-align: center;">
-
- <div style="font-size: 14pt; font-style: italic; width: 190px; margin: 0 auto;">graph anything</div>
-
- <div style="margin-top: 40px;"><a href="/login?go=1"><img src="/assets/sign-in-with-twitter-d.png" width="151" height="24" /></a></div>
-
- <div style="font-size: 9pt; margin-top: 60px;">You might also like <a href="http://geoloqi.com">Geoloqi</a></div>
-
-</div>
-
-<?php
-}
-
include('templates/footer.php');
View
@@ -1,5 +1,8 @@
<?php
+session_start();
+
unset($_SESSION['userID']);
+session_destroy();
header('Location: /');
View
@@ -0,0 +1,68 @@
+<?php
+include('inc.php');
+require_once('EpiCurl.php');
+require_once('EpiOAuth.php');
+require_once('EpiTwitter.php');
+
+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();
+
+ $user->addTwitterInfo($account->screen_name, $account->id, $token->oauth_token, $token->oauth_token_secret);
+
+ header('Location: /twitter_connect?confirmed');
+ die();
+ }
+ 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(array_key_exists('confirmed', $_GET)) {
+?>
+ <div style="text-align: center;">
+ <div style="font-size: 14pt; width: 190px; margin: 40px auto;">Looks good! You can go back to your<br /><a href="/list">list of graphs</a>.</div>
+ </div>
+<?php
+}
+else
+{
+ try
+ {
+ $auth_url = $twitter->getAuthorizeUrl(null, array('oauth_callback' => https() . $_SERVER['SERVER_NAME'] . '/twitter_connect'));
+ }
+ 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();
+}

0 comments on commit 43d17e8

Please sign in to comment.