Self hosted FLOSS fitness/workout, nutrition and weight tracker
Update to django_browserid 0.8 and make appropriate API changes.
Roland Geider9ec496ca1a6d
diff --git a/requirements.txt b/requirements.txtindex 71ced8ad1..f7206a76b 100644--- a/requirements.txt+++ b/requirements.txt@@ -1,9 +1,9 @@Django==1.4.5-django-browserid==0.7.1+django-browserid==0.8django-recaptchareportlabdjango_mobiledjango-discover-runnerpep8bleach-south\ No newline at end of file+southdiff --git a/wger/manager/static/js/browserid.js b/wger/manager/static/js/browserid.jsindex 8a52a6317..0438ae3a3 100644--- a/wger/manager/static/js/browserid.js+++ b/wger/manager/static/js/browserid.js@@ -5,64 +5,83 @@(function($) {'use strict';- // If there are problems initialising the browserID javascript- // don't try to setup the watchers- try{- navigator.id.watch;- }- catch(error)- {- console.debug('navigator.id not available. Login with Persona not possible.');- return;- }-$(function() {- var requestOptions = [- 'siteName',- 'siteLogo',- 'oncancel',- 'privacyPolicy',- 'returnTo',- 'termsOfService'- ];++ // If there are problems initialising the browserID javascript+ // don't try to setup the watchers+ try{+ navigator.id.watch;+ }+ catch(error)+ {+ console.debug('navigator.id not available. Login with Persona not possible.');+ return;+ }- $(document).delegate('.browserid-login, #browserid', 'click', function(e) {- e.preventDefault();+ // State? Ewwwwww.+ var loginRedirect = null; // Path to redirect to post-login.+ var logoutRedirect = null; // Path to redirect to post-logout.- // Arguments to navigator.id.request can be specified by data-attributes- // on the BrowserID link: <a href="#" data-site-name="Site Name">- var options = {};- var $link = $(e.target);- for (var k = 0; k < requestOptions.length; k++) {- var name = requestOptions[k];- var value = $link.data(name);- if (value !== undefined) {- options[name] = value;- }- }+ var $loginForm = $('#browserid-form'); // Form used to submit login.+ var $browseridInfo = $('#browserid-info'); // Useful info from backend.++ var requestArgs = $browseridInfo.data('requestArgs') || {};+ var loginFailed = location.search.indexOf('bid_login_failed=1') !== -1;++ // Call navigator.id.request whenever a login link is clicked.+ $(document).on('click', '.browserid-login', function(e) {+ e.preventDefault();- navigator.id.request(options); // Triggers BrowserID login dialog.+ loginRedirect = $(this).data('next');+ navigator.id.request(requestArgs);});- $('.browserid-logout').bind('click', function(e) {- // Clears User Agent BrowserID state.+ // Call navigator.id.logout whenever a logout link is clicked.+ $(document).on('click', '.browserid-logout', function(e) {+ // Roland: Commented out+ //e.preventDefault();++ logoutRedirect = $(this).attr('href');navigator.id.logout();});navigator.id.watch({-+ loggedInUser: $browseridInfo.data('userEmail') || null,onlogin: function(assertion) {+ // Avoid auto-login on failure.+ if (loginFailed) {+ loginFailed = false;+ return;+ }+if (assertion) {- var $e = $('#id_assertion');- $e.val(assertion.toString());- $e.parent().submit();+ $loginForm.find('input[name="next"]').val(loginRedirect);+ $loginForm.find('input[name="assertion"]').val(assertion);+ $loginForm.submit();}},-onlogout: function() {- // No functionality here- //console.debug('navigator.id.watch onLogout');+ // Follow the logout link's href once logout is complete.++ var currentLogoutUrl = logoutRedirect;+ if (currentLogoutUrl !== null) {+ logoutRedirect = null;+ window.location = currentLogoutUrl;+ } else {+ // Sometimes you can get caught in a loop where BrowserID+ // keeps trying to log you out as soon as watch is called,+ // and fails since the logout URL hasn't been set yet.+ // Here we just find the first logout button and use that+ // URL; if this breaks your site, you'll just need custom+ // JavaScript instead, sorry. :(+ currentLogoutUrl = $('.browserid-logout').attr('href');+ if (currentLogoutUrl) {+ // Roland: commented out+ // window.location = currentLogoutUrl;+ }+ }}});});})(jQuery);+diff --git a/wger/manager/templates/template.html b/wger/manager/templates/template.htmlindex 30df2ce06..a56e4e7ba 100644--- a/wger/manager/templates/template.html+++ b/wger/manager/templates/template.html@@ -1,5 +1,6 @@<!DOCTYPE html>{% load i18n %}+{% load browserid %}{% load url from future %}{% load staticfiles %}<html lang="{{language.short_name}}">@@ -67,6 +68,7 @@<title>{% block title %}{% endblock %}</title></head><body>+{% browserid_info %}<header><div class="ym-wrapper"><div class="ym-wbox">diff --git a/wger/manager/templates/user/login.html b/wger/manager/templates/user/login.htmlindex 646b6570a..eb0dad7e7 100644--- a/wger/manager/templates/user/login.html+++ b/wger/manager/templates/user/login.html@@ -1,5 +1,6 @@{% extends "base.html" %}{% load url from future %}+{% load browserid %}{% load i18n %}{% load staticfiles %}{% load manager_extras %}@@ -39,14 +40,11 @@<div style="padding-top:1em;"></div><a id="browserid-login"href="#"- class="persona-button dark browserid-login"- data-site-name="Workout Manager">+ class="browserid-login persona-button dark browserid-login"+ data-site-name="Workout Manager"+ data-next="/"><span>{% trans "Sign in with your Email" %}</span></a>- <form method="POST" action="{% url 'browserid_verify' %}" id="browserid-form">- {% csrf_token %}- {{ browserid_form.as_p }}- </form></div><p>diff --git a/wger/settings_global.py b/wger/settings_global.pyindex 93f205e1f..0e7514098 100644--- a/wger/settings_global.py+++ b/wger/settings_global.py@@ -56,7 +56,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ('wger.manager.context_processor.processor','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages',- 'django_browserid.context_processors.browserid_form',+ 'django_browserid.context_processors.browserid',)# Store the user messages in the session