diff --git a/app/Controllers/Auth/LoginController.php b/app/Controllers/Auth/LoginController.php index 31bcc4b..7904daf 100644 --- a/app/Controllers/Auth/LoginController.php +++ b/app/Controllers/Auth/LoginController.php @@ -53,7 +53,7 @@ class LoginController extends Controller $username = param($request, 'username'); $user = $this->database->query('SELECT `id`, `email`, `username`, `password`,`is_admin`, `active`, `current_disk_quota`, `max_disk_quota`, `ldap` FROM `users` WHERE `username` = ? OR `email` = ? LIMIT 1', [$username, $username])->fetch(); - if ($this->config['ldap']['enabled']) { + if ($this->config['ldap']['enabled'] && ($user->ldap ?? true)) { $user = $this->ldapLogin($request, $username, param($request, 'password'), $user); } @@ -140,7 +140,7 @@ class LoginController extends Controller if (!$dbUser) { $email = $username; if (!filter_var($username, FILTER_VALIDATE_EMAIL)) { - $search = ldap_search($server, $this->config['ldap']['user_domain'].','.$this->config['ldap']['base_domain'], 'uid='.addslashes($username), ['mail']); + $search = ldap_search($server, $this->config['ldap']['base_domain'], 'uid='.addslashes($username), ['mail']); $entry = ldap_first_entry($server, $search); $email = @ldap_get_values($server, $entry, 'mail')[0] ?? platform_mail($username.rand(0, 100)); // if the mail is not set, generate a placeholder } diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 04293c7..8bcff69 100644 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -3,6 +3,7 @@ namespace App\Controllers; use App\Database\Queries\MediaQuery; +use App\Database\Queries\TagQuery; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; @@ -59,6 +60,11 @@ class DashboardController extends Controller ->filterByTag(param($request, 'tag')) ->run($page); + $tags = make(TagQuery::class, [ + 'isAdmin' => (bool) $this->session->get('admin', false), + 'userId' => $this->session->get('user_id') + ])->all(); + return view()->render( $response, ($this->session->get('admin', false) && $this->session->get('gallery_view', true)) ? 'dashboard/list.twig' : 'dashboard/grid.twig', @@ -68,6 +74,7 @@ class DashboardController extends Controller 'previous' => $page >= 1, 'current_page' => ++$page, 'copy_url_behavior' => $this->getSetting('copy_url_behavior', 'off'), + 'tags' => $tags, ] ); } diff --git a/app/Controllers/UploadController.php b/app/Controllers/UploadController.php index 7f9331a..bad2562 100644 --- a/app/Controllers/UploadController.php +++ b/app/Controllers/UploadController.php @@ -27,7 +27,11 @@ class UploadController extends Controller */ public function uploadWebPage(Response $response): Response { - return view()->render($response, 'upload/web.twig'); + $maxFileSize = min(stringToBytes(ini_get('post_max_size')), stringToBytes(ini_get('upload_max_filesize'))); + + return view()->render($response, 'upload/web.twig', [ + 'max_file_size' => humanFileSize($maxFileSize) + ]); } /** diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index a022b64..8b78a39 100644 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -185,7 +185,8 @@ class UserController extends Controller param($request, 'password'), param($request, 'is_admin') !== null ? 1 : 0, param($request, 'is_active') !== null ? 1 : 0, - $user->max_disk_quota + $user->max_disk_quota, + param($request, 'ldap') !== null ? 1 : 0 ); if ($user->id === $this->session->get('user_id')) { diff --git a/app/Database/Queries/TagQuery.php b/app/Database/Queries/TagQuery.php index 40f4677..8a99d03 100644 --- a/app/Database/Queries/TagQuery.php +++ b/app/Database/Queries/TagQuery.php @@ -14,10 +14,32 @@ class TagQuery * @var DB */ private $db; + /** + * @var null|bool + */ + private $isAdmin; + /** + * @var null|int|string + */ + private $userId; - public function __construct(DB $db) + public function __construct(DB $db, $isAdmin = null, $userId = null) { $this->db = $db; + $this->isAdmin = $isAdmin; + $this->userId = $userId; + } + + /** + * @return array + */ + public function all() + { + if ($this->isAdmin) { + return $this->db->query('SELECT * FROM `tags` ORDER BY `name`')->fetchAll(); + } + + return $this->db->query('SELECT `tags`.* FROM `tags` INNER JOIN `uploads_tags` ON `tags`.`id` = `uploads_tags`.`tag_id` INNER JOIN `uploads` ON `uploads`.`id` = `uploads_tags`.`upload_id` WHERE `uploads`.`user_id` = ? ORDER BY `tags`.`name`', $this->userId)->fetchAll(); } /** diff --git a/resources/lang/en.lang.php b/resources/lang/en.lang.php index 6275e3b..470fbee 100644 --- a/resources/lang/en.lang.php +++ b/resources/lang/en.lang.php @@ -152,4 +152,6 @@ return [ 'mail.new_account_text_with_pw' => "Hi %s!\na new account was created for you on %s (%s), with the following credentials:\n\nUsername: %s\nPassword: %s\n\nClick on the following link to go to the login page:\n%s", 'user_create_password' => 'If leaved empty, you might want to send a notification to the user email.', 'ldap_cant_connect' => 'Can\'t connect to the LDAP auth server.', + 'upload_max_file_size' => 'The max file size is currently %s.', + 'no_tags' => 'No tags added' ]; diff --git a/resources/templates/dashboard/pager_header.twig b/resources/templates/dashboard/pager_header.twig index 14922f1..d62f9a7 100644 --- a/resources/templates/dashboard/pager_header.twig +++ b/resources/templates/dashboard/pager_header.twig @@ -1,19 +1,33 @@