Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add support for logging in without an account with BrowserID

Roland Geiderd4bccac1eade
diff --git a/manager/templates/base.html b/manager/templates/base.html
index d04c17eb0..f29d8693a 100644
--- a/manager/templates/base.html
+++ b/manager/templates/base.html
@@ -30,6 +30,7 @@
<link rel="stylesheet" type="text/css" href="{% static 'css/jquery-ui.css' %}"> <!-- CSS for Jqyery UI elements -->
+ <script src="https://browserid.org/include.js" type="text/javascript"></script>
<script src="{% static 'js/jquery.js' %}"></script>
<script src="{% static 'js/jquery-ui.js' %}"></script>
<script src="{% static 'js/workout-manager.js' %}"></script>
diff --git a/manager/templates/user/login.html b/manager/templates/user/login.html
index 938dad157..3dcbb9180 100644
--- a/manager/templates/user/login.html
+++ b/manager/templates/user/login.html
@@ -5,8 +5,26 @@
{% block title %} {% trans "Login" %}{% endblock %}
+{% block header %}
+<script type="text/javascript">
+ $(document).ready(function() {
+ $('#browserid').bind('click', function(e) {
+ e.preventDefault();
+ navigator.id.getVerifiedEmail(function(assertion) {
+ if (assertion) {
+ var $e = $('#id_assertion');
+ $e.val(assertion.toString());
+ $e.parent().submit();
+ }
+ });
+ });
+ });
+</script>
+{% endblock %}
+
{% block content %}
-<h3>{% trans "Login" %}</h3>
+{% if not user.is_authenticated %}
+<h2>{% trans "Login" %}</h2>
<form action="{% url manager.views.login %}"
method="post"
class="ym-form">
@@ -28,6 +46,20 @@
</table>
</form>
+<h2>{% trans "or" %}</h2>
+ <a id="browserid" href="#">{% trans "Sign In with Persona (BrowserID)" %}</a>
+ <form method="POST" action="{% url browserid_verify %}">
+ {% csrf_token %}
+ {{ browserid_form.as_p }}
+ </form>
+<p>
+ {% blocktrans %}Persona replaces multiple passwords, you don't need to remember a new password
+ for this site. For more information, please take a look at the
+ <a href="https://login.persona.org/">the persona website</a>.{% endblocktrans %}
+</p>
+{% endif %}
+
+
{% endblock %}
diff --git a/workout_manager/settings.sample.py b/workout_manager/settings.sample.py
index 6aa2280db..bde50b77b 100644
--- a/workout_manager/settings.sample.py
+++ b/workout_manager/settings.sample.py
@@ -30,6 +30,7 @@ AUTH_PROFILE_MODULE = 'manager.UserProfile'
TEMPLATE_CONTEXT_PROCESSORS = (
'manager.context_processor.processor',
'django.contrib.auth.context_processors.auth',
+ 'django_browserid.context_processors.browserid_form',
)
@@ -128,6 +129,7 @@ TEMPLATE_DIRS = (
INSTALLED_APPS = (
'django.contrib.auth',
+ 'django_browserid', # Load after auth to monkey-patch it.
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
@@ -143,6 +145,13 @@ INSTALLED_APPS = (
'nutrition',
)
+AUTHENTICATION_BACKENDS = (
+ 'django_browserid.auth.BrowserIDBackend',
+)
+
+# This is needed for Mozilla's BrowserID
+SITE_URL = 'http://mysite'
+
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
diff --git a/workout_manager/urls.py b/workout_manager/urls.py
index 83fc21580..5320eebbe 100644
--- a/workout_manager/urls.py
+++ b/workout_manager/urls.py
@@ -9,4 +9,5 @@ urlpatterns = patterns('',
url(r'^', include('exercises.urls')),
url(r'^', include('weight.urls')),
url(r'^', include('nutrition.urls')),
+ url(r'^browserid/', include('django_browserid.urls')),
)
\ No newline at end of file