-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathMyDevicesController.php
More file actions
86 lines (74 loc) · 2.49 KB
/
MyDevicesController.php
File metadata and controls
86 lines (74 loc) · 2.49 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
// SPDX-FileCopyrightText: 2021 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-3.0-or-later
namespace Icinga\Controllers;
use Icinga\Application\Hook;
use Icinga\Application\Hook\TwoFactorHook;
use Icinga\Common\Database;
use Icinga\Web\Notification;
use Icinga\Web\RememberMe;
use Icinga\Web\RememberMeUserDevicesList;
use ipl\Web\Compat\CompatController;
/**
* MyDevicesController
*
* this controller shows you all the devices you are logged in
*/
class MyDevicesController extends CompatController
{
use Database;
public function init()
{
$this->getTabs()
->add(
'account',
array(
'title' => $this->translate('Update your account'),
'label' => $this->translate('My Account'),
'url' => 'account'
)
)
->add(
'navigation',
array(
'title' => $this->translate('List and configure your own navigation items'),
'label' => $this->translate('Navigation'),
'url' => 'navigation'
)
)
->add(
'devices',
array(
'title' => $this->translate('List of devices you are logged in'),
'label' => $this->translate('My Devices'),
'url' => 'my-devices'
)
)->activate('devices');
if (Hook::has(TwoFactorHook::NAME)) {
$this->getTabs()->add('two-factor', [
'title' => $this->translate('Configure two-factor authentication'),
'label' => $this->translate('Two-Factor Auth'),
'url' => 'two-factor/config',
]);
}
}
public function indexAction()
{
$name = $this->auth->getUser()->getUsername();
$data = (new RememberMeUserDevicesList())
->setDevicesList(RememberMe::getAllByUsername($name))
->setUsername($name)
->setUrl('my-devices/delete');
$this->addContent($data);
if (! $this->hasDb()) {
Notification::warning(
$this->translate("Users can't stay logged in without a database configuration backend")
);
}
}
public function deleteAction()
{
(new RememberMe())->remove($this->params->getRequired('fingerprint'));
$this->redirectNow('my-devices');
}
}