Mojolicious::Plugin::RoutesAuthDBI::Access

¡ ¡ ¡ ALL GLORY TO GLORIA ! ! !

NAME

Mojolicious::Plugin::RoutesAuthDBI::Access - Generation routes, authentication and controll access to routes trought sintax of ->over(...), see Mojolicious::Routes::Route#over

DB DESIGN DIAGRAM

See https://github.com/mche/Mojolicious-Plugin-RoutesAuthDBI/blob/master/Diagram.svg

Generate the routes from DB

  • route -> actions.action <- controllers [ <- namespaces]

    Route to action method on controller. If no ref from namespace to controller then controller will find on $app->routes->namespaces as usual.

  • routes -> actions.callback

    Route to callback (no ref to controller, defined callback column (as text "sub {...}") in db table actions)

Access controll flow

There are two ways of flow: explicit and implicit.

  • Explicit access

    Check by tables ids: routes, actions, controllers, namespaces. Check refs to profile roles ids.

  • Implicit access

    Access to routes by names: action, controller, namespace, role. This way used for db route to access namespace and for non db routes by syntax:

    $r->route('/foo')->...->to('foo#bar')->over(access=>{auth=>1})->...; 

    or

    $r->...->over(access=>{auth=>1, role => <id|name>})->...; # access to route by role id|name

See detail Mojolicious::Plugin::RoutesAuthDBI#access

SYNOPSIS

$app->plugin('RoutesAuthDBI', 
    ...
    access => {< hashref options list below >},
    ...
);

OPTIONS for plugin

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

fail_auth_cb => sub {my $c = shift;...}

This callback invoke when request need auth route but authentication was failure.

fail_access_cb

fail_access_cb => sub {my ($c, $route, $r_hash, $u) = @_;...}

This callback invoke when request need auth route but access was failure. $route - Mojolicious::Routes::Route object, $r_hash - route hashref db item, $u - useer hashref.

tables

Hashref of any DB tables names. See Mojolicious::Plugin::RoutesAuthDBI::Schema#Default-variables-for-SQL-templates.

EXPORT SUBS

load_user($c, $uid)

Fetch user record from table profiles by COOKIES. Import for Mojolicious::Plugin::Authentication. Required.

validate_user($c, $login, $pass, $extradata)

Fetch login record from table logins by Mojolicious::Plugin::Authentication. Required. If hashref $extradata->{id} then no fetch and $extradata->{id} will return.

METHODS

As child of Mojolicious::Controller inherits all parent methods and following ones:

new(app=> ..., plugin => ...)

Return new access object.

apply_ns()

Select from db table namespaces ns thus app_ns=1 and push them to $app->namespaces()

apply_route($r_hash)

Heart of routes generation from db tables and not only. Insert to app->routes an hash item $r_hash. DB schema specific. Return new Mojolicious route.

routes()

Fetch records for apply_routes. Must return arrayref of hashrefs routes.

access_explicit($id1, $id2)

Check access to route ($id1 arrayref - either route id or action id or controller id or namespace id) by roles ids ($id2 arrayref). Must return false for deny access or true - allow access.

access_namespace($namespace, $id2)

Check implicit access to route by $namespace for profile roles ids ($id2 arrayref). Must return false for deny access or true - allow access to all actions of this namespace.

access_controller($namespace, $controller, $id2)

Check implicit access to route by $namespace and $controller for profile roles ids ($id2 arrayref). Must return false for deny access or true - allow access to all actions of this controller.

access_action($namespace, $controller, $action, $id2)

Check implicit access to route by $namespace and $controller and $action for profile roles ids ($id2 arrayref). Must return false for deny access or true - allow access to this action.

access_role($role, $id2)

Check implicit access to route by $role (id|name) and profile roles ids ($id2 arrayref). Must return false for deny access or true - allow access.

auth_cookie($c, $cookie_value, $cookie_name)

Returns $c->cookie($cookie_name) unless $cookie_value.

Returns authenticate profile for $cookie_value. I use this method for cordova mobile app then cookie lost on any reasons.

$cookie_name has defaults to $c->app->sessions->cookie_name

SEE ALSO

Mojolicious::Plugin::RoutesAuthDBI

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.