Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
20.00% |
4 / 20 |
|
21.43% |
3 / 14 |
CRAP | |
0.00% |
0 / 1 |
Auth | |
20.00% |
4 / 20 |
|
21.43% |
3 / 14 |
130.20 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
renderTemplate | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getManager | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isLoggedIn | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getUserObject | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getIdentity | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCreateFields | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getILSPatron | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getLoginFields | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getLogin | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getLoginDesc | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getLoginTokens | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getNewPasswordForm | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPasswordRecoveryForm | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Authentication view helper |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2010. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package View_Helpers |
25 | * @author Demian Katz <demian.katz@villanova.edu> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org/wiki/development Wiki |
28 | */ |
29 | |
30 | namespace VuFind\View\Helper\Root; |
31 | |
32 | use LmcRbacMvc\Identity\IdentityInterface; |
33 | use VuFind\Db\Entity\UserEntityInterface; |
34 | use VuFind\Db\Service\DbServiceAwareInterface; |
35 | use VuFind\Db\Service\DbServiceAwareTrait; |
36 | use VuFind\Db\Service\LoginTokenServiceInterface; |
37 | use VuFind\Exception\ILS as ILSException; |
38 | |
39 | /** |
40 | * Authentication view helper |
41 | * |
42 | * @category VuFind |
43 | * @package View_Helpers |
44 | * @author Demian Katz <demian.katz@villanova.edu> |
45 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
46 | * @link https://vufind.org/wiki/development Wiki |
47 | */ |
48 | class Auth extends \Laminas\View\Helper\AbstractHelper implements DbServiceAwareInterface |
49 | { |
50 | use ClassBasedTemplateRendererTrait; |
51 | use DbServiceAwareTrait; |
52 | |
53 | /** |
54 | * Authentication manager |
55 | * |
56 | * @var \VuFind\Auth\Manager |
57 | */ |
58 | protected $manager; |
59 | |
60 | /** |
61 | * ILS Authenticator |
62 | * |
63 | * @var \VuFind\Auth\ILSAuthenticator |
64 | */ |
65 | protected $ilsAuthenticator; |
66 | |
67 | /** |
68 | * Constructor |
69 | * |
70 | * @param \VuFind\Auth\Manager $manager Authentication manager |
71 | * @param \VuFind\Auth\ILSAuthenticator $ilsAuthenticator ILS Authenticator |
72 | */ |
73 | public function __construct( |
74 | \VuFind\Auth\Manager $manager, |
75 | \VuFind\Auth\ILSAuthenticator $ilsAuthenticator |
76 | ) { |
77 | $this->manager = $manager; |
78 | $this->ilsAuthenticator = $ilsAuthenticator; |
79 | } |
80 | |
81 | /** |
82 | * Render a template within an auth module folder. |
83 | * |
84 | * @param string $name Template name to render |
85 | * @param array $context Context for rendering template |
86 | * |
87 | * @return string |
88 | */ |
89 | protected function renderTemplate($name, $context = []) |
90 | { |
91 | // Get the current auth module's class name |
92 | $className = $this->getManager()->getAuthClassForTemplateRendering(); |
93 | $template = 'Auth/%s/' . $name; |
94 | $context['topClass'] = $this->getBriefClass($className); |
95 | return $this->renderClassTemplate($template, $className, $context); |
96 | } |
97 | |
98 | /** |
99 | * Get manager |
100 | * |
101 | * @return \VuFind\Auth\Manager |
102 | */ |
103 | public function getManager() |
104 | { |
105 | return $this->manager; |
106 | } |
107 | |
108 | /** |
109 | * Checks whether the user is logged in. |
110 | * |
111 | * @return UserEntityInterface|bool Object if user is logged in, false |
112 | * otherwise. |
113 | * |
114 | * @deprecated Use getIdentity() or getUserObject() instead. |
115 | */ |
116 | public function isLoggedIn() |
117 | { |
118 | return $this->getManager()->isLoggedIn(); |
119 | } |
120 | |
121 | /** |
122 | * Checks whether the user is logged in. |
123 | * |
124 | * @return ?UserEntityInterface Object if user is logged in, null otherwise. |
125 | */ |
126 | public function getUserObject(): ?UserEntityInterface |
127 | { |
128 | return $this->getManager()->getUserObject(); |
129 | } |
130 | |
131 | /** |
132 | * Get the logged-in user's identity (null if not logged in) |
133 | * |
134 | * @return ?IdentityInterface |
135 | */ |
136 | public function getIdentity(): ?IdentityInterface |
137 | { |
138 | return $this->getManager()->getIdentity(); |
139 | } |
140 | |
141 | /** |
142 | * Render the create account form fields. |
143 | * |
144 | * @param array $context Context for rendering template |
145 | * |
146 | * @return string |
147 | */ |
148 | public function getCreateFields($context = []) |
149 | { |
150 | return $this->renderTemplate('create.phtml', $context); |
151 | } |
152 | |
153 | /** |
154 | * Get ILS patron record for the currently logged-in user. |
155 | * |
156 | * @return array|bool Patron array if available, false otherwise. |
157 | */ |
158 | public function getILSPatron() |
159 | { |
160 | try { |
161 | return $this->ilsAuthenticator->storedCatalogLogin(); |
162 | } catch (ILSException $e) { |
163 | return false; |
164 | } |
165 | } |
166 | |
167 | /** |
168 | * Render the login form fields. |
169 | * |
170 | * @param array $context Context for rendering template |
171 | * |
172 | * @return string |
173 | */ |
174 | public function getLoginFields($context = []) |
175 | { |
176 | return $this->renderTemplate('loginfields.phtml', $context); |
177 | } |
178 | |
179 | /** |
180 | * Render the login template. |
181 | * |
182 | * @param array $context Context for rendering template |
183 | * |
184 | * @return string |
185 | */ |
186 | public function getLogin($context = []) |
187 | { |
188 | return $this->renderTemplate('login.phtml', $context); |
189 | } |
190 | |
191 | /** |
192 | * Render the login description template. |
193 | * |
194 | * @param array $context Context for rendering template |
195 | * |
196 | * @return string |
197 | */ |
198 | public function getLoginDesc($context = []) |
199 | { |
200 | return $this->renderTemplate('logindesc.phtml', $context); |
201 | } |
202 | |
203 | /** |
204 | * Get login token data |
205 | * |
206 | * @param int $userId user identifier |
207 | * |
208 | * @return array |
209 | */ |
210 | public function getLoginTokens(int $userId): array |
211 | { |
212 | return $this->getDbService(LoginTokenServiceInterface::class)->getByUser($userId); |
213 | } |
214 | |
215 | /** |
216 | * Render the new password form template. |
217 | * |
218 | * @param array $context Context for rendering template |
219 | * |
220 | * @return string |
221 | */ |
222 | public function getNewPasswordForm($context = []) |
223 | { |
224 | return $this->renderTemplate('newpassword.phtml', $context); |
225 | } |
226 | |
227 | /** |
228 | * Render the password recovery form template. |
229 | * |
230 | * @param array $context Context for rendering template |
231 | * |
232 | * @return string |
233 | */ |
234 | public function getPasswordRecoveryForm($context = []) |
235 | { |
236 | return $this->renderTemplate('recovery.phtml', $context); |
237 | } |
238 | } |