2013-09-03 09:59:30 +00:00
/ * *
2014-01-22 10:12:51 +00:00
* @ name Password Module
* @ description Controls the access to password - protected albums and photos .
2013-09-03 09:59:30 +00:00
* @ author Tobias Reich
2014-01-22 10:12:51 +00:00
* @ copyright 2014 by Tobias Reich
2013-09-03 09:59:30 +00:00
* /
password = {
value : "" ,
set : function ( albumID ) {
var buttons ,
params ;
buttons = [
[ "Set Password" , function ( ) {
2014-01-22 10:12:51 +00:00
if ( visible . album ( ) ) {
album . json . password = true ;
view . album . password ( ) ;
}
2013-09-03 09:59:30 +00:00
2014-04-01 19:33:29 +00:00
params = "setAlbumPassword&albumID=" + albumID + "&password=" + md5 ( $ ( ".message input.text" ) . val ( ) ) ;
2014-01-22 10:12:51 +00:00
lychee . api ( params , function ( data ) {
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
if ( data !== true ) lychee . error ( null , params , data ) ;
2013-09-03 09:59:30 +00:00
} ) ;
} ] ,
[ "Cancel" , function ( ) { } ]
] ;
2014-01-22 10:12:51 +00:00
modal . show ( "Set Password" , "Set a password to protect '" + album . json . title + "' from unauthorized viewers. Only people with this password can view this album. <input class='text' type='password' placeholder='password' value=''>" , buttons ) ;
2013-09-03 09:59:30 +00:00
} ,
get : function ( albumID , callback ) {
2014-01-22 10:12:51 +00:00
var passwd = $ ( ".message input.text" ) . val ( ) ,
2013-09-03 09:59:30 +00:00
params ;
if ( ! lychee . publicMode ) callback ( ) ;
else if ( album . json && album . json . password == false ) callback ( ) ;
else if ( albums . json && albums . json . content [ albumID ] . password == false ) callback ( ) ;
else if ( ! a lbums . json && ! album . json ) {
// Continue without password
album . json = { password : true } ;
callback ( "" ) ;
} else if ( passwd == undefined ) {
// Request password
password . getDialog ( albumID , callback ) ;
} else {
// Check password
2014-04-01 19:33:29 +00:00
params = "checkAlbumAccess&albumID=" + albumID + "&password=" + md5 ( passwd ) ;
2014-01-22 10:12:51 +00:00
lychee . api ( params , function ( data ) {
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
if ( data === true ) {
2014-04-01 19:33:29 +00:00
password . value = md5 ( passwd ) ;
2013-09-03 09:59:30 +00:00
callback ( ) ;
} else {
lychee . goto ( "" ) ;
2014-01-22 10:12:51 +00:00
loadingBar . show ( "error" , "Access denied. Wrong password!" ) ;
2013-09-03 09:59:30 +00:00
}
} ) ;
}
} ,
getDialog : function ( albumID , callback ) {
var buttons ;
buttons = [
[ "Enter" , function ( ) { password . get ( albumID , callback ) } ] ,
[ "Cancel" , lychee . goto ]
] ;
2014-01-22 10:12:51 +00:00
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 ) ;
2013-09-03 09:59:30 +00:00
} ,
remove : function ( albumID ) {
var params ;
2014-01-22 10:12:51 +00:00
if ( visible . album ( ) ) {
album . json . password = false ;
view . album . password ( ) ;
}
2013-09-03 09:59:30 +00:00
params = "setAlbumPassword&albumID=" + albumID + "&password=" ;
2014-01-22 10:12:51 +00:00
lychee . api ( params , function ( data ) {
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
if ( data !== true ) lychee . error ( null , params , data ) ;
2013-09-03 09:59:30 +00:00
} ) ;
}
2014-02-25 22:37:05 +00:00
} ;