password.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @name Password Module
  3. * @description Controls the access to password-protected albums and photos.
  4. * @author Tobias Reich
  5. * @copyright 2014 by Tobias Reich
  6. */
  7. password = {
  8. value: "",
  9. get: function(albumID, callback) {
  10. var passwd = $(".message input.text").val(),
  11. params;
  12. if (!lychee.publicMode) callback();
  13. else if (album.json&&album.json.password==false) callback();
  14. else if (albums.json&&albums.json.content[albumID].password==false) callback();
  15. else if (!albums.json&&!album.json) {
  16. // Continue without password
  17. album.json = {password: true};
  18. callback("");
  19. } else if (passwd==undefined) {
  20. // Request password
  21. password.getDialog(albumID, callback);
  22. } else {
  23. // Check password
  24. params = "checkAlbumAccess&albumID=" + albumID + "&password=" + md5(passwd);
  25. lychee.api(params, function(data) {
  26. if (data===true) {
  27. password.value = md5(passwd);
  28. callback();
  29. } else {
  30. lychee.goto("");
  31. loadingBar.show("error", "Access denied. Wrong password!");
  32. }
  33. });
  34. }
  35. },
  36. getDialog: function(albumID, callback) {
  37. var buttons;
  38. buttons = [
  39. ["Enter", function() { password.get(albumID, callback) }],
  40. ["Cancel", lychee.goto]
  41. ];
  42. modal.show("<a class='icon-lock'></a> Enter Password", "This album is protected by a password. Enter the password below to view the photos of this album: <input class='text' type='password' placeholder='password' value=''>", buttons, -110, false);
  43. }
  44. };