Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Using class based browserID …
Browse files Browse the repository at this point in the history
This gets a lot of mozillians specific code out and merges it upstream
to the django-browserID library
  • Loading branch information
tallowen committed Jan 28, 2012
1 parent a0cb407 commit ea4e1c8
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 62 deletions.
22 changes: 22 additions & 0 deletions apps/common/backends.py
@@ -1,5 +1,27 @@
from django.contrib.auth.models import User

from django_browserid.auth import BrowserIDBackend


class MozilliansBrowserID(BrowserIDBackend):
"""
Special auth backend to allow registration to work without a current
assertion. This is dangerous. Don't use authenticated_email unless you've
just verified somebody.
"""

def authenticate(self, assertion=None, audience=None, authenticated_email=None):
if authenticated_email:
users = User.objects.filter(email=email)
if len(users) > 1:
log.warn('%d users with email address %s.' % (len(users), email))
return None
if len(users) == 1:
return users[0]

return super(MozilliansBrowserID, self).authenticate(
assertion=assertion, audience=audience)


class TestBackend(object):
supports_inactive_user = True
Expand Down
49 changes: 0 additions & 49 deletions apps/users/browserid_views.py

This file was deleted.

3 changes: 3 additions & 0 deletions apps/users/urls.py
Expand Up @@ -13,6 +13,9 @@
urlpatterns = patterns('',
url(r'^logout$', views.logout, name='logout'),
url(r'^confirm$', redirect_to, dict(url='/', name='home')),
url('^browserid/verify/', views.Browserid.as_view(),
name='browserid_verify'),

# This sucks: we should not have to do this, but a lot of people/libraries/
# existing code is looking for this view.
url(r'^login$', redirect_to, dict(url='/', name='home'), name='login'),
Expand Down
22 changes: 17 additions & 5 deletions apps/users/views.py
Expand Up @@ -5,6 +5,8 @@
from django.shortcuts import redirect, render

import commonware.log
from django_browserid.auth import get_audience
from django_browserid.views import Verify
from funfactory.urlresolvers import reverse
from tower import ugettext as _

Expand All @@ -27,6 +29,18 @@ def logout(request, **kwargs):
return auth_views.logout(request, next_page=reverse('home'), **kwargs)


class Browserid(Verify):
"""View for dealing with Browserid callback"""

def handle_user(self, request, user):
if user.get_profile().is_complete():
auth.login(request, user)
return redirect(reverse('profile', args=[user.username]))
else:
request.session['authenticated_email'] = user.email
return redirect(reverse('register'))


def password_reset_confirm(request, uidb36=None, token=None):
"""TODO: Legacy URL, keep around until 1.4 release."""
return redirect('home')
Expand All @@ -46,14 +60,12 @@ def register(request):
if request.user.is_authenticated():
return redirect(reverse('profile', args=[request.user.username]))

assertion = request.session.get('assertion')
audience = request.session.get('audience')
if not (assertion and audience):
authenticated_email = request.session.get('authenticated_email')
if not authenticated_email:
log.error('Browserid registration, but no verified email in session')
return redirect('home')

user = auth.authenticate(assertion=assertion,
audience=audience)
user = auth.authenticate(authenticated_email=authenticated_email)
if not user:
return redirect('home')

Expand Down
6 changes: 1 addition & 5 deletions media/js/infinite.js
Expand Up @@ -10,11 +10,7 @@
results.hide();

// If there is no paginator, don't do any scrolling
if (pages == undefined) {
cease = true;
} else {
cease = false;
}
cease = (pages == undefined)

$(document).endlessScroll({
// Number of pixels from the bottom at which callback is triggered
Expand Down
2 changes: 1 addition & 1 deletion settings/default.py
Expand Up @@ -92,7 +92,7 @@
# OpenLDAP
LDAP_USERS_GROUP = 'ou=people,dc=mozillians,dc=org'

AUTHENTICATION_BACKENDS = ('django_browserid.auth.BrowserIDBackend',)
AUTHENTICATION_BACKENDS = ('common.backends.MozilliansBrowserID',)

#BrowserID creates useer if one doesn't exist
BROWSERID_CREATE_USER = True
Expand Down
1 change: 0 additions & 1 deletion urls.py
Expand Up @@ -23,7 +23,6 @@ def error_page(request, template, status=None):
handler_csrf = lambda r, cb=None: error_page(r, 'csrf_error', status=400)

urlpatterns = patterns('',
url('^browserid/verify/', 'users.browserid_views.verify', name='browserid_verify'),
(r'', include('users.urls')),
(r'', include('groups.urls')),

Expand Down
2 changes: 1 addition & 1 deletion vendor
Submodule vendor updated 3 files
+3 −3 .gitmodules
+1 −1 src/django-browserid
+1 −0 vendor.pth

0 comments on commit ea4e1c8

Please sign in to comment.