Skip to content

Commit beda98f

Browse files
committed
update docs content
1 parent 9dd0514 commit beda98f

File tree

6 files changed

+55
-59
lines changed

6 files changed

+55
-59
lines changed

src/app/core/extension/extension.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ <h1>Extension Methods</h1>
1212
</p>
1313
<h3>Extended class</h3>
1414
<p>
15-
The extended class is the class that the extension method operates on, and must include the trait <code>DevNet\System\Tweak</code> to enable this feature like in the following eample:
15+
The extended class is the class that the extension method operates on, and must include the trait <code>DevNet\System\Tweak</code> to enable this feature like in the following code example:
1616
</p>
1717
<pre><code class="language-php">&lt;?php
1818

@@ -84,7 +84,7 @@ <h3>Calling the extension method</h3>
8484
</a>
8585
</li>
8686
<li class="nav-page-item">
87-
<a class="nav-page-link" routerLink="/docs/core/generics">
87+
<a class="nav-page-link" routerLink="/docs/core/linq">
8888
Next <i class="chevron right"></i>
8989
</a>
9090
</li>

src/app/security/authentication/authentication.component.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ <h3>Configuration</h3>
3535
use DevNet\Web\Hosting\WebHost;
3636
use DevNet\Web\Extensions\ApplicationBuilderExtensions;
3737
use DevNet\Web\Extensions\ServiceCollectionExtensions;
38+
use DevNet\Web\Security\Authentication\AuthenticationScheme;
3839

3940
class Program
4041
&lcub;
@@ -90,7 +91,6 @@ <h3>Cookie-based Authentication</h3>
9091
use DevNet\Web\Http\HttpContext;
9192
use DevNet\Web\Security\Authentication\AuthenticationScheme;
9293
use DevNet\Web\Security\ClaimsIdentity;
93-
use DevNet\Web\Security\ClaimsType;
9494
...
9595

9696
$app->useEndpoint(function($routes) &lcub;
@@ -109,8 +109,8 @@ <h3>Cookie-based Authentication</h3>
109109
}
110110

111111
$identity = new ClaimsIdentity(AuthenticationScheme::CookieSession);
112-
$identity->addClaim(new Claim(ClaimType::Identifier , $form->getValue('username')));
113-
$identity->addClaim(new Claim(ClaimType::Role, 'member'));
112+
$identity->addClaim(new Claim('Username' , $form->getValue('username')));
113+
$identity->addClaim(new Claim('Role', $user->Role));
114114

115115
$context->Authentication->signIn($identity, $form->getValue('remember'));
116116
}
@@ -161,7 +161,7 @@ <h3>Token-based Authentication</h3>
161161

162162
$claims = new ClaimsIdentity(AuthenticationScheme::JwtBearer);
163163
$claims->addClaim(new Claim('sub', $form->getValue('username')));
164-
$claims->addClaim(new Claim('role', 'member'));
164+
$claims->addClaim(new Claim('role', $user->Role));
165165
$claims->addClaim(new Claim('iss', '127.0.0.1:8000'));
166166
$claims->addClaim(new Claim('aud', '127.0.0.1:8080'));
167167

@@ -190,7 +190,7 @@ <h3>Token-based Authentication</h3>
190190
</a>
191191
</li>
192192
<li class="nav-page-item">
193-
<a class="nav-page-link" routerLink="/docs/security/authorisation">
193+
<a class="nav-page-link" routerLink="/docs/security/authorization">
194194
Next <i class="chevron right"></i>
195195
</a>
196196
</li>

src/app/security/overview/overview.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ <h1>Overview</h1>
1313
<ul>
1414
<li>Cookie-based Authentication</li>
1515
<li>Token-based Authentication</li>
16-
<li>Policy-based Authorisation</li>
17-
<li>Role-based Authorisation</li>
16+
<li>Role-based Authorization</li>
17+
<li>Policy-based Authorization</li>
1818
<li>Identity Manager</li>
1919
<li>CSRF Prevention</li>
2020
</ul>

src/app/shared/sidebar/sidebar.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
<li><a class="link-dark d-inline-flex text-decoration-none rounded" routerLink="/docs/core/overview" routerLinkActive="fw-bold">Overview</a></li>
3535
<li><a class="link-dark d-inline-flex text-decoration-none rounded" routerLink="/docs/core/properties" routerLinkActive="fw-bold">Computed Properties</a></li>
3636
<li><a class="link-dark d-inline-flex text-decoration-none rounded" routerLink="/docs/core/extension" routerLinkActive="fw-bold">Extension Methods</a></li>
37+
<li><a class="link-dark d-inline-flex text-decoration-none rounded" routerLink="/docs/core/linq" routerLinkActive="fw-bold">LINQ Methods</a></li>
3738
<li><a class="link-dark d-inline-flex text-decoration-none rounded" routerLink="/docs/core/generics" routerLinkActive="fw-bold">Generic Types</a></li>
3839
<li><a class="link-dark d-inline-flex text-decoration-none rounded" routerLink="/docs/core/asynchronous" routerLinkActive="fw-bold">Async Operations</a></li>
3940
<li><a class="link-dark d-inline-flex text-decoration-none rounded" routerLink="/docs/core/delegate" routerLinkActive="fw-bold">Event Delegate</a></li>
40-
<li><a class="link-dark d-inline-flex text-decoration-none rounded" routerLink="/docs/core/linq" routerLinkActive="fw-bold">LINQ</a></li>
4141
<li><a class="link-dark d-inline-flex text-decoration-none rounded" routerLink="/docs/core/diagnostics" routerLinkActive="fw-bold">Diagnostics</a></li>
4242
</ul>
4343
</div>

src/app/web/filter/filter.component.html

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -28,61 +28,25 @@ <h1>Action Filter</h1>
2828
#[Attribute]
2929
class AuthenticationFilter implements IActionFilter
3030
&lcub;
31-
use Tweak;
31+
use Tweak;
3232

33-
public function async_invoke(ActionContext $context, ActionDelegate $next): void
34-
&lcub;
35-
// short-circuiting the pipeline if does not fulfil the condition.
36-
if (!$context->HttpContext->User) &lcub;
37-
$context->HttpContext->Response->setStatusCode(401);
38-
return;
39-
}
40-
// await next action delegate to chain the pipline to the next filter befor executing the action.
41-
await($next($context));
42-
// logging or other works can be done here after executing the action.
43-
}
44-
}
45-
</code></pre>
46-
<br>
47-
<h3>Apply Filters</h3>
48-
<p>
49-
Any action filter that implements the interface <code>DevNet\Web\Action\IActionFilter</code> can be applied to the route endpoint handler or to the controller, but to apply an action filter to a controller, the action filter class must be declared as an attribute because the controller accepts only action filters as attributes, and if the action filter attribute is applied to the class of controller it will be applied to all the action methods of the controller, and if it is applied only to a specific action method of a controller it will be applied only to that specific action method.
50-
</p>
51-
<p>
52-
The following code represents an example of applying action filters to a controller as attributes.
53-
</p>
54-
<pre><code class="language-php">&lt;?php
55-
56-
namespace Application\Controllers;
57-
58-
use DevNet\Web\Action\ActionController;
59-
use DevNet\Web\Action\IActionResult;
60-
use DevNet\Web\Action\Filters\HttpMethod;
61-
use DevNet\Web\Action\Filters\Antiforgery;
62-
use Application\Filters\AuthenticationFilter;
63-
use Application\Models\Profile;
64-
65-
// this filter will be applied to all controller's methods.
66-
#[AuthenticationFilter]
67-
class UserController extends ActionController
68-
&lcub;
69-
public function index(): IActionResult
70-
&lcub;
71-
return $this->view();
72-
}
73-
74-
// this filters will be applied only to this action method.
75-
#[Antiforgery]
76-
#[HttpMethod('post')]
77-
public function edit(Profile $form): IActionResult
33+
public function async_invoke(ActionContext $context, ActionDelegate $next): void
7834
&lcub;
79-
// code...
35+
// short-circuiting the pipeline if does not fulfil the condition.
36+
if (!$context->HttpContext->User) &lcub;
37+
$context->HttpContext->Response->setStatusCode(401);
38+
return;
39+
}
40+
// await next action delegate to chain the pipline to the next filter befor executing the action.
41+
await($next($context));
42+
// logging or other works can be done here after executing the action.
8043
}
8144
}
8245
</code></pre>
8346
<br>
47+
<h3>Registering action filters</h3>
8448
<p>
85-
The next code example shows how to add action filters to the route endpoint handler, as class or as an anonymous async function, with the help of the method <code>RouteHandler::addFilter(callable|string $filter, ...$args)</code>
49+
The code example below shows how to add action filters to the route endpoint handler as class or as an anonymous async function, with the help of the method <code>RouteHandler::addFilter(callable|string $filter, ...$args)</code>
8650
</p>
8751
<pre><code class="language-php">&lt;?php
8852

@@ -116,6 +80,38 @@ <h3>Apply Filters</h3>
11680
// other routes.
11781
});
11882
});</code></pre>
83+
<p>
84+
You can apply the action filter to a controller using the attribute syntax and decorate the controller class or the action method with the filter name, as shown in the following code example.
85+
</p>
86+
<pre><code class="language-php">&lt;?php
87+
88+
namespace Application\Controllers;
89+
90+
use DevNet\Web\Action\ActionController;
91+
use DevNet\Web\Action\IActionResult;
92+
use DevNet\Web\Action\Filters\HttpMethod;
93+
use DevNet\Web\Action\Filters\Antiforgery;
94+
use Application\Filters\AuthenticationFilter;
95+
use Application\Models\Profile;
96+
97+
// this filter will be applied to all controller's methods.
98+
#[AuthenticationFilter]
99+
class UserController extends ActionController
100+
&lcub;
101+
public function index(): IActionResult
102+
&lcub;
103+
return $this->view();
104+
}
105+
106+
// this filters will be applied only to this action method.
107+
#[Antiforgery]
108+
#[HttpMethod('post')]
109+
public function edit(Profile $form): IActionResult
110+
&lcub;
111+
// code...
112+
}
113+
}
114+
</code></pre>
119115
<br>
120116
<h3>Built-in filters</h3>
121117
<table class="table">

src/app/web/middleware/middleware.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ <h1>Middleware</h1>
4949
}
5050
}</code></pre>
5151
<br>
52-
<h3>Registring Middlewares</h3>
52+
<h3>Registering Middlewares</h3>
5353
<p>
5454
Inside the method <code>WebHost::start(Closure $configure)</code>, middlewares can be registered to the pipeline as a class that implements the interface <code>DevNet\Web\Middleware\IMiddleware</code> or as an in-line middleware defined by an anonymous async function, with the help of the following methods:
5555
</p>

0 commit comments

Comments
 (0)