1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\Auth\Controller; |
6
|
|
|
|
7
|
|
|
use App\Auth\AuthService; |
8
|
|
|
use App\Auth\Form\LoginForm; |
9
|
|
|
use App\Service\WebControllerService; |
10
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
|
|
|
11
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
|
|
|
12
|
|
|
use Yiisoft\FormModel\FormHydrator; |
|
|
|
|
13
|
|
|
use Yiisoft\Http\Method; |
|
|
|
|
14
|
|
|
use Yiisoft\Translator\TranslatorInterface; |
|
|
|
|
15
|
|
|
use Yiisoft\User\Login\Cookie\CookieLogin; |
|
|
|
|
16
|
|
|
use Yiisoft\User\Login\Cookie\CookieLoginIdentityInterface; |
|
|
|
|
17
|
|
|
use Yiisoft\Yii\View\ViewRenderer; |
|
|
|
|
18
|
|
|
|
19
|
|
|
final class AuthController |
20
|
|
|
{ |
21
|
|
|
public function __construct( |
22
|
|
|
private readonly AuthService $authService, |
23
|
|
|
private readonly WebControllerService $webService, |
24
|
|
|
private ViewRenderer $viewRenderer, |
25
|
|
|
) { |
26
|
|
|
$this->viewRenderer = $viewRenderer->withControllerName('auth'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function login( |
30
|
|
|
ServerRequestInterface $request, |
31
|
|
|
TranslatorInterface $translator, |
32
|
|
|
FormHydrator $formHydrator, |
33
|
|
|
CookieLogin $cookieLogin |
34
|
|
|
): ResponseInterface { |
35
|
|
|
if (!$this->authService->isGuest()) { |
36
|
|
|
return $this->redirectToMain(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$loginForm = new LoginForm($this->authService, $translator); |
40
|
|
|
|
41
|
|
|
if ($formHydrator->populateFromPostAndValidate($loginForm, $request)) { |
42
|
|
|
$identity = $this->authService->getIdentity(); |
43
|
|
|
|
44
|
|
|
if ($identity instanceof CookieLoginIdentityInterface && $loginForm->getPropertyValue('rememberMe')) { |
45
|
|
|
return $cookieLogin->addCookie($identity, $this->redirectToMain()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $this->redirectToMain(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $this->viewRenderer->render('login', ['formModel' => $loginForm]); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
public function logout(): ResponseInterface |
56
|
|
|
{ |
57
|
|
|
$this->authService->logout(); |
58
|
|
|
|
59
|
|
|
return $this->redirectToMain(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function redirectToMain(): ResponseInterface |
63
|
|
|
{ |
64
|
|
|
return $this->webService->getRedirectResponse('site/index'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths