Added filter by tag list
Completed ldap implementation
This commit is contained in:
parent
64772d190c
commit
ac9f1d1578
11 changed files with 86 additions and 13 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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')) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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'
|
||||
];
|
||||
|
|
|
@ -1,19 +1,33 @@
|
|||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<form method="get" action="{{ route('home') }}">
|
||||
<div class="input-group mb-3">
|
||||
<div class="col-md-4 mb-3 d-flex justify-content-between justify-content-md-start">
|
||||
<form method="get" action="{{ route('home') }}" class="mr-1">
|
||||
<div class="input-group">
|
||||
<input type="text" name="search" class="form-control" placeholder="{{ lang('dotted_search') }}" aria-label="{{ lang('dotted_search') }}" value="{{ param(request, 'search', '') }}">
|
||||
<div class="input-group-append">
|
||||
<button type="submit" class="btn btn-outline-secondary"><i class="fas fa-search"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-outline-dark dropdown-toggle" type="button" data-toggle="dropdown">
|
||||
<i class="fas fa-tags"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu" style="max-height: 250px; overflow: auto">
|
||||
{% if tags is empty %}
|
||||
<h6 class="dropdown-header">{{ lang('no_tags') }}</h6>
|
||||
{% else %}
|
||||
{% for tag in tags %}
|
||||
<a class="dropdown-item {{ request.queryParams['tag'] == tag.id ? 'active' }}" href="{{ queryParams({'tag': tag.id}) }}">{{ tag.name }}</a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 d-flex justify-content-center">
|
||||
<div class="col-md-4 d-flex justify-content-center">
|
||||
{% include 'comp/pager.twig' %}
|
||||
</div>
|
||||
<div class="col-md-3 text-lg-right text-center mb-3">
|
||||
<div class="btn-group">
|
||||
<div class="col-md-4 mb-3 d-flex justify-content-md-end justify-content-between">
|
||||
<div class="btn-group mr-1">
|
||||
<div class="btn-group">
|
||||
<button class="btn btn-outline-primary dropdown-toggle" type="button" id="dropdownOrder" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
{{ lang('order_by') }}
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
{% include 'comp/navbar.twig' %}
|
||||
<div class="container">
|
||||
{% include 'comp/alert.twig' %}
|
||||
<div class="alert alert-info alert-permanent">
|
||||
{{ lang('upload_max_file_size', [max_file_size]) }}
|
||||
</div>
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<div class="row mb-3">
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<div class="form-group row">
|
||||
<label for="password" class="col-sm-2 col-form-label">{{ lang('password') }}</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="password" class="form-control" id="password" placeholder="{{ lang('password') }}" name="password" autocomplete="off">
|
||||
<input type="password" class="form-control" id="password" placeholder="{{ lang('password') }}" name="password" autocomplete="off"{{ user.ldap ? ' disabled' }}>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
|
@ -89,6 +89,14 @@
|
|||
<input type="checkbox" name="is_active" data-toggle="toggle" data-off="{{ lang('no') }}" data-on="{{ lang('yes') }}" {{ user.active ? 'checked' }}>
|
||||
</div>
|
||||
</div>
|
||||
{% if config.ldap.enabled %}
|
||||
<div class="form-group row">
|
||||
<label for="ldap" class="col-sm-2 col-form-label">LDAP Auth</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="checkbox" name="ldap" data-toggle="toggle" data-off="{{ lang('no') }}" data-on="{{ lang('yes') }}" {{ user.ldap ? 'checked' }}>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">{{ lang('delete_all') }}</label>
|
||||
<div class="col-sm-10">
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
<th>{{ lang('user_code') }}</th>
|
||||
<th>{{ lang('used_space') }}</th>
|
||||
<th>{{ lang('active') }}</th>
|
||||
{% if config.ldap.enabled %}
|
||||
<th>{{ lang('LDAP') }}</th>
|
||||
{% endif %}
|
||||
<th>{{ lang('admin') }}</th>
|
||||
<th>{{ lang('reg_date') }}</th>
|
||||
<th></th>
|
||||
|
@ -43,6 +46,15 @@
|
|||
<span class="badge badge-danger"><i class="fas fa-times"></i></span>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% if config.ldap.enabled %}
|
||||
<td class="text-center">
|
||||
{% if user.ldap %}
|
||||
<span class="badge badge-success"><i class="fas fa-check"></i></span>
|
||||
{% else %}
|
||||
<span class="badge badge-danger"><i class="fas fa-times"></i></span>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
<td class="text-center">
|
||||
{% if user.is_admin %}
|
||||
<span class="badge badge-success"><i class="fas fa-check"></i></span>
|
||||
|
|
|
@ -33,7 +33,7 @@ var app = {
|
|||
$('.tag-item').contextmenu(app.removeTag);
|
||||
|
||||
|
||||
$('.alert').fadeTo(10000, 500).slideUp(500, function () {
|
||||
$('.alert').not('.alert-permanent').fadeTo(10000, 500).slideUp(500, function () {
|
||||
$('.alert').slideUp(500);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue