Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Switch to BrowserID for reg and auth

  • Loading branch information...
commit 8088f70f0c50c28298b3bc00d2734d43b1a20d84 1 parent 4abe4c8
@lmorchard authored
View
4 media/css/main.css
@@ -21,8 +21,8 @@ header#masthead .logo a {
header#masthead nav {
color: #EEEEEE;
position: absolute;
- right: 1em;
- top: 1em;
+ right: 3em;
+ top: 1.5em;
}
header#masthead nav a {
View
4 media/js/main.js
@@ -3,9 +3,9 @@
*/
$(document).ready(function () {
- $('.browserid-signin').click(function (ev) {
+ $('.browserid-signin').click(function (e) {
e.preventDefault();
- navigator.getVerifiedEmail(function(assertion) {
+ navigator.id.getVerifiedEmail(function(assertion) {
if (assertion) {
var $e = $('#id_assertion');
$e.val(assertion.toString());
View
1  requirements/dev.txt
@@ -16,6 +16,7 @@ Sphinx==1.0.6
# Testing
nose==1.0.0
+fudge==1.0.3
-e git://github.com/jbalogh/django-nose.git#egg=django_nose
-e git://github.com/jbalogh/test-utils.git#egg=test-utils
View
2  requirements/prod.txt
@@ -24,6 +24,8 @@ Babel>=0.9.4
-e git://github.com/clouserw/tower.git#egg=tower
-e git://github.com/fwenzel/django-mozilla-product-details#egg=django-mozilla-product-details
+# Auth
+-e hg+https://code.google.com/p/httplib2/@6525cadfde53#egg=httplib2
-e git://github.com/mozilla/django-browserid.git#egg=django-browserid
# Apps
View
25 settings.py
@@ -60,23 +60,28 @@
'south',
)
+TEMPLATE_CONTEXT_PROCESSORS = TEMPLATE_CONTEXT_PROCESSORS + (
+ 'django_browserid.context_processors.browserid_form',
+)
+
+
AUTHENTICATION_BACKENDS = (
- # ...
'django_browserid.auth.BrowserIDBackend',
- # ...
)
-# URL of a BrowserID verification service.
BROWSERID_VERIFICATION_URL = 'https://browserid.org/verify'
+BROWSERID_CREATE_USER = True
-# CA cert file for validating SSL certificate
-BROWSERID_CACERT_FILE = ''
+def username_algo(email):
+ from django.contrib.auth.models import User
+ cnt, base_name = 0, email.split('@')[0]
+ username = base_name
+ while User.objects.filter(username=username).count() > 0:
+ cnt += 1
+ username = '%s_%s' % (base_name, cnt)
+ return username
-# Create user accounts automatically if no user is found.
-BROWSERID_CREATE_USER = False
+BROWSERID_USERNAME_ALGO = username_algo
-# Path to redirect to on successful login.
LOGIN_REDIRECT_URL = '/'
-
-# Path to redirect to on unsuccessful login attempt.
LOGIN_REDIRECT_URL_FAILURE = '/'
View
25 templates/base.html
@@ -28,19 +28,18 @@
</div>
<nav>
{% if request.user.is_authenticated() %}
- <a href="{{url('django.contrib.auth.views.logout')}}">Logout</a>
- -
- <a href="{{url('django.contrib.auth.views.password_change')}}">Change password</a>
- <br />
- Welcome back, <a href="{{url('badger.views.awards_by_user', request.user.username)}}">{{ request.user }}</a>
+ {{ _('Welcome back, <a href="{user_url}">{user_name}</a>') | f(
+ user_url=url('badger.views.awards_by_user', request.user.username),
+ user_name=request.user) | safe }}
+ (
+ <a href="{{url('django.contrib.auth.views.logout')}}">{{_('settings')}}</a>,
+ <a href="{{url('django.contrib.auth.views.logout')}}">{{_('logout')}}</a>
+ )
{% else %}
- <a href="{{url('registration.views.register')}}">Register</a>
- -
- <a href="{{url('django.contrib.auth.views.login')}}">Login</a>
- {#
- -
- <a href="#" class="browserid-signin" title="{{_('Sign In with BrowserID')}}"><img src="{{MEDIA_URL}}img/sign_in_blue.png" /></a>
- #}
+ <form action="{{url('browserid_verify')}}" method="POST">
+ <a href="#" class="browserid-signin" title="{{_('Sign In with BrowserID')}}"><img src="{{MEDIA_URL}}img/sign_in_blue.png" /></a>
+ {{ browserid_form }}
+ </form>
{% endif %}
</nav>
</header>
@@ -55,7 +54,7 @@
</footer>
{% block site_js %}
- <!-- <script src="https://browserid.org/include.js" type="text/javascript"></script> -->
+ <script src="https://browserid.org/include.js" type="text/javascript"></script>
{{ js('main') }}
{% for script in scripts %}
{{ js(script) }}
View
13 urls.py
@@ -12,6 +12,10 @@
from badger import Progress
from badger_multiplayer.models import Badge, Award, Nomination
+from session_csrf import anonymous_csrf_exempt
+import django_browserid.views
+
+
urlpatterns = patterns('',
url(r'^$', direct_to_template, dict(
@@ -29,13 +33,16 @@
(r'^comments/', include('django.contrib.comments.urls')),
- (r'^accounts/', include('django.contrib.auth.urls')),
+ (r'^accounts/', include('django.contrib.auth.urls')),
(r'^accounts/', include('registration.backends.default.urls')),
- (r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/', include(admin.site.urls)),
- (r'^browserid/', include('django_browserid.urls')),
+ #(r'^browserid/', include('django_browserid.urls')),
+ # HACK: CSRF troubles wth browserid auth
+ url(r'^browserid/verify/',
+ anonymous_csrf_exempt(django_browserid.views.verify),
+ name="browserid_verify"),
)
Please sign in to comment.
Something went wrong with that request. Please try again.