1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Components\Controller; |
6
|
|
|
use App\Components\View; |
7
|
|
|
use App\Models\LoginFormModel; |
8
|
|
|
use Micro\Form\FormBuilder; |
9
|
|
|
use Micro\Web\Html; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class DefaultController |
13
|
|
|
* @package App\Controllers |
14
|
|
|
*/ |
15
|
|
|
class DefaultController extends Controller |
16
|
|
|
{ |
17
|
|
|
public function filters() |
18
|
|
|
{ |
19
|
|
|
return [ |
20
|
|
|
[ |
21
|
|
|
'class' => '\Micro\Filter\AccessFilter', |
22
|
|
|
'actions' => ['login', 'logout', 'index'], |
23
|
|
|
'rules' => [ |
24
|
|
|
[ |
25
|
|
|
'allow' => false, |
26
|
|
|
'actions' => ['index'], |
27
|
|
|
'users' => ['@'], |
28
|
|
|
'message' => 'Only for not authorized!' |
29
|
|
|
], |
30
|
|
|
[ |
31
|
|
|
'allow' => false, |
32
|
|
|
'actions' => ['login'], |
33
|
|
|
'users' => ['@'], |
34
|
|
|
'message' => 'Not authorized only' |
35
|
|
|
], |
36
|
|
|
[ |
37
|
|
|
'allow' => false, |
38
|
|
|
'actions' => ['logout'], |
39
|
|
|
'users' => ['?'], |
40
|
|
|
'message' => 'Authorized only' |
41
|
|
|
] |
42
|
|
|
] |
43
|
|
|
], |
44
|
|
|
[ |
45
|
|
|
'class' => '\Micro\Filter\CsrfFilter', |
46
|
|
|
'actions' => ['login'] |
47
|
|
|
], |
48
|
|
|
[ |
49
|
|
|
'class' => '\Micro\Filter\XssFilter', |
50
|
|
|
'actions' => ['index', 'login', 'logout'], |
51
|
|
|
'clean' => '*' |
52
|
|
|
] |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function actionIndex() |
57
|
|
|
{ |
58
|
|
|
return new View($this->container); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function actionLogin() |
62
|
|
|
{ |
63
|
|
|
/** @noinspection PhpIncludeInspection */ |
64
|
|
|
$form = new FormBuilder( |
65
|
|
|
include $this->container->kernel->getAppDir() . '/views/default/loginform.php', |
66
|
|
|
new LoginFormModel($this->container), |
67
|
|
|
'POST' |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
if ($post = $this->container->request->post('LoginFormModel')) { |
|
|
|
|
71
|
|
|
$form->setModelData($post); |
72
|
|
|
/** @noinspection PhpUndefinedMethodInspection */ |
73
|
|
|
if ($form->validateModel() && $form->getModel()->logined()) { |
|
|
|
|
74
|
|
|
$this->redirect('/profile'); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$v = new View($this->container); |
79
|
|
|
$v->addParameter('form', $form); |
80
|
|
|
|
81
|
|
|
return $v; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function actionError() |
85
|
|
|
{ |
86
|
|
|
$result = null; |
87
|
|
|
/** @var \Micro\Base\Exception $error */ |
88
|
|
|
if ($error = $this->container->request->post('error')) { |
|
|
|
|
89
|
|
|
$result .= Html::heading(3, $error->getMessage(), ['class' => 'text-danger bg-danger']); |
90
|
|
|
} |
91
|
|
|
$v = new View($this->container); |
92
|
|
|
$v->data = $result ?: 'undefined error'; |
93
|
|
|
|
94
|
|
|
return $v; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function actionLogout() |
98
|
|
|
{ |
99
|
|
|
$this->container->session->destroy(); |
|
|
|
|
100
|
|
|
$this->redirect('/'); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: