Permalink
Browse files

fixing when twitter authentiction fails

  • Loading branch information...
peterbe committed Sep 18, 2011
1 parent a99d391 commit 5838cebee759d12a801fcc13c090bec0ffbb068f
Showing with 36 additions and 1 deletion.
  1. +8 −1 handlers.py
  2. +10 −0 templates/twitter_auth_failed.html
  3. +18 −0 tests/test_handlers.py
View
@@ -227,7 +227,8 @@ def get(self):
def _on_auth(self, user_struct):
if not user_struct:
- raise HTTPError(500, "Twitter auth failed")
+ self.redirect(self.reverse_url('auth_twitter_failed'))
+ return
username = user_struct.get('username')
self.redis.rpush('usernames', username)
#first_name = user_struct.get('first_name', user_struct.get('name'))
@@ -242,6 +243,12 @@ def _on_auth(self, user_struct):
expires_days=30, path='/')
self.redirect('/')
+@route('/auth/twitter/failed', name='auth_twitter_failed')
+class TwitterAuthFailedHandler(BaseAuthHandler):
+ def get(self):
+ options = {}
+ options['page_title'] = "Twitter authentication failed"
+ self.render('twitter_auth_failed.html', **options)
@route(r'/auth/logout/', name='logout')
class AuthLogoutHandler(BaseAuthHandler):
@@ -0,0 +1,10 @@
+{% extends "base.html" %}
+{% block content %}
+<h1>Sorry, Twitter's authentication link failed</h1>
+
+<p>Unfortunately, sometimes Twitter's server run over capacity and just simply don't work as
+expected. Most of them time, the solution is very simple...</p>
+
+<h2 style="padding:20px;text-align:center"><a href="{{ reverse_url('auth_twitter') }}">Try again &rarr;</a></h2>
+
+{% end %}
View
@@ -32,6 +32,24 @@ def test_twitter_login(self):
json.dumps({'key': '0123456789',
'secret': 'xxx'}))
+
+ def test_twitter_login_twitter_failing(self):
+ TwitterAuthHandler.get_authenticated_user = \
+ make_twitter_get_authenticated_user_callback(None)
+ url = self.reverse_url('auth_twitter')
+ response = self.client.get(url)
+ self.assertEqual(response.code, 302)
+ self.assertTrue('twitter.com' in response.headers['location'])
+
+ response = self.client.get(url, {'oauth_token':'xxx'})
+ self.assertEqual(response.code, 302)
+ to_url = self.reverse_url('auth_twitter')
+ self.assertTrue(to_url in response.headers['location'])
+
+ response = self.client.get(response.headers['location'])
+ self.assertEqual(response.code, 200)
+ self.assertTrue(to_url in response.body)
+
def _login(self, username=u'peterbe', name=u'Peter Bengtsson',
email=None):
struct = {

0 comments on commit 5838ceb

Please sign in to comment.