Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Use navigator.id.watch for BrowserID, which is more flexible

Roland Geiderc112d38313a5
diff --git a/manager/templates/base.html b/manager/templates/base.html
index f29d8693a..10231be75 100644
--- a/manager/templates/base.html
+++ b/manager/templates/base.html
@@ -37,9 +37,44 @@
{% block header %}{% endblock %}
<script>
+ navigator.id.watch({
+ loggedInUser: {% if user.is_authenticated %}"{{user.email}}"{% else %}null{% endif %},
+ onlogin: function(assertion) {
+
+ var $e = $('#id_assertion');
+ $e.val(assertion.toString());
+
+ $.ajax({
+ type: 'POST',
+ url: $('#browserid-form').attr('action'),
+ data: $('#browserid-form').serialize(),
+ success: function(res, status, xhr) { window.location = '/'; },
+ error: function(xhr, status, err) { alert("login failure: " + err); }
+ });
+ },
+ onlogout: function() {
+ $.ajax({
+ type: 'POST',
+ url: '/logout',
+ success: function(res, status, xhr) { window.location.reload(); },
+ error: function(xhr, status, err) { alert("logout failure: " + err); }
+ });
+ }
+ });
+
+
$(document).ready(function() {
- // Init the modal dialog for editing forms
- form_modal_dialog();
+
+ $('#browserid-login').bind('click', function(e) {
+ navigator.id.request({siteName: 'Workout Manager'});
+ });
+
+ $('#logout').bind('click', function(e) {
+ navigator.id.logout();
+ });
+
+ // Init the modal dialog for editing forms
+ form_modal_dialog();
});
</script>
@@ -74,7 +109,7 @@
{% if user.username %}
<ul style="float:right;">
<li>
- <a href="{% url manager.views.logout %}">
+ <a href="{% url manager.views.logout %}" id="logout">
{% trans 'Logout' %}
</a>
</li>
diff --git a/manager/templates/user/login.html b/manager/templates/user/login.html
index 047ec35a8..274649ef0 100644
--- a/manager/templates/user/login.html
+++ b/manager/templates/user/login.html
@@ -7,20 +7,6 @@
{% block header %}
<link rel="stylesheet" href="{% static 'css/persona-buttons.css' %}" />
-<script type="text/javascript">
- $(document).ready(function() {
- $('#browserid').bind('click', function(e) {
- e.preventDefault();
- navigator.id.get(function(assertion) {
- if (assertion) {
- var $e = $('#id_assertion');
- $e.val(assertion.toString());
- $e.parent().submit();
- }
- });
- });
- });
-</script>
{% endblock %}
{% block content %}
@@ -48,12 +34,12 @@
</form>
<h2>{% trans "or" %}</h2>
- <a id="browserid"
+ <a id="browserid-login"
href="#"
class="persona-button dark">
<span>{% trans "Sign in with your Email" %}</span>
</a>
- <form method="POST" action="{% url browserid_verify %}">
+ <form method="POST" action="{% url browserid_verify %}" id="browserid-form">
{% csrf_token %}
{{ browserid_form.as_p }}
</form>