Skip to content
Snippets Groups Projects
Commit c49722fa authored by Ben Adida's avatar Ben Adida
Browse files

added ability to reauth with facebook when authentication has failed, either...

added ability to reauth with facebook when authentication has failed, either because no groups permission or just stale token.
parent 49e09eb5
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,11 @@ def facebook_url(url, params):
def facebook_get(url, params):
full_url = facebook_url(url,params)
try:
return urllib2.urlopen(full_url).read()
except urllib2.HTTPError:
from auth.models import AuthenticationExpired
raise AuthenticationExpired()
def facebook_post(url, params):
full_url = facebook_url(url, None)
......
......@@ -14,6 +14,9 @@ import datetime, logging
from auth_systems import AUTH_SYSTEMS, can_check_constraint, can_list_categories
# an exception to catch when a user is no longer authenticated
class AuthenticationExpired(Exception):
pass
class User(models.Model):
user_type = models.CharField(max_length=50)
......
......@@ -23,6 +23,7 @@ from view_utils import *
from auth.security import *
from auth.auth_systems import AUTH_SYSTEMS, can_list_categories
from auth.models import AuthenticationExpired
from helios import security
from auth import views as auth_views
......@@ -304,7 +305,16 @@ def one_election_view(request, election):
voter = Voter.get_by_election_and_user(election, user)
if not voter:
try:
eligible_p = _check_eligibility(election, user)
except AuthenticationExpired:
# FIXME: should we be wary of infinite redirects here, and
# add a parameter to prevent it? Maybe.
login_url = "%s%s?%s" % (settings.SECURE_URL_HOST,
reverse(auth_views.start, args=[user.user_type]),
urllib.urlencode({'return_url':
request.get_full_path()}))
return HttpResponseRedirect(login_url)
notregistered = True
else:
voter = get_voter(request, user, election)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment