Skip to content

Commit

Permalink
BrowserID settings and example user authentication flow.
Browse files Browse the repository at this point in the history
  • Loading branch information
rfreebern committed Jun 2, 2012
1 parent 0e83d96 commit 883366d
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
8 changes: 8 additions & 0 deletions project/examples/models.py
@@ -0,0 +1,8 @@
from django.contrib.auth.models import User


# User class extensions
def user_unicode(self):
"""Use email address for string representation of user."""
return self.email
User.add_to_class('__unicode__', user_unicode)
19 changes: 18 additions & 1 deletion project/examples/templates/examples/home.html
Expand Up @@ -5,6 +5,17 @@ <h1>
<a href="/">{{ _('Hello world') }}</a>
</h1>

{% if request.user.is_active %}
<p>{{ _('You are logged in as {username}')|f(username=request.user) }}.
<a href="{{ url('examples.logout') }}">{{ _('Log out') }}</a></p>
{% else %}
<p><a id="browserid" href="#">{{ _('Log in with BrowserID') }}</a></p>
<form method="POST" action="{{ url('browserid_verify') }}">
{{ csrf() }}
{{ browserid_form.as_p() }}
</form>
{% endif %}

{# L10n: This is a localizer comment #}
{% if request.MOBILE %}
<p>{{ _('This is a <em>test view</em> for mobile browsers.') }}</p>
Expand All @@ -15,7 +26,7 @@ <h1>
{% trans docs_url='http://playdoh.rtfd.org/' %}
<a href="{{ docs_url }}">Learn you some Playdoh</a> and then go build
something <strong>awesome</strong>.
{% endtrans %}
{% endtrans %}
</p>
<p>
{% trans langs=LANGUAGES.items() %}
Expand All @@ -28,3 +39,9 @@ <h1>
<li><a href="{{ url('examples.bleach') }}">Input sanitization with Bleach</a></li>
</ul>
{% endblock %}
{% block site_js %}
{{ js('example_js') }}
{% if not request.user.is_active %}
{{ browserid_form.media }}
{% endif %}
{% endblock %}
3 changes: 3 additions & 0 deletions project/examples/urls.py
Expand Up @@ -5,5 +5,8 @@

urlpatterns = patterns('',
url(r'^$', views.home, name='examples.home'),
url(r'^browserid/', include('django_browserid.urls')),
url(r'^logout/?$', 'django.contrib.auth.views.logout', {'next_page': '/'},
name='examples.logout'),
url(r'^bleach/?$', views.bleach_test, name='examples.bleach'),
)
1 change: 0 additions & 1 deletion project/examples/views.py
Expand Up @@ -2,7 +2,6 @@

import logging

from django import http
from django.shortcuts import render

import bleach
Expand Down
18 changes: 18 additions & 0 deletions project/settings/base.py
Expand Up @@ -47,6 +47,24 @@
'registration',
]

# BrowserID configuration
AUTHENTICATION_BACKENDS = [
'django_browserid.auth.BrowserIDBackend',
'django.contrib.auth.backends.ModelBackend',
]

SITE_URL = 'http://127.0.0.1:8000'
LOGIN_URL = '/'
LOGIN_REDIRECT_URL = 'examples.home'
LOGIN_REDIRECT_URL_FAILURE = 'examples.home'

TEMPLATE_CONTEXT_PROCESSORS = list(TEMPLATE_CONTEXT_PROCESSORS) + [
'django_browserid.context_processors.browserid_form',
]

# Always generate a CSRF token for anonymous users.
ANON_ALWAYS = True

# Tells the extract script what files to look for L10n in and what function
# handles the extraction. The Tower library expects this.
DOMAIN_METHODS['messages'] = [
Expand Down
4 changes: 4 additions & 0 deletions project/settings/local.py-dist
Expand Up @@ -43,6 +43,10 @@ DEBUG = TEMPLATE_DEBUG = True
# instances and False on stage/prod.
DEV = True

# By default, BrowserID expects your app to use http://127.0.0.1:8000
# Uncomment the following line if you prefer to access your app via localhost
# SITE_URL = 'http://localhost:8000'

# # Playdoh ships with sha512 password hashing by default. Bcrypt+HMAC is safer,
# # so it is recommended. Please read <https://github.com/fwenzel/django-sha2#readme>,
# # uncomment the bcrypt hasher and pick a secret HMAC key for your application.
Expand Down

0 comments on commit 883366d

Please sign in to comment.