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-01-22 10:12:51 +00:00
params = "setAlbumPassword&albumID=" + albumID + "&password=" + hex _md5 ( $ ( ".message input.text" ) . val ( ) ) ;
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 ( ! albums . json && ! album . json ) {
// Continue without password
album . json = { password : true } ;
callback ( "" ) ;
} else if ( passwd == undefined ) {
// Request password
password . getDialog ( albumID , callback ) ;
} else {
// Check password
params = "checkAlbumAccess&albumID=" + albumID + "&password=" + hex _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 ) {
2013-09-03 09:59:30 +00:00
password . value = hex _md5 ( passwd ) ;
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
} ;