password.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @description Controls the access to password-protected albums and photos.
  3. * @copyright 2015 by Tobias Reich
  4. */
  5. password = {
  6. value: ''
  7. }
  8. password.get = function(albumID, callback) {
  9. if (lychee.publicMode===false) callback()
  10. else if (album.json && album.json.password==='0') callback()
  11. else if (albums.json && albums.getByID(albumID).password==='0') callback()
  12. else if (!albums.json && !album.json) {
  13. // Continue without password
  14. album.json = { password: true }
  15. callback('')
  16. } else {
  17. // Request password
  18. password.getDialog(albumID, callback)
  19. }
  20. }
  21. password.getDialog = function(albumID, callback) {
  22. const action = (data) => {
  23. let passwd = data.password
  24. let params = {
  25. albumID,
  26. password: passwd
  27. }
  28. api.post('Album::getPublic', params, function(data) {
  29. if (data===true) {
  30. basicModal.close()
  31. password.value = passwd
  32. callback()
  33. } else {
  34. basicModal.error('password')
  35. }
  36. })
  37. }
  38. const cancel = () => {
  39. basicModal.close()
  40. if (!visible.albums()) lychee.goto()
  41. }
  42. let msg = `
  43. <p>
  44. This album is protected by a password. Enter the password below to view the photos of this album:
  45. <input name='password' class='text' type='password' placeholder='password' value=''>
  46. </p>
  47. `
  48. basicModal.show({
  49. body: msg,
  50. buttons: {
  51. action: {
  52. title: 'Enter',
  53. fn: action
  54. },
  55. cancel: {
  56. title: 'Cancel',
  57. fn: cancel
  58. }
  59. }
  60. })
  61. }