-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextend.php
69 lines (55 loc) · 2.36 KB
/
extend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/*
* This file is part of tiborsulyan/autologout.
*
* Copyright (c) 2021 stibi.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Tiborsulyan\Autologout;
use Flarum\Foundation\ValidationException;
use Flarum\Settings\Event\Saving;
use Flarum\Extend;
use Illuminate\Config\Repository as ConfigRepository;
return [
(new Extend\Frontend('forum'))
->js(__DIR__ . '/js/dist/forum.js'),
(new Extend\Frontend('admin'))
->js(__DIR__ . '/js/dist/admin.js'),
new Extend\Locales(__DIR__ . '/resources/locale'),
(new Extend\Settings)
->serializeToForum('tiborsulyan-autologout.logoutAfter', 'tiborsulyan-autologout.logoutAfter')
->serializeToForum('tiborsulyan-autologout.warnAfter', 'tiborsulyan-autologout.warnAfter'),
(new Extend\Routes('api'))
->post('/keepalive', 'tiborsulyan.autologout.keepalive', KeepaliveController::class),
(new Extend\Event())
->listen(Saving::class, function (Saving $event) {
$lt = null;
if (isset($event->settings['tiborsulyan-autologout.logoutAfter'])) {
$lt = $event->settings['tiborsulyan-autologout.logoutAfter'];
}
$wt = null;
if (isset($event->settings['tiborsulyan-autologout.warnAfter'])) {
$wt = $event->settings['tiborsulyan-autologout.warnAfter'];
}
if (!$lt && $wt) {
throw new ValidationException([
'autologout' => app('translator')->trans('tiborsulyan-autologout.admin.validation.logoutTimeoutNotSet')
]);
}
if ($lt && $wt && $wt >= $lt) {
throw new ValidationException([
'autologout' => app('translator')->trans('tiborsulyan-autologout.admin.validation.warnTimeoutTooBig')
]);
}
if ($lt) {
$sessionLifetime = app(ConfigRepository::class)->get("session.lifetime");
if ($lt > $sessionLifetime) {
throw new ValidationException([
'autologout' => app('translator')->trans('tiborsulyan-autologout.admin.validation.logoutTimeoutTooBig', ['sessionLifetime' => $sessionLifetime])
]);
}
}
}),
];