Fix sorting in user auth failure list
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / acp / page / UserAuthenticationFailureListPage.class.php
CommitLineData
359f3c53 1<?php
a9229942 2
359f3c53 3namespace wcf\acp\page;
a9229942 4
157054c9 5use wcf\data\user\authentication\failure\UserAuthenticationFailureList;
359f3c53 6use wcf\page\SortablePage;
aca2c9bf 7use wcf\system\WCF;
359f3c53
MW
8
9/**
10 * Shows a list of user authentication failures.
a9229942
TD
11 *
12 * @author Marcel Werk
13 * @copyright 2001-2019 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
a9229942
TD
15 *
16 * @property UserAuthenticationFailureList $objectList
359f3c53 17 */
a9229942
TD
18class UserAuthenticationFailureListPage extends SortablePage
19{
20 /**
21 * @inheritDoc
22 */
23 public $activeMenuItem = 'wcf.acp.menu.link.log.authentication.failure';
24
25 /**
26 * @inheritDoc
27 */
28 public $neededPermissions = ['admin.management.canViewLog'];
29
30 /**
31 * @inheritDoc
32 */
33 public $neededModules = ['ENABLE_USER_AUTHENTICATION_FAILURE'];
34
35 /**
36 * @inheritDoc
37 */
38 public $defaultSortField = 'time';
39
40 /**
41 * @inheritDoc
42 */
43 public $defaultSortOrder = 'DESC';
44
45 /**
46 * @inheritDoc
47 */
c09d5efc 48 public $validSortFields = ['failureID', 'environment', 'userID', 'username', 'time', 'ipAddress', 'userAgent', 'validationError'];
a9229942
TD
49
50 /**
51 * @inheritDoc
52 */
53 public $objectListClassName = UserAuthenticationFailureList::class;
aca2c9bf
MS
54
55 /**
56 * @var string[]
57 * @since 5.4
58 */
59 public $filter = [
60 'environment' => '',
61 'endDate' => '',
62 'startDate' => '',
63 'username' => '',
64 'userAgent' => '',
65 'validationError' => '',
66 ];
67
68 /**
69 * @inheritDoc
70 */
71 public function readParameters()
72 {
73 parent::readParameters();
74
75 if (isset($_REQUEST['filter']) && \is_array($_REQUEST['filter'])) {
76 foreach ($_REQUEST['filter'] as $key => $value) {
77 if (\array_key_exists($key, $this->filter)) {
78 $this->filter[$key] = $value;
79 }
80 }
81 }
82 }
83
84 /**
85 * @inheritDoc
86 */
87 protected function initObjectList()
88 {
89 parent::initObjectList();
90
91 if ($this->filter['environment'] !== '') {
92 $this->objectList->getConditionBuilder()->add(
93 'user_authentication_failure.environment = ?',
94 [$this->filter['environment']]
95 );
96 }
97 if ($this->filter['endDate'] !== '') {
98 $endDate = @\strtotime($this->filter['endDate']);
99 if ($endDate > 0) {
100 $this->objectList->getConditionBuilder()->add(
101 'user_authentication_failure.time <= ?',
102 [$endDate]
103 );
104 }
105 }
106 if ($this->filter['startDate'] !== '') {
107 $startDate = @\strtotime($this->filter['startDate']);
108 if ($startDate > 0) {
109 $this->objectList->getConditionBuilder()->add(
110 'user_authentication_failure.time >= ?',
111 [$startDate]
112 );
113 }
114 }
115 if ($this->filter['username'] !== '') {
116 $this->objectList->getConditionBuilder()->add(
117 'user_authentication_failure.username LIKE ?',
118 ['%' . \addcslashes($this->filter['username'], '_%') . '%']
119 );
120 }
121 if ($this->filter['userAgent'] !== '') {
122 $this->objectList->getConditionBuilder()->add(
123 'user_authentication_failure.userAgent LIKE ?',
124 ['%' . \addcslashes($this->filter['userAgent'], '_%') . '%']
125 );
126 }
127 if ($this->filter['validationError'] !== '') {
128 $this->objectList->getConditionBuilder()->add(
129 'user_authentication_failure.validationError = ?',
130 [$this->filter['validationError']]
131 );
132 }
133 }
134
135 /**
136 * @inheritDoc
137 */
138 public function assignVariables()
139 {
140 parent::assignVariables();
141
142 $filterLinkParameters = \http_build_query(['filter' => \array_filter($this->filter)], '', '&');
143
144 WCF::getTPL()->assign([
145 'filter' => $this->filter,
146 'filterLinkParameters' => $filterLinkParameters ? '&' . $filterLinkParameters : '',
147 ]);
148 }
359f3c53 149}