# HG changeset patch # User Brian Neal # Date 1352948225 21600 # Node ID f36d1a168be7fb62721d5d4eeac6b5f6d8effbb0 # Parent 63603e9315038eb6046923c081d8847059c133cb For issue 27, disable login dialog button during POST. This seems to prevent multiple logins most of the time. You can still bang on the enter key and sometimes get more through. diff -r 63603e931503 -r f36d1a168be7 accounts/static/js/ajax_login.js --- a/accounts/static/js/ajax_login.js Wed Nov 14 17:47:01 2012 -0600 +++ b/accounts/static/js/ajax_login.js Wed Nov 14 20:57:05 2012 -0600 @@ -7,55 +7,69 @@ height: 375, width: 380, modal: true, - buttons: { - "Login": function() { - loginError.text('').hide(); - $.ajax({ - url: '/accounts/login/ajax/', - type: 'POST', - data: { - username: userBox.val(), - password: passBox.val(), - csrfmiddlewaretoken: csrf_token - }, - dataType: 'json', - success: function(data, textStatus) { - if (data.success) { - loginDialog.dialog("close"); - if (window.location.pathname == "/accounts/logout/") { - window.location.replace("/"); + buttons: [ + { + id: "login-button", + text: "Login", + click: function() { + loginError.text('').hide(); + $("#login-button").button("disable"); + $.ajax({ + url: '/accounts/login/ajax/', + type: 'POST', + data: { + username: userBox.val(), + password: passBox.val(), + csrfmiddlewaretoken: csrf_token + }, + dataType: 'json', + success: function(data, textStatus) { + $("#login-button").button("enable"); + if (data.success) { + loginDialog.dialog("close"); + if (window.location.pathname == "/accounts/logout/") { + window.location.replace("/"); + } + else { + $('#header-nav').html(data.navbar_html); + } } else { - $('#header-nav').html(data.navbar_html); + loginError.text(data.error).show(); + userBox.val(''); + passBox.val(''); + userBox.focus(); + } + }, + error: function (xhr, textStatus, ex) { + $("#login-button").button("enable"); + if (xhr.status == 403) { + loginDialog.dialog("close"); + alert("Oops, we are detecting some strange behavior and are blocking this action. If you feel this is an error, please feel free to contact us. Thank you."); + window.location.href = "/"; + } + else { + loginError.text('Oops, an error occurred. If this problem persists, please contact us.').show(); } } - else { - loginError.text(data.error).show(); - userBox.val(''); - passBox.val(''); - userBox.focus(); - } - }, - error: function (xhr, textStatus, ex) { - if (xhr.status == 403) { - loginDialog.dialog("close"); - alert("Oops, we are detecting some strange behavior and are blocking this action. If you feel this is an error, please feel free to contact us. Thank you."); - window.location.href = "/"; - } - else { - loginError.text('Oops, an error occurred. If this problem persists, please contact us.').show(); - } - } - }); + }); + } }, - "Cancel": function() { - loginDialog.dialog("close"); + { + id: "cancel-button", + text: "Cancel", + click: function() { + loginDialog.dialog("close"); + } } - }, + ], focus: function() { $(':input', this).keyup(function(event) { if (event.keyCode == 13) { - $('.ui-dialog-buttonpane button:first').click(); + var loginButton = $("#login-button"); + if (!loginButton.button("option", "disabled")) { + loginButton.click(); + } } }); }