|
4 | 4 |
|
5 | 5 | use DevNet\System\Linq; |
6 | 6 | use DevNet\System\Collections\ArrayList; |
| 7 | +use DevNet\Web\Action\ActionController; |
7 | 8 | use DevNet\Web\Action\Filters\Antiforgery; |
8 | 9 | use DevNet\Web\Action\Filters\Authorize; |
9 | 10 | use DevNet\Web\Action\IActionResult; |
10 | | -use DevNet\Web\Controller\AbstractController; |
11 | 11 | use DevNet\Web\Security\Claims\ClaimsIdentity; |
12 | | -use DevNet\Web\Security\Claims\ClaimType; |
13 | 12 | use DevNet\Web\Security\Claims\Claim; |
14 | 13 | use Application\Models\Login; |
15 | 14 | use Application\Models\Registration; |
|
20 | 19 | * This example dosen't encrypt the user password or data, so it's not recommanded for production, |
21 | 20 | * Use DevNet Identity Manager instead, or encrypt you own data. |
22 | 21 | */ |
23 | | -#[Authorize(roles: ['admin', 'member'])] |
24 | | -class AccountController extends AbstractController |
| 22 | +#[Authorize(roles: ['admin', 'user'])] |
| 23 | +class AccountController extends ActionController |
25 | 24 | { |
26 | 25 | public function index(): IActionResult |
27 | 26 | { |
28 | 27 | $user = $this->HttpContext->User; |
29 | | - $claim = $user->findClaim(fn ($claim) => $claim->Type == ClaimType::Name); |
| 28 | + $claim = $user->findClaim(fn ($claim) => $claim->Type == 'Name'); |
30 | 29 | $name = $claim ? $claim->Value : null; |
31 | 30 | $this->ViewData['Name'] = $name; |
32 | 31 | return $this->view(); |
33 | 32 | } |
34 | 33 |
|
35 | | - #[Authorize] |
36 | 34 | #[Antiforgery] |
| 35 | + #[Authorize('Anonymous')] |
37 | 36 | public function login(Login $form): IActionResult |
38 | 37 | { |
39 | 38 | $user = $this->HttpContext->User; |
@@ -67,17 +66,17 @@ public function login(Login $form): IActionResult |
67 | 66 | } |
68 | 67 |
|
69 | 68 | $identity = new ClaimsIdentity('AuthenticationUser'); |
70 | | - $identity->addClaim(new Claim(ClaimType::Name, $user->Name)); |
71 | | - $identity->addClaim(new Claim(ClaimType::Email, $user->Username)); |
72 | | - $identity->addClaim(new Claim(ClaimType::Role, 'member')); |
| 69 | + $identity->addClaim(new Claim('Name', $user->Name)); |
| 70 | + $identity->addClaim(new Claim('Email', $user->Username)); |
| 71 | + $identity->addClaim(new Claim('Role', 'user')); |
73 | 72 | $authentication = $this->HttpContext->Authentication; |
74 | 73 | $authentication->signIn($identity, $form->Remember); |
75 | 74 |
|
76 | 75 | return $this->redirect('/account/index'); |
77 | 76 | } |
78 | 77 |
|
79 | | - #[Authorize] |
80 | 78 | #[AntiForgery] |
| 79 | + #[Authorize('Anonymous')] |
81 | 80 | public function register(Registration $form): IActionResult |
82 | 81 | { |
83 | 82 | $this->ViewData['success'] = false; |
|
0 commit comments