|
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\Translator\TranslatorInterface; |
|
|
|
|
|
|
14
|
|
|
use Yiisoft\User\Login\Cookie\CookieLogin; |
|
|
|
|
|
|
15
|
|
|
use Yiisoft\User\Login\Cookie\CookieLoginIdentityInterface; |
|
|
|
|
|
|
16
|
|
|
use Yiisoft\Yii\View\Renderer\ViewRenderer; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
final class AuthController |
|
19
|
|
|
{ |
|
20
|
|
|
public function __construct( |
|
21
|
|
|
private readonly AuthService $authService, |
|
22
|
|
|
private readonly WebControllerService $webService, |
|
23
|
|
|
private ViewRenderer $viewRenderer, |
|
24
|
|
|
) { |
|
25
|
|
|
$this->viewRenderer = $viewRenderer->withControllerName('auth'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function login( |
|
29
|
|
|
ServerRequestInterface $request, |
|
30
|
|
|
TranslatorInterface $translator, |
|
31
|
|
|
FormHydrator $formHydrator, |
|
32
|
|
|
CookieLogin $cookieLogin |
|
33
|
|
|
): ResponseInterface { |
|
34
|
|
|
if (!$this->authService->isGuest()) { |
|
35
|
|
|
return $this->redirectToMain(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$loginForm = new LoginForm($this->authService, $translator); |
|
39
|
|
|
|
|
40
|
|
|
if ($formHydrator->populateFromPostAndValidate($loginForm, $request)) { |
|
41
|
|
|
$identity = $this->authService->getIdentity(); |
|
42
|
|
|
|
|
43
|
|
|
if ($identity instanceof CookieLoginIdentityInterface && $loginForm->getPropertyValue('rememberMe')) { |
|
44
|
|
|
return $cookieLogin->addCookie($identity, $this->redirectToMain()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return $this->redirectToMain(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return $this->viewRenderer->render('login', ['formModel' => $loginForm]); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function logout(): ResponseInterface |
|
54
|
|
|
{ |
|
55
|
|
|
$this->authService->logout(); |
|
56
|
|
|
|
|
57
|
|
|
return $this->redirectToMain(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
private function redirectToMain(): ResponseInterface |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->webService->getRedirectResponse('site/index'); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
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