Skip to content

Commit

Permalink
Always response with Response::()
Browse files Browse the repository at this point in the history
  • Loading branch information
electerious committed Feb 13, 2016
1 parent a02ba01 commit 72b4321
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 34 deletions.
46 changes: 23 additions & 23 deletions php/Access/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static function addAlbumAction() {
Validator::required(isset($_POST['title']), __METHOD__);

$album = new Album(null);
echo $album->add($_POST['title']);
Response::json($album->add($_POST['title']));

}

Expand All @@ -97,7 +97,7 @@ private static function setAlbumTitleAction() {
Validator::required(isset($_POST['albumIDs'], $_POST['title']), __METHOD__);

$album = new Album($_POST['albumIDs']);
echo $album->setTitle($_POST['title']);
Response::json($album->setTitle($_POST['title']));

}

Expand All @@ -106,7 +106,7 @@ private static function setAlbumDescriptionAction() {
Validator::required(isset($_POST['albumID'], $_POST['description']), __METHOD__);

$album = new Album($_POST['albumID']);
echo $album->setDescription($_POST['description']);
Response::json($album->setDescription($_POST['description']));

}

Expand All @@ -115,7 +115,7 @@ private static function setAlbumPublicAction() {
Validator::required(isset($_POST['albumID'], $_POST['password'], $_POST['visible'], $_POST['downloadable']), __METHOD__);

$album = new Album($_POST['albumID']);
echo $album->setPublic($_POST['public'], $_POST['password'], $_POST['visible'], $_POST['downloadable']);
Response::json($album->setPublic($_POST['public'], $_POST['password'], $_POST['visible'], $_POST['downloadable']));

}

Expand All @@ -124,15 +124,15 @@ private static function deleteAlbumAction() {
Validator::required(isset($_POST['albumIDs']), __METHOD__);

$album = new Album($_POST['albumIDs']);
echo $album->delete();
Response::json($album->delete());

}

private static function mergeAlbumsAction() {

Validator::required(isset($_POST['albumIDs']), __METHOD__);
$album = new Album($_POST['albumIDs']);
echo $album->merge();
Response::json($album->merge());

}

Expand All @@ -152,7 +152,7 @@ private static function setPhotoTitleAction() {
Validator::required(isset($_POST['photoIDs'], $_POST['title']), __METHOD__);

$photo = new Photo($_POST['photoIDs']);
echo $photo->setTitle($_POST['title']);
Response::json($photo->setTitle($_POST['title']));

}

Expand All @@ -161,7 +161,7 @@ private static function setPhotoDescriptionAction() {
Validator::required(isset($_POST['photoID'], $_POST['description']), __METHOD__);

$photo = new Photo($_POST['photoID']);
echo $photo->setDescription($_POST['description']);
Response::json($photo->setDescription($_POST['description']));

}

Expand All @@ -170,7 +170,7 @@ private static function setPhotoStarAction() {
Validator::required(isset($_POST['photoIDs']), __METHOD__);

$photo = new Photo($_POST['photoIDs']);
echo $photo->setStar();
Response::json($photo->setStar());

}

Expand All @@ -179,7 +179,7 @@ private static function setPhotoPublicAction() {
Validator::required(isset($_POST['photoID']), __METHOD__);

$photo = new Photo($_POST['photoID']);
echo $photo->setPublic();
Response::json($photo->setPublic());

}

Expand All @@ -188,7 +188,7 @@ private static function setPhotoAlbumAction() {
Validator::required(isset($_POST['photoIDs'], $_POST['albumID']), __METHOD__);

$photo = new Photo($_POST['photoIDs']);
echo $photo->setAlbum($_POST['albumID']);
Response::json($photo->setAlbum($_POST['albumID']));

}

Expand All @@ -197,7 +197,7 @@ private static function setPhotoTagsAction() {
Validator::required(isset($_POST['photoIDs'], $_POST['tags']), __METHOD__);

$photo = new Photo($_POST['photoIDs']);
echo $photo->setTags($_POST['tags']);
Response::json($photo->setTags($_POST['tags']));

}

Expand All @@ -206,7 +206,7 @@ private static function duplicatePhotoAction() {
Validator::required(isset($_POST['photoIDs']), __METHOD__);

$photo = new Photo($_POST['photoIDs']);
echo $photo->duplicate();
Response::json($photo->duplicate());

}

Expand All @@ -215,18 +215,18 @@ private static function deletePhotoAction() {
Validator::required(isset($_POST['photoIDs']), __METHOD__);

$photo = new Photo($_POST['photoIDs']);
echo $photo->delete();
Response::json($photo->delete());

}

// Add functions

private static function uploadAction() {

Validator::required(isset($_FILES, $_POST['albumID'], $_POST['tags']), __METHOD__);
Validator::required(isset($_FILES, $_POST['albumID']), __METHOD__);

$photo = new Photo(null);
echo $photo->add($_FILES, $_POST['albumID'], '', $_POST['tags']);
Response::json($photo->add($_FILES, $_POST['albumID']));

}

Expand All @@ -235,7 +235,7 @@ private static function importUrlAction() {
Validator::required(isset($_POST['url'], $_POST['albumID']), __METHOD__);

$import = new Import();
echo $import->url($_POST['url'], $_POST['albumID']);
Response::json($import->url($_POST['url'], $_POST['albumID']));

}

Expand Down Expand Up @@ -272,14 +272,14 @@ private static function loginAction() {
Validator::required(isset($_POST['user'], $_POST['password']), __METHOD__);

$session = new Session();
echo $session->login($_POST['user'], $_POST['password']);
Response::json($session->login($_POST['user'], $_POST['password']));

}

private static function logoutAction() {

$session = new Session();
echo $session->logout();
Response::json($session->logout());

}

Expand All @@ -290,7 +290,7 @@ private static function setLoginAction() {
Validator::required(isset($_POST['username'], $_POST['password']), __METHOD__);

if (isset($_POST['oldPassword'])===false) $_POST['oldPassword'] = '';
echo Settings::setLogin($_POST['oldPassword'], $_POST['username'], $_POST['password']);
Response::json(Settings::setLogin($_POST['oldPassword'], $_POST['username'], $_POST['password']));

}

Expand All @@ -301,16 +301,16 @@ private static function setSortingAction() {
$sA = Settings::setSortingAlbums($_POST['typeAlbums'], $_POST['orderAlbums']);
$sP = Settings::setSortingPhotos($_POST['typePhotos'], $_POST['orderPhotos']);

if ($sA===true&&$sP===true) echo true;
else echo false;
if ($sA===true&&$sP===true) Response::json(true);
else Response::json(false);

}

private static function setDropboxKeyAction() {

Validator::required(isset($_POST['key']), __METHOD__);

echo Settings::setDropboxKey($_POST['key']);
Response::json(Settings::setDropboxKey($_POST['key']));

}

Expand Down
14 changes: 7 additions & 7 deletions php/Access/Guest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ private static function getAlbumAction() {
if ($album->getPublic()===true) {

// Album public
if ($album->checkPassword($_POST['password'])) Response::json($album->get());
else Response::warning('Wrong password!');
if ($album->checkPassword($_POST['password'])===true) Response::json($album->get());
else Response::warning('Wrong password!');

} else {

Expand All @@ -76,13 +76,13 @@ private static function checkAlbumAccessAction() {
if ($album->getPublic()===true) {

// Album public
if ($album->checkPassword($_POST['password'])) echo true;
else echo false;
if ($album->checkPassword($_POST['password'])===true) Response::json(true);
else Response::json(false);

} else {

// Album private
echo false;
Response::json(false);

}

Expand Down Expand Up @@ -118,14 +118,14 @@ private static function loginAction() {
Validator::required(isset($_POST['user'], $_POST['password']), __METHOD__);

$session = new Session();
echo $session->login($_POST['user'], $_POST['password']);
Response::json($session->login($_POST['user'], $_POST['password']));

}

private static function logoutAction() {

$session = new Session();
echo $session->logout();
Response::json($session->logout());

}

Expand Down
4 changes: 2 additions & 2 deletions src/scripts/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ api.post = function(fn, params, callback) {
}

// Convert 1 to true and an empty string to false
if (data==='1') data = true
else if (data==='') data = false
if (data==='true') data = true
else if (data==='false') data = false

// Convert to JSON if string start with '{' and ends with '}'
if (typeof data==='string' && data.substring(0, 1)==='{' && data.substring(data.length - 1, data.length)==='}') {
Expand Down
3 changes: 1 addition & 2 deletions src/scripts/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ upload.start = {

formData.append('function', 'Photo::add')
formData.append('albumID', albumID)
formData.append('tags', '')
formData.append(0, file)

xhr.open('POST', api.path)
Expand All @@ -128,7 +127,7 @@ upload.start = {
file.ready = true

// Set status
if (xhr.status===200 && xhr.responseText==='1') {
if (xhr.status===200 && xhr.responseText==='true') {

// Success
$('.basicModal .rows .row:nth-child(' + (file.num + 1) + ') .status')
Expand Down

0 comments on commit 72b4321

Please sign in to comment.