Wed Oct 27 22:01:20 UTC 2010 pix@kepibu.org
* Mention hanging on synchronous requests
diff -rN -u old-httpauth/form-to-http-auth.js new-httpauth/form-to-http-auth.js
--- old-httpauth/form-to-http-auth.js 2015-04-17 10:03:44.000000000 +0000
+++ new-httpauth/form-to-http-auth.js 2015-04-17 10:03:44.000000000 +0000
@@ -3,12 +3,15 @@
/* Skip if the browser indicates it does this itself. */
if (this.className.match(/(\\s|^)natively-supported(\\s|$)/))
return true;
+
/* Attempt login with provided credentials. */
var username = this.username.value;
var password = this.password.value;
var authed = false;
+ var form = this;
$.ajax({
url: "/ajax-login.php",
+ /* synchronous hangs some browsers temporarily. :/ */
async: false,
global: false,
username: username,
@@ -16,13 +19,21 @@
dataType: 'text',
success: function (data, status, xhr) {
authed = true;
+ },
+ error: function (xhr, status, err) {
+ authed = false;
+ },
+ complete: function (xhr, status) {
+ /* Don't send username and password if we successfully managed to auth via HTTP */
+ if (authed) {
+ form.username.parentNode.removeChild(form.username);
+ form.password.parentNode.removeChild(form.password);
+ }
}
});
- /* Don't send username and password if we successfully managed to auth via HTTP */
- if (authed) {
- this.username.parentNode.removeChild(this.username);
- this.password.parentNode.removeChild(this.password);
- }
+
+ /* This is the only way to get browsers to submit the form exactly as
+ the user did, which is why we aren't using async above. */
return true;
}