1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Components\Controller; |
6
|
|
|
use App\Components\View; |
7
|
|
|
use App\Models\User; |
8
|
|
|
use Micro\Web\RequestInjector; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class RegisterController |
12
|
|
|
* @package App\Controllers |
13
|
|
|
*/ |
14
|
|
|
class RegisterController extends Controller |
15
|
|
|
{ |
16
|
|
|
public function filters() |
17
|
|
|
{ |
18
|
|
|
return [ |
19
|
|
|
[ |
20
|
|
|
'class' => '\Micro\Filter\AccessFilter', |
21
|
|
|
'actions' => ['success', 'error', 'index', 'post'], |
22
|
|
|
'rules' => [ |
23
|
|
|
[ |
24
|
|
|
'allow' => false, |
25
|
|
|
'actions' => ['index', 'success', 'error', 'post'], |
26
|
|
|
'users' => ['@'], |
27
|
|
|
'message' => 'Only for not authorized!' |
28
|
|
|
] |
29
|
|
|
] |
30
|
|
|
], |
31
|
|
|
[ |
32
|
|
|
'class' => '\Micro\Filter\CsrfFilter', |
33
|
|
|
'actions' => ['index'] |
34
|
|
|
], |
35
|
|
|
[ |
36
|
|
|
'class' => '\Micro\Filter\XssFilter', |
37
|
|
|
'actions' => ['post'], |
38
|
|
|
'clean' => '*' |
39
|
|
|
] |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function actionIndex() |
44
|
|
|
{ |
45
|
|
|
$v = new View; |
46
|
|
|
$v->addParameter('model', new User); |
47
|
|
|
|
48
|
|
|
return $v; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function actionSuccess() |
52
|
|
|
{ |
53
|
|
|
return new View; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function actionError() |
57
|
|
|
{ |
58
|
|
|
return new View; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function actionPost() |
62
|
|
|
{ |
63
|
|
|
$body = (new RequestInjector)->build()->getParsedBody(); |
64
|
|
|
|
65
|
|
|
if (!empty($body['User'])) { |
66
|
|
|
$user = new User(); |
67
|
|
|
$user->setModelData($body['User']); |
68
|
|
|
$user->pass = md5($user->pass); |
69
|
|
|
|
70
|
|
|
if ($user->validate() && $user->save()) { |
71
|
|
|
return $this->redirect('/register/success'); |
72
|
|
|
} |
73
|
|
|
return $this->redirect('/register/error'); |
74
|
|
|
} |
75
|
|
|
return $this->redirect('/register'); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|