Initial version
form-to-http-auth.js
Wed Oct 27 04:18:01 UTC 2010 pix@kepibu.org
* Initial version
--- old-httpauth/form-to-http-auth.js 1970-01-01 00:00:00.000000000 +0000
+++ new-httpauth/form-to-http-auth.js 2015-04-15 14:59:07.000000000 +0000
@@ -0,0 +1,45 @@
+(function () {
+ function hasClass(node,className) {
+ return node.className.match(new RegExp('(\\s|^)'+className+'(\\s|$)'));
+ }
+ function form2httpAuth () {
+ /* Skip if the browser indicates it does this itself. */
+ if (this.className.match(/(\\s|^)natively-supported(\\s|$)/))
+ return true;
+ /* Force the browser to clear the auth credentials. */
+ /*
+ var xhr = $.ajax({
+ url: "/ajax-login.php",
+ async: true,
+ global: false,
+ username: "-",
+ password: "-",
+ dataType: "text"
+ });
+ xhr.abort();
+ */
+ /* Attempt login with provided credentials. */
+ var username = this.username.value;
+ var password = this.password.value;
+ var authed = false;
+ $.ajax({
+ url: "/ajax-login.php",
+ async: false,
+ global: false,
+ username: username,
+ password: password,
+ dataType: 'text',
+ success: function (data, status, xhr) {
+ authed = true;
+ }
+ });
+ /* 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);
+ }
+ return true;
+ }
+
+ $("form.http-authentication").submit(form2httpAuth);
+})();