lychee/php/Access/Guest.php

180 lines
3.4 KiB
PHP
Raw Normal View History

2014-04-30 08:56:04 +00:00
<?php
namespace Lychee\Access;
2014-04-30 08:56:04 +00:00
use Lychee\Modules\Album;
use Lychee\Modules\Module;
use Lychee\Modules\Photo;
use Lychee\Modules\Session;
2014-04-30 08:56:04 +00:00
final class Guest implements Access {
2014-04-30 08:56:04 +00:00
public function check($fn) {
switch ($fn) {
# Album functions
2015-02-02 22:36:33 +00:00
case 'Album::getAll': $this->getAlbums(); break;
case 'Album::get': $this->getAlbum(); break;
case 'Album::getPublic': $this->checkAlbumAccess(); break;
2014-04-30 08:56:04 +00:00
# Photo functions
2015-02-02 22:36:33 +00:00
case 'Photo::get': $this->getPhoto(); break;
2014-04-30 08:56:04 +00:00
# Session functions
2015-02-02 22:36:33 +00:00
case 'Session::init': $this->init(); break;
case 'Session::login': $this->login(); break;
case 'Session::logout': $this->logout(); break;
2014-04-30 08:56:04 +00:00
# $_GET functions
2015-02-02 22:36:33 +00:00
case 'Album::getArchive': $this->getAlbumArchive(); break;
case 'Photo::getArchive': $this->getPhotoArchive(); break;
2014-04-30 08:56:04 +00:00
# Error
2014-04-30 09:09:28 +00:00
default: exit('Error: Function not found! Please check the spelling of the called function.');
break;
2014-04-30 08:56:04 +00:00
}
return true;
}
# Album functions
private function getAlbums() {
$album = new Album(null);
2014-04-30 08:56:04 +00:00
echo json_encode($album->getAll(true));
}
private function getAlbum() {
Module::dependencies(isset($_POST['albumID'], $_POST['password']));
$album = new Album($_POST['albumID']);
2014-04-30 08:56:04 +00:00
if ($album->getPublic()) {
# Album public
2015-02-16 19:27:27 +00:00
if ($album->checkPassword($_POST['password'])) echo json_encode($album->get());
else echo 'Warning: Wrong password!';
2014-04-30 08:56:04 +00:00
} else {
# Album private
echo 'Warning: Album private!';
}
}
private function checkAlbumAccess() {
Module::dependencies(isset($_POST['albumID'], $_POST['password']));
$album = new Album($_POST['albumID']);
2014-04-30 08:56:04 +00:00
if ($album->getPublic()) {
# Album public
2015-02-16 19:27:27 +00:00
if ($album->checkPassword($_POST['password'])) echo true;
else echo false;
2014-04-30 08:56:04 +00:00
} else {
# Album private
echo false;
}
}
# Photo functions
private function getPhoto() {
Module::dependencies(isset($_POST['photoID'], $_POST['albumID'], $_POST['password']));
$photo = new Photo($_POST['photoID']);
2014-04-30 08:56:04 +00:00
$pgP = $photo->getPublic($_POST['password']);
if ($pgP===2) echo json_encode($photo->get($_POST['albumID']));
else if ($pgP===1) echo 'Warning: Wrong password!';
else if ($pgP===0) echo 'Warning: Photo private!';
2014-04-30 08:56:04 +00:00
}
# Session functions
private function init() {
global $dbName;
$session = new Session();
echo json_encode($session->init(true));
2014-04-30 08:56:04 +00:00
}
private function login() {
Module::dependencies(isset($_POST['user'], $_POST['password']));
$session = new Session();
2014-04-30 08:56:04 +00:00
echo $session->login($_POST['user'], $_POST['password']);
}
private function logout() {
$session = new Session();
echo $session->logout();
}
2014-04-30 08:56:04 +00:00
# $_GET functions
private function getAlbumArchive() {
Module::dependencies(isset($_GET['albumID'], $_GET['password']));
$album = new Album($_GET['albumID']);
2014-04-30 08:56:04 +00:00
2014-08-17 18:22:46 +00:00
if ($album->getPublic()&&$album->getDownloadable()) {
2014-04-30 08:56:04 +00:00
# Album Public
2015-02-16 19:27:27 +00:00
if ($album->checkPassword($_GET['password'])) $album->getArchive();
else exit('Warning: Wrong password!');
2014-04-30 08:56:04 +00:00
} else {
# Album Private
exit('Warning: Album private or not downloadable!');
}
}
private function getPhotoArchive() {
Module::dependencies(isset($_GET['photoID'], $_GET['password']));
$photo = new Photo($_GET['photoID']);
2014-04-30 08:56:04 +00:00
$pgP = $photo->getPublic($_GET['password']);
2014-04-30 08:56:04 +00:00
# Photo Download
if ($pgP===2) {
2014-04-30 08:56:04 +00:00
# Photo Public
$photo->getArchive();
} else {
# Photo Private
exit('Warning: Photo private or password incorrect!');
2014-04-30 08:56:04 +00:00
}
}
}
?>