Support simple auth form.

master
Jason A. Donenfeld 2012-08-11 01:47:11 +02:00
parent b41ad8c91e
commit 499614eab0
2 changed files with 38 additions and 5 deletions

View File

@ -34,8 +34,11 @@
callback(album);
}
};
if (typeof error !== "undefined" && error !== null)
ajaxOptions.error = error;
if (typeof error !== "undefined" && error !== null) {
ajaxOptions.error = function(jqXHR, textStatus, errorThrown) {
error(jqXHR.status);
};
}
$.ajax(ajaxOptions);
};
PhotoFloat.prototype.albumPhoto = function(subalbum, callback, error) {
@ -85,6 +88,19 @@
callback(theAlbum, photo, i);
}, error);
};
PhotoFloat.prototype.authenticate = function(password, result) {
$.ajax({
type: "GET",
dataType: "text",
url: "auth?password=" + password,
success: function() {
result(true);
},
error: function() {
result(false);
}
});
};
/* static functions */
PhotoFloat.cachePath = function(path) {

View File

@ -228,13 +228,17 @@ $(document).ready(function() {
/* Error displays */
function die() {
function die(error) {
if (error == 403) {
$("#auth-text").fadeIn(1000);
$("#password").focus();
} else
$("#error-text").fadeIn(2500);
$("#error-overlay").fadeTo(500, 0.8);
$("#error-text").fadeIn(2500);
$("body, html").css("overflow", "hidden");
}
function undie() {
$("#error-text, #error-overlay").fadeOut(500);
$("#error-text, #error-overlay, #auth-text").fadeOut(500);
$("body, html").css("overflow", "auto");
}
@ -332,4 +336,17 @@ $(document).ready(function() {
$("#metadata-link").text($("#metadata-link").text().replace("hide", "show"));
});
});
$("#auth-form").submit(function() {
var password = $("#password");
password.css("background-color", "rgb(128, 128, 200)");
photoFloat.authenticate(password.val(), function(success) {
password.val("");
if (success) {
password.css("background-color", "rgb(200, 200, 200)");
$(window).hashchange();
} else
password.css("background-color", "rgb(255, 64, 64)");
});
return false;
});
});