NAME
Mojolicious::Plugin::RoutesAuthDBI::Access - Generation routes, authentication and controll access to routes trought sintax of ->over(...), see Mojolicious::Routes::Route#over
Access controll flow
routes -> roles -> users
controllers -> roles -> users
Access to routes of any actions on controller.
$r->...->to('foo#bar')->over(access=>{auth=>1}); # check access to route by controller name Foo.pm.
roles
Access to route (which not in db) by role id|name
$r->...->over(access=>{auth=>1, role => <id|name>})->...
Generate the routes from DBI
route -> actions.action <- controllers
Route to action method on controller
routes -> actions.callback
Route to callback (no ref to controller, defined callback column (as text "sub {...}") in db table actions)
SYNOPSIS
$app->plugin('RoutesAuthDBI',
dbh => $app->dbh,
auth => {...},
access => {< options below >},
);
namespace - default 'Mojolicious::Plugin::RoutesAuthDBI',
module - default 'Access' (this module),
Both above options determining the module which will play as manager of authentication, accessing and generate routing from DBI source.
fail_auth_cb = sub {my $c = shift;...}
This callback invoke when request need auth route but authentication was failure.
fail_access_cb = sub {my ($c, $route, $r_hash) = @_;...}
This callback invoke when request need auth route but access was failure. $route - Mojolicious::Routes::Route object, $r_hash - route hashref db item.
EXPORT SUBS
load_user($c, $uid) - fetch user record from table users by COOKIES. Import for Mojolicious::Plugin::Authentication. Required.
validate_user($c, $login, $pass, $extradata) - fetch user record from table users by Mojolicious::Plugin::Authentication. Required.
METHODS NEEDS IN PLUGIN
init_class()
Make initialization of class vars: $dbh, $sth, $init_conf. Return $self object controller;
apply_route($self, $app, $r_hash)
Insert to app->routes an hash item $r_hash. DB schema specific. Return new Mojolicious route.
db_routes()
Fetch records for apply_routes. Must return arrayref of hashrefs routes.
load_user_roles($self, $c, $uid)
Fetch records roles for session user. Must return arrayref of hashrefs roles.
access_route($self, $c, $id1, $id2)
Check access to route ($id1) by user roles ids ($id2 arrayref). Must return false for deny access or true - allow access.
access_controller($self, $c, $r, $id2)
Check access to route by $r->{namespace} and $r->{controller} for user roles ids ($id2 arrayref). Must return false for deny access or true - allow access to all actions of this controller.
access_role($self, $c, $r, $id2)
Check access to route by role id|name ($r->{role}) and user roles ids ($id2 arrayref). Must return false for deny access or true - allow access.
AUTHOR
Михаил Че (Mikhail Che), <mche [on] cpan.org>
BUGS / CONTRIBUTING
Please report any bugs or feature requests at https://github.com/mche/Mojolicious-Plugin-RoutesAuthDBI/issues. Pull requests welcome also.
COPYRIGHT
Copyright 2016 Mikhail Che.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.