From 499614eab0939575cfab3fd8d7a50885a7277e2c Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 11 Aug 2012 01:47:11 +0200 Subject: [PATCH] Support simple auth form. --- web/js/010-libphotofloat.js | 20 ++++++++++++++++++-- web/js/011-display.js | 23 ++++++++++++++++++++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/web/js/010-libphotofloat.js b/web/js/010-libphotofloat.js index f716ca7..fb469a0 100644 --- a/web/js/010-libphotofloat.js +++ b/web/js/010-libphotofloat.js @@ -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) { diff --git a/web/js/011-display.js b/web/js/011-display.js index 479cb8e..f0ddd77 100644 --- a/web/js/011-display.js +++ b/web/js/011-display.js @@ -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; + }); });