-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tutorial #282
Comments
If I find time, I'll create an "examples" page in the wiki, with a user authentication section. However, if you just need some code to get you started: $klein = new Klein\Klein();
$klein->respond('/unauthorised', function () {
return 'You do not have access to this page!';
});
$klein->with('/admin', function () use ($klein) {
// this will be run when anyone
// navigates to a route beginning
// with "/admin".
$klein->respond(function ($request, $response) {
$hasAccess = Auth::isAuthorized();
// redirect if not authorized
if ( ! $hasAccess) {
$response->redirect('/unauthorized');
}
});
$klein->respond('/?', function () {
return 'Admin Home Page!';
});
});
$klein->dispatch(); This code is untested. |
Instead of redirecting, it might be better to use $klein->abort(403), and set up a 403 block in the onHttpError handler:
I do wish the abort method were on the $response object instead of the $klein object, though. |
Nice catch. :) I keep forgetting about the |
In |
$klein->onHttpError(function ($code, $router) {
$app = $router->app();
}); |
That works, thanks @nbish11 |
Hi,
just wondering if there are any tutorials for this library.
I wanna use it to filter users as that is allow user access to a page based on his session.
can you show some examples as to how your library works
The text was updated successfully, but these errors were encountered: