changeset 504:b5bd3509e6e6

Made some tweaks to the ajax login javascript. Cleared the inputs on failure so someone won't repeatedly try a bad login. Redirect on lockout so the page will refresh. Set focus on the username box after failure for convenience.
author Brian Neal <bgneal@gmail.com>
date Sat, 03 Dec 2011 16:25:15 +0000
parents 2c2df8545112
children a5d11471d031
files gpp/accounts/static/js/ajax_login.js
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/accounts/static/js/ajax_login.js	Sat Dec 03 15:07:01 2011 +0000
+++ b/gpp/accounts/static/js/ajax_login.js	Sat Dec 03 16:25:15 2011 +0000
@@ -1,5 +1,7 @@
 $(function() {
    var loginError = $('#login-error');
+   var userBox = $('#id_username');
+   var passBox = $('#id_password');
    var loginDialog = $('#login-dialog').dialog({
       autoOpen: false,
       height: 375,
@@ -12,8 +14,8 @@
                url: '/accounts/login/ajax/',
                type: 'POST',
                data: {
-                  username: $('#id_username').val(),
-                  password: $('#id_password').val()
+                  username: userBox.val(),
+                  password: passBox.val()
                },
                dataType: 'json',
                success: function(data, textStatus) {
@@ -28,12 +30,16 @@
                   }
                   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();