<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Mojolicious::Plugin::RoutesAuthDBI;
use Mojo::Base 'Mojolicious::Plugin::Authentication';
use Mojolicious::Plugin::RoutesAuthDBI::Util qw(load_class);
use Mojo::Util qw(hmac_sha1_sum);
use Hash::Merge qw( merge );

my $pkg = __PACKAGE__;

has [qw(app dbh conf)];

has default =&gt; sub {
  my $self = shift;
  require Mojolicious::Plugin::RoutesAuthDBI::Schema;
  {
  auth =&gt; {
    stash_key =&gt; $pkg."__user__",
    current_user_fn =&gt; 'auth_user',# helper
    load_user =&gt; \&amp;load_user,
    validate_user =&gt; \&amp;validate_user,
  },
  
  access =&gt; {
    namespace =&gt; $pkg,
    module =&gt; 'Access',
    fail_auth_cb =&gt; sub {
      shift-&gt;render(status =&gt; 401, format=&gt;'txt', text=&gt;"Please sign in.\n");
    },
    fail_access_cb =&gt; sub {
      shift-&gt;render(status =&gt; 403, format=&gt;'txt', text=&gt;"You don`t have access on this route (url, action).\n");
    },
    import =&gt; [qw(load_user validate_user)],
  },
  
  admin =&gt; {
    namespace =&gt; $pkg,
    controller =&gt; 'Admin',
    prefix =&gt; lc($self-&gt;conf-&gt;{admin}{controller} || 'admin'),
    trust =&gt; hmac_sha1_sum('admin', $self-&gt;app-&gt;secrets-&gt;[0]),
    role_admin =&gt; 'administrators',
  },
  
  oauth =&gt; {
    namespace =&gt; $pkg,
    controller =&gt; 'OAuth',
    fail_auth_cb =&gt; sub {shift-&gt;render(format=&gt;'txt', text=&gt;"@_")},
  },
  
  template =&gt; $Mojolicious::Plugin::RoutesAuthDBI::Schema::defaults,
  
  model_namespace =&gt; $pkg.'::Model',
  
  guest =&gt; {# from Mojolicious::Plugin::Authentication
    #~ autoload_user =&gt; 1,
    session_key =&gt; 'guest_data',
    stash_key =&gt; $pkg."__guest__",
    #~ current_user_fn =&gt; 'current_guest',# helper
    #~ load_user =&gt; \&amp;load_guest,
    #~ validate_user =&gt; not need
    #~ fail_render =&gt; not need
    #######end Mojolicious::Plugin::Authentication conf#######
    namespace =&gt; $pkg,
    module =&gt; 'Guest',
    #~ import =&gt; [qw(load_guest)],
  },
  };
};

has merge_conf =&gt; sub {#hashref
  my $self = shift;
  #~ @{ $self-&gt;conf }{qw(app plugin)} = ($self-&gt;app, $self);
  merge($self-&gt;conf, $self-&gt;default);
};

has access =&gt; sub {# object
  my $self = shift;
  my $conf = $self-&gt;merge_conf-&gt;{'access'};
  my $class = load_class($conf);
  $class-&gt;import( @{ $conf-&gt;{import} });
  $class-&gt;new(app=&gt;$self-&gt;app, plugin=&gt;$self,);
};

has admin =&gt; sub {# object
  my $self = shift;
  my $conf = $self-&gt;merge_conf-&gt;{'admin'};
  #~ $conf-&gt;{module} ||= $conf-&gt;{controller};
  load_class($conf)-&gt;init(%$conf, app=&gt;$self-&gt;app, plugin=&gt;$self,);
};

has oauth =&gt; sub {
  my $self = shift;
  my $conf = $self-&gt;merge_conf-&gt;{'oauth'};
  load_class($conf)-&gt;init(%$conf, app=&gt;$self-&gt;app, plugin=&gt;$self, model=&gt;$self-&gt;model($conf-&gt;{controller}),);
};

has guest =&gt; sub {# object
  my $self = shift;
  my $conf = $self-&gt;merge_conf-&gt;{'guest'};
  my $class = load_class($conf);
  #~ $class-&gt;import( @{ $conf-&gt;{import} });
  
  $class-&gt;new( %$conf, app=&gt;$self-&gt;app, plugin=&gt;$self, model=&gt;$self-&gt;model($conf-&gt;{module}), );# plugin=&gt;$self,
};

#~ has model =&gt; sub {
  #~ my $m = { map {$_ =&gt; load_class("Mojolicious::Plugin::RoutesAuthDBI::Model::$_")-&gt;new} qw(Profiles Namespaces Routes Refs Controllers Actions Roles Logins) };
  
#~ };

sub register {
  my $self = shift;
  $self-&gt;app(shift);
  $self-&gt;conf(shift); # global
  
  $self-&gt;dbh($self-&gt;conf-&gt;{dbh} || $self-&gt;app-&gt;dbh);
  $self-&gt;dbh($self-&gt;dbh-&gt;($self-&gt;app))
    if ref($self-&gt;dbh) eq 'CODE';
  die "Plugin must work with dbh, see SYNOPSIS" unless $self-&gt;dbh;
  
  # init base model
  load_class('DBIx::Mojo::Model')-&gt;singleton(dbh=&gt;$self-&gt;dbh, template_vars=&gt;$self-&gt;merge_conf-&gt;{template}, mt=&gt;{tag_start=&gt;'{%', tag_end=&gt;'%}'});
  
  my $access = $self-&gt;access;
  
  die "Plugin [Authentication] already loaded"
    if $self-&gt;app-&gt;renderer-&gt;helpers-&gt;{'authenticate'};
  
  $self-&gt;SUPER::register($self-&gt;app, $self-&gt;merge_conf-&gt;{auth});
  $self-&gt;app-&gt;plugin('HeaderCondition');# routes host_re
  
  $self-&gt;app-&gt;routes-&gt;add_condition(access =&gt; sub {$self-&gt;cond_access(@_)});
  $access-&gt;apply_ns();
  $access-&gt;apply_route($_) for @{ $access-&gt;routes };
  
  if ($self-&gt;conf-&gt;{oauth}) {
    my $oauth = $self-&gt;oauth;
    $access-&gt;apply_route($_) for $oauth-&gt;_routes;
  }
  
  if ($self-&gt;conf-&gt;{admin}) {
    my $admin = $self-&gt;admin;
    $access-&gt;apply_route($_) for $admin-&gt;self_routes;
  }
  
  $self-&gt;guest
    if $self-&gt;conf-&gt;{guest};
  
  $self-&gt;app-&gt;helper('access', sub {$access});
  
  return $self, $access;

}

sub cond_access {# add_condition
  my $self= shift;
  my ($route, $c, $captures, $args) = @_;
  my $conf = $self-&gt;merge_conf;
  my $app = $c-&gt;app;
  my $access = $self-&gt;access;
  #~ $app-&gt;log-&gt;debug($c-&gt;dumper($route));#$route-&gt;pattern-&gt;defaults
  
  my $auth_helper = $conf-&gt;{auth}{current_user_fn};
  my $u = $c-&gt;$auth_helper;
  my $fail_auth_cb = $conf-&gt;{access}{fail_auth_cb};
  
  if (ref $args eq 'CODE') {
    $args-&gt;($u, @_)
      or $self-&gt;deny_log($route, $args, $u)
      and $c-&gt;$fail_auth_cb()
      and return undef;
    $app-&gt;log-&gt;debug(sprintf(qq[Access allow [%s] by callback condition],
      $route-&gt;pattern-&gt;unparsed,
    ));
    return 0x01;
  }
  
  $app-&gt;log-&gt;debug(
    sprintf(qq[Access allow [%s] for none {auth} and none {role} and none {guest}], $route-&gt;pattern-&gt;unparsed)
  )
    and return 1 # 郇迮 郈�郋赲迮��觧菩� 迡郋���郈
    unless $args-&gt;{auth} || $args-&gt;{role} || $args-&gt;{guest};
  
  
  if ($args-&gt;{guest}) {#  &amp;&amp; $args-&gt;{auth} =~ m'\bguest\b'i
    $app-&gt;log-&gt;debug(sprintf(qq[Access allow [%s] for {guest}],
        $route-&gt;pattern-&gt;unparsed,
      ))
      and return 1
      if $self-&gt;guest-&gt;is_guest($c);
  }
  
  # 郇迮 訄赲�郋�邽郱郋赲訄郅���
  $self-&gt;deny_log($route, $args, $u)
    and $c-&gt;$fail_auth_cb()
    and return undef
    unless $u &amp;&amp; $u-&gt;{id};
  
  # 迡郋郈���邽��� 迮�郅邽 {auth=&gt;'only'}
  $app-&gt;log-&gt;debug(sprintf(qq[Access allow [%s] for {auth}=~'only'],
    $route-&gt;pattern-&gt;unparsed,
  ))
    and return 1
    if $args-&gt;{auth} &amp;&amp; $args-&gt;{auth} =~ m'\bonly\b'i;

  my $id2 = [$u-&gt;{id}, map($_-&gt;{id}, grep !$_-&gt;{disable},@{$u-&gt;roles})];
  my $id1 = [grep $_, @$args{qw(id route_id action_id controller_id namespace_id)}];
  
  # explicit acces to route
  scalar @$id1
    &amp;&amp; $access-&gt;access_explicit($id1, $id2)
    &amp;&amp; $app-&gt;log-&gt;debug(sprintf "Access allow [%s] for roles=[%s] joined id1=%s; args=[%s]; defaults=%s",
      $route-&gt;pattern-&gt;unparsed,
      $c-&gt;dumper($id2) =~ s/\s+//gr,
      $c-&gt;dumper($id1) =~ s/\s+//gr,
      $c-&gt;dumper($args) =~ s/\s+//gr,
      $c-&gt;dumper($route-&gt;pattern-&gt;defaults) =~ s/\s+//gr,
    )
    &amp;&amp; return 1;
  
  # Access to non db route by role
  $args-&gt;{role}
    &amp;&amp; $access-&gt;access_role($args-&gt;{role}, $id2)
    &amp;&amp; $app-&gt;log-&gt;debug(sprintf "Access allow [%s] by role [%s]",
      $route-&gt;pattern-&gt;unparsed,
      $args-&gt;{role},
    )
    &amp;&amp; return 1;
  
  # implicit access to non db routes
  my $controller = $args-&gt;{controller} || $route-&gt;pattern-&gt;defaults-&gt;{controller} &amp;&amp; ucfirst(lc($route-&gt;pattern-&gt;defaults-&gt;{controller}));
  my $namespace = $args-&gt;{namespace} || $route-&gt;pattern-&gt;defaults-&gt;{namespace};
  if ($controller &amp;&amp; !$namespace) {
    (load_class(namespace=&gt;$_, controller=&gt;$controller) and ($namespace = $_) and last) for @{ $app-&gt;routes-&gt;namespaces };
    #~ warn "FOUND CONTROLLER[$controller] in NAMESPACE: $namespace";
  }
  
  my $fail_access_cb = $conf-&gt;{access}{fail_access_cb};
  
  $self-&gt;deny_log($route, $args, $u)
    and $c-&gt;$fail_access_cb()
    and return undef
    unless $controller &amp;&amp; $namespace;# failed load class

  $access-&gt;access_namespace($namespace, $id2)
    &amp;&amp; $app-&gt;log-&gt;debug(sprintf "Access allow [%s] for roles=[%s] by namespace=[%s]; args=[%s]; defaults=[%s]",
      $route-&gt;pattern-&gt;unparsed,
      $c-&gt;dumper($id2) =~ s/\s+//gr,
      $namespace,
      $c-&gt;dumper($args) =~ s/\s+//gr,
      $c-&gt;dumper($route-&gt;pattern-&gt;defaults) =~ s/\s+//gr,
    )
    &amp;&amp; return 1;
  
  $access-&gt;access_controller($namespace, $controller, $id2)
    &amp;&amp; $app-&gt;log-&gt;debug(sprintf "Access allow [%s] for roles=[%s] by namespace=[%s] and controller=[%s]; args=[%s]; defaults=[%s]",
      $route-&gt;pattern-&gt;unparsed,
      $c-&gt;dumper($id2) =~ s/\s+//gr,
      $namespace, $controller,
      $c-&gt;dumper($args) =~ s/\s+//gr,
      $c-&gt;dumper($route-&gt;pattern-&gt;defaults) =~ s/\s+//gr,
    )
    &amp;&amp; return 1;
    
  # 迮�亀� �訄郱 郕郋郇��郋郅郅迮�, 郕郋�郋��氵� ��� 訇迮郱 namespace 邽 赲 訇訄郱迮 訇迮郱 namespace ------&gt; 迡郋���郈 邽郱 郅�耨教憶創� 邾迮��訄
  $args-&gt;{namespace} || $route-&gt;pattern-&gt;defaults-&gt;{namespace}
    || $access-&gt;access_controller(undef, $controller, $id2)
    &amp;&amp; $app-&gt;log-&gt;debug(sprintf "Access allow [%s] for roles=[%s] by controller=[%s] without namespace on db; args=[%s]; defaults=[%s]",
      $route-&gt;pattern-&gt;unparsed,
      $c-&gt;dumper($id2) =~ s/\s+//gr,
      $controller,
      $c-&gt;dumper($args) =~ s/\s+//gr,
      $c-&gt;dumper($route-&gt;pattern-&gt;defaults) =~ s/\s+//gr,
    )
    &amp;&amp; return 1;
  
  my $action = $args-&gt;{action} || $route-&gt;pattern-&gt;defaults-&gt;{action}
    or $self-&gt;deny_log($route, $args, $u)
    and $c-&gt;$fail_access_cb()
    and return undef;
  
  $access-&gt;access_action($namespace, $controller, $action, $id2)
    &amp;&amp; $app-&gt;log-&gt;debug(sprintf "Access allow [%s] for roles=[%s] by namespace=[%s] and controller=[%s] and action=[%s]; args=[%s]; defaults=[%s]",
      $route-&gt;pattern-&gt;unparsed,
      $c-&gt;dumper($id2) =~ s/\s+//gr,
      $namespace , $controller, $action,
      $c-&gt;dumper($args) =~ s/\s+//gr,
      $c-&gt;dumper($route-&gt;pattern-&gt;defaults) =~ s/\s+//gr,
    )
    &amp;&amp; return 1;
  
  # 迮�亀� �訄郱 郕郋郇��郋郅郅迮�, 郕郋�郋��氵� ��� 訇迮郱 namespace 邽 赲 訇訄郱迮 訇迮郱 namespace ------&gt; 迡郋���郈 邽郱 郅�耨教憶創� 邾迮��訄
  $args-&gt;{namespace} || $route-&gt;pattern-&gt;defaults-&gt;{namespace}
    &amp;&amp; $access-&gt;access_action(undef, $controller, $action, $id2)
    &amp;&amp; $app-&gt;log-&gt;debug(sprintf "Access allow [%s] for roles=[%s] by (namespace=[any]) controller=[%s] and action=[%s]; args=[%s]; defaults=[%s]",
      $route-&gt;pattern-&gt;unparsed,
      $c-&gt;dumper($id2) =~ s/\s+//gr,
      $controller, $action,
      $c-&gt;dumper($args) =~ s/\s+//gr,
      $c-&gt;dumper($route-&gt;pattern-&gt;defaults) =~ s/\s+//gr,
    )
    &amp;&amp; return 1;
    
  $self-&gt;deny_log($route, $args, $u);
  $c-&gt;$fail_access_cb();
  return undef;
}

sub deny_log {
  my $self = shift;
  my ($route, $args, $u) = @_;
  my $app = $self-&gt;app;
  $app-&gt;log-&gt;debug(sprintf "Access deny [%s] for profile id=[%s]; args=[%s]; defaults=[%s]",
    $route-&gt;pattern-&gt;unparsed,
    $u ? $u-&gt;{id} : 'non auth',
    $app-&gt;dumper($args) =~ s/\s+//gr,
    $app-&gt;dumper($route-&gt;pattern-&gt;defaults) =~ s/\s+//gr,
  );
}

sub model {
  my ($self, $name) = @_;
  my $ns = $self-&gt;merge_conf-&gt;{'model_namespace'};
  my $class =  load_class(namespace =&gt; $ns, module=&gt; $name)
    or die "Model module [$name] not found at namespace [$ns] or has errors";
  
  $class-&gt;new(app=&gt;$self-&gt;app); # �邽郇迣郅迮�郋郇�� 赲 郋訇�亀菩�
  
  #~ my $m = { map {$_ =&gt; load_class("Mojolicious::Plugin::RoutesAuthDBI::Model::$_")-&gt;new} qw(Profiles Namespaces Routes Refs Controllers Actions Roles Logins) };
  
};

our $VERSION = '0.840';

=pod

=encoding utf8

�秴憶敗�郋迣郋 赲�迮邾

癒 癒 癒 ALL GLORY TO GLORIA ! ! !

=head1 Mojolicious::Plugin::RoutesAuthDBI

Plugin makes an auth operations throught the plugin L&lt;Mojolicious::Plugin::Authentication&gt; and OAuth2 by L&lt;Mojolicious::Plugin::OAuth2&gt;.

=head1 VERSION

0.840

=head1 NAME

Mojolicious::Plugin::RoutesAuthDBI - from DBI tables does generate routes, make authentication and make restrict access (authorization) to app routes.

=head1 DB DESIGN DIAGRAM

First of all you will see L&lt;SVG|https://github.com/mche/Mojolicious-Plugin-RoutesAuthDBI/blob/master/Diagram.svg&gt;  or L&lt;PNG|http://i.imgur.com/CwqiB4f.png&gt;

=head1 SYNOPSIS

  $app-&gt;plugin('RoutesAuthDBI',
    dbh =&gt; $app-&gt;dbh,
    auth =&gt; {...},
    access =&gt; {...},
    admin =&gt; {...},
    oauth =&gt; {...},
    guest =&gt; {...},
    template =&gt; {...},
    model_namespace=&gt;...,
  );


=head2 PLUGIN OPTIONS

One option C&lt;dbh&gt; is mandatory, all other - optional.

=head3 dbh

Handler DBI connection where are tables: controllers, actions, routes, logins, profiles, roles, refs and oauth.

  dbh =&gt; $app-&gt;dbh,
  # or
  dbh =&gt; sub { shift-&gt;dbh },

=head3 auth

Hashref options pass to base plugin L&lt;Mojolicious::Plugin::Authentication&gt;.
By default the option:

  current_user_fn =&gt; 'auth_user',
  stash_key =&gt; "Mojolicious::Plugin::RoutesAuthDBI__user__",
    
The options:

  load_user =&gt; \&amp;load_user,
  validate_user =&gt; \&amp;validate_user,

are imported from package access module. See below.

=head3 access

Hashref options for special access module. This module has subs/methods for manage auth and access operations, has appling routes from DBI table. By default plugin will load the builtin module:

  access =&gt; {
    module =&gt; 'Access',
    namespace =&gt; 'Mojolicious::Plugin::RoutesAuthDBI',
    ...,
  },


You might define your own module by passing options:

  access =&gt; {
    module =&gt; 'Foo',
    namespace =&gt; 'Bar::Baz', 
    ...,
  },

See L&lt;Mojolicious::Plugin::RoutesAuthDBI::Access&gt; for detail options list.

=head3 admin

Hashref options for admin controller for actions on SQL tables routes, roles, profiles, logins. By default the builtin module:

  admin =&gt; {
    controller =&gt; 'Admin',
    namespace =&gt; 'Mojolicious::Plugin::RoutesAuthDBI',
    ...,
  },


You might define your own controller by passing options:

  admin =&gt; {
    controller =&gt; 'Foo',
    namespace =&gt; 'Bar::Baz', 
    ...,
  },

See L&lt;Mojolicious::Plugin::RoutesAuthDBI::Admin&gt; for detail options list.

=head3 oauth

Hashref options for oauth controller. By default the builtin module:

  oauth =&gt; {
    controller =&gt; 'OAuth',
    namespace =&gt; 'Mojolicious::Plugin::RoutesAuthDBI',
    ...,
  },


You might define your own controller by passing options:

  oauth =&gt; {
    controller =&gt; 'Foo::Bar::Baz',
    ...,
  },

See L&lt;Mojolicious::Plugin::RoutesAuthDBI::OAuth&gt; for detail options list.

=head3 guest

Hashref options for guest module. Defaults are:

  guest =&gt; {
    namespace =&gt; 'Mojolicious::Plugin::RoutesAuthDBI',
    module =&gt; 'Guest',
    session_key =&gt; 'guest_data',
    stash_key =&gt; "Mojolicious::Plugin::RoutesAuthDBI__guest__",
    
  },

Disable guest module usage:

  guest =&gt; undef, # or none in config

See L&lt;Mojolicious::Plugin::RoutesAuthDBI::Guest&gt;

=head3 model_namespace

Where are your models place. Default to "Mojolicious::Plugin::RoutesAuthDBI::Model".

=head3 template

Hashref variables for SQL templates of models dictionaries. Defaults is C&lt;$Mojolicious::Plugin::RoutesAuthDBI::Schema::defaults&gt;. See L&lt;Mojolicious::Plugin::RoutesAuthDBI::Model::Base&gt;.

=head1 INSTALL

See L&lt;Mojolicious::Plugin::RoutesAuthDBI::Install&gt;.

=head1 OVER CONDITIONS

=head2 access

Heart of this plugin! This condition apply for all db routes even if column auth set to 0. It is possible to apply this condition to non db routes also:

=over 4

=item * No access check to route, but authorization by session will ready:

  $r-&gt;route('/foo')-&gt;...-&gt;over(access=&gt;{auth=&gt;0})-&gt;...;

=item * Allow if has authentication only:

  $r-&gt;route('/foo')-&gt;...-&gt;over(access=&gt;{auth=&gt;'only'})-&gt;...;
  # same as
  # $r-&gt;route('/foo')-&gt;...-&gt;over(authenticated =&gt; 1)-&gt;...; # see Mojolicious::Plugin::Authentication

=item * Allow for guest

  $r-&gt;route('/foo')-&gt;...-&gt;over(access=&gt;{guest=&gt;1})-&gt;...;
  
To makes guest session:

  $c-&gt;access-&gt;plugin-&gt;guest-&gt;store($c, {&lt;...some data...&gt;});

See L&lt;Mojolicious::Plugin::RoutesAuthDBI::Guest&gt;

=item * Route accessible if profile roles assigned to either B&lt;loadable&gt; namespace or controller 'Bar.pm' (which assigned neither namespece on db or assigned to that loadable namespace) or action 'bar' on controller Bar.pm (action record in db table actions):

  $r-&gt;route('/bar-bar-any-namespace')-&gt;to('bar#bar',)-&gt;over(access=&gt;{auth=&gt;1})-&gt;...;

=item * Explicit defined namespace route accessible either namespace 'Bar' or 'Bar::Bar.pm' controller or action 'bar' in controller 'Bar::Bar.pm' (which assigned to namespace 'Bar' in table refs):

  $r-&gt;route('/bar-bar-bar')-&gt;to('bar#bar', namespace=&gt;'Bar')-&gt;over(access=&gt;{auth=&gt;1})-&gt;...;

=item * Check access by overriden namespace 'BarX': controller and action also with that namespace in db table refs:

  $r-&gt;route('/bar-nsX')-&gt;to('bar#bar', namespace=&gt;'Bar')-&gt;over(access=&gt;{auth=&gt;1, namespace=&gt;'BarX'})-&gt;...;

=item * Check access by overriden namespace 'BarX' and controller 'BarX.pm', action record also with that ns &amp; c in db table refs:

  $r-&gt;route('/bar-nsX-cX')-&gt;to('bar#bar', namespace=&gt;'Bar')-&gt;over(access=&gt;{auth=&gt;1, namespace=&gt;'BarX', controller=&gt;'BarX'})-&gt;...;

=item * Full override names access:

  $r-&gt;route('/bar-nsX-cX-aX')-&gt;to('bar#bar', namespace=&gt;'Bar')-&gt;over(access=&gt;{auth=&gt;1, namespace=&gt;'BarX', controller=&gt;'BarX', action=&gt;'barX'})-&gt;...;

=item *

  $r-&gt;route('/bar-cX-aX')-&gt;to('bar#bar',)-&gt;over(access=&gt;{auth=&gt;1, controller=&gt;'BarX', action=&gt;'barX'})-&gt;...;

=item * Route accessible if profile roles list has defined role (admin):

  $r-&gt;route('/bar-role-admin')-&gt;to('bar#bar',)-&gt;over(access=&gt;{auth=&gt;1, role=&gt; 'admin'})-&gt;...;
  
=item * Pass callback to access condition

The callback will get parameters: $profile, $route, $c, $captures, $args (this callback ref). Callback must returns true or false for restrict access. Example simple auth access:

  $r-&gt;route('/check-auth')-&gt;over(access=&gt;sub {my ($profile, $route, $c, $captures, $args) = @_; return $profile;})-&gt;to(cb=&gt;sub {my $c =shift; $c-&gt;render(format=&gt;'txt', text=&gt;"Hi @{[$c-&gt;auth_user-&gt;{names}]}!\n\nYou have access!");});

=back

=head1 HELPERS

=head2 access

Returns access instance obiect. See L&lt;Mojolicious::Plugin::RoutesAuthDBI::Access&gt; methods.

  if ($c-&gt;access-&gt;access_explicit([1,2,3], [1,2,3])) {
    # yes, accessible
  }

=head1 METHODS and SUBS

Registration() &amp; access() &amp; &lt;internal&gt;.

=head2 Example routing table records

    Request
    HTTP method(s) (optional)
    and the URL (space delim)
                               Contoller    Method          Route Name        Auth
    -------------------------  -----------  --------------  ----------------- -----
    GET /city/new              City         new_form        city_new_form     1
    GET /city/:id              City         show            city_show         1
    GET /city/edit/:id         City         edit_form       city_edit_form    1
    GET /cities                City         index           city_index        1
    POST /city                 City         save            city_save         1
    GET /city/delete/:id       City         delete_form     city_delete_form  1
    DELETE /city/:id           City         delete          city_delete       1
    /                          Home         index           home_index        0
    get post /foo/baz          Foo          baz             foo_baz           1

It table will generate the L&lt;Mojolicious routes|http://mojolicious.org/perldoc/Mojolicious/Guides/Routing&gt;:

    # GET /city/new 
    $r-&gt;route('/city/new')-&gt;via('get')-&gt;over(&lt;access&gt;)-&gt;to(controller =&gt; 'city', action =&gt; 'new_form')-&gt;name('city_new_form');

    # GET /city/123 - show item with id 123
    $r-&gt;route('/city/:id')-&gt;via('get')-&gt;over(&lt;access&gt;)-&gt;to(controller =&gt; 'city', action =&gt; 'show')-&gt;name('city_show');

    # GET /city/edit/123 - form to edit an item
    $r-&gt;route('/city/edit/:id')-&gt;via('get')-&gt;over(&lt;access&gt;)-&gt;to(controller =&gt; 'city', action =&gt; 'edit_form')-&gt;name('city_edit_form');

    # GET /cities - list of all items
    $r-&gt;route('/cities')-&gt;via('get')-&gt;over(&lt;access&gt;)-&gt;to(controller =&gt; 'city', action =&gt; 'index')-&gt;name('cities_index');

    # POST /city - create new item or update the item
    $r-&gt;route('/city')-&gt;via('post')-&gt;to(controller =&gt; 'city', action =&gt; 'save')-&gt;name('city_save');
    
    # GET /city/delete/123 - form to confirm delete an item id=123
    $r-&gt;route('/city/delete/:id')-&gt;via('get')-&gt;over(&lt;access&gt;)-&gt;to(controller =&gt; 'city', action =&gt; 'delete_form')-&gt;name('city_delete_form');

    # DELETE /city/123 - delete an item id=123
    $r-&gt;route('/city/:id')-&gt;via('delete')-&gt;over(&lt;access&gt;)-&gt;to(controller =&gt; 'city', action =&gt; 'delete')-&gt;name('city_delete');
        
    # without HTTP method and no auth restrict
    $r-&gt;route('/')-&gt;to(controller =&gt; 'Home', action =&gt; 'index')-&gt;name('home_index');
        
    # GET or POST /foo/baz 
    $r-&gt;route('/foo/baz')-&gt;via('GET', 'post')-&gt;over(&lt;access&gt;)-&gt;to(controller =&gt; 'Foo', action =&gt; 'baz')-&gt;name('foo_baz');

=head2 Warning

If you changed the routes table then kill -HUP or reload app to regenerate routes. Changing assess not require reloading the service.

=head1 SEE ALSO

L&lt;Mojolicious::Plugin::Authentication&gt;

L&lt;Mojolicious::Plugin::Authorization&gt;

=head1 AUTHOR

�婧解�訄邽郅 虴迮 (Mikhail Che), C&lt;&lt; &lt;mche[-at-]cpan.org&gt; &gt;&gt;

=head1 BUGS / CONTRIBUTING

Please report any bugs or feature requests at L&lt;https://github.com/mche/Mojolicious-Plugin-RoutesAuthDBI/issues&gt;. Pull requests also welcome.

=head1 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.

=cut

</pre></body></html>