Skip to content

Commit f7d0526

Browse files
committed
update controllers
1 parent 38598b6 commit f7d0526

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

Controllers/AccountController.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
use DevNet\System\Linq;
66
use DevNet\System\Collections\ArrayList;
7+
use DevNet\Web\Action\ActionController;
78
use DevNet\Web\Action\Filters\Antiforgery;
89
use DevNet\Web\Action\Filters\Authorize;
910
use DevNet\Web\Action\IActionResult;
10-
use DevNet\Web\Controller\AbstractController;
1111
use DevNet\Web\Security\Claims\ClaimsIdentity;
12-
use DevNet\Web\Security\Claims\ClaimType;
1312
use DevNet\Web\Security\Claims\Claim;
1413
use Application\Models\Login;
1514
use Application\Models\Registration;
@@ -20,20 +19,20 @@
2019
* This example dosen't encrypt the user password or data, so it's not recommanded for production,
2120
* Use DevNet Identity Manager instead, or encrypt you own data.
2221
*/
23-
#[Authorize(roles: ['admin', 'member'])]
24-
class AccountController extends AbstractController
22+
#[Authorize(roles: ['admin', 'user'])]
23+
class AccountController extends ActionController
2524
{
2625
public function index(): IActionResult
2726
{
2827
$user = $this->HttpContext->User;
29-
$claim = $user->findClaim(fn ($claim) => $claim->Type == ClaimType::Name);
28+
$claim = $user->findClaim(fn ($claim) => $claim->Type == 'Name');
3029
$name = $claim ? $claim->Value : null;
3130
$this->ViewData['Name'] = $name;
3231
return $this->view();
3332
}
3433

35-
#[Authorize]
3634
#[Antiforgery]
35+
#[Authorize('Anonymous')]
3736
public function login(Login $form): IActionResult
3837
{
3938
$user = $this->HttpContext->User;
@@ -67,17 +66,17 @@ public function login(Login $form): IActionResult
6766
}
6867

6968
$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'));
7372
$authentication = $this->HttpContext->Authentication;
7473
$authentication->signIn($identity, $form->Remember);
7574

7675
return $this->redirect('/account/index');
7776
}
7877

79-
#[Authorize]
8078
#[AntiForgery]
79+
#[Authorize('Anonymous')]
8180
public function register(Registration $form): IActionResult
8281
{
8382
$this->ViewData['success'] = false;

Controllers/HomeController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Application\Controllers;
44

5+
use DevNet\Web\Action\ActionController;
56
use DevNet\Web\Action\IActionResult;
6-
use DevNet\Web\Controller\AbstractController;
77

8-
class HomeController extends AbstractController
8+
class HomeController extends ActionController
99
{
1010
public function index(): IActionResult
1111
{

0 commit comments

Comments
 (0)