Mojolicious-Plugin-RoutesAuthDBI
view release on metacpan or search on metacpan
has [qw(app dbh conf)];
has default => sub {
my $self = shift;
require Mojolicious::Plugin::RoutesAuthDBI::Schema;
{
auth => {
stash_key => PKG."__user__",
current_user_fn => 'auth_user',# helper
load_user => \&load_user,
validate_user => \&validate_user,
},
access => {
namespace => PKG,
module => 'Access',
fail_auth_cb => sub {
shift->render(status => 401, format=>'txt', text=>"Please sign in.\n");
},
fail_access_cb => sub {
shift->render(status => 403, format=>'txt', text=>"You don`t have access on this route (url, action).\n");
},
import => [qw(load_user validate_user)],
},
admin => {
namespace => PKG,
controller => 'Admin',
prefix => lc($self->conf->{admin}{controller} || 'admin'),
trust => hmac_sha1_sum('admin', $self->app->secrets->[0]),
role_admin => 'administrators',
},
template => $Mojolicious::Plugin::RoutesAuthDBI::Schema::defaults,
model_namespace => PKG.'::Model',
guest => {# from Mojolicious::Plugin::Authentication
#~ autoload_user => 1,
session_key => 'guest_data',
stash_key => PKG."__guest__",
#~ current_user_fn => 'current_guest',# helper
#~ load_user => \&load_guest,
#~ validate_user => not need
#~ fail_render => not need
#######end Mojolicious::Plugin::Authentication conf#######
namespace => PKG,
module => 'Guest',
#~ import => [qw(load_guest)],
},
log=>{
namespace => PKG,
module => 'Log',
Hashref options pass to base plugin L<Mojolicious::Plugin::Authentication>.
By default the option:
current_user_fn => 'auth_user',
stash_key => "Mojolicious::Plugin::RoutesAuthDBI__user__",
The options:
load_user => \&load_user,
validate_user => \&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 => {
module => 'Access',
namespace => 'Mojolicious::Plugin::RoutesAuthDBI',
lib/Mojolicious/Plugin/RoutesAuthDBI.pm view on Meta::CPAN
has [qw(app dbh conf)];
has default => sub {
my $self = shift;
require Mojolicious::Plugin::RoutesAuthDBI::Schema;
{
auth => {
stash_key => PKG."__user__",
current_user_fn => 'auth_user',# helper
load_user => \&load_user,
validate_user => \&validate_user,
},
access => {
namespace => PKG,
module => 'Access',
fail_auth_cb => sub {
shift->render(status => 401, format=>'txt', text=>"Please sign in.\n");
},
fail_access_cb => sub {
shift->render(status => 403, format=>'txt', text=>"You don`t have access on this route (url, action).\n");
},
import => [qw(load_user validate_user)],
},
admin => {
namespace => PKG,
controller => 'Admin',
prefix => lc($self->conf->{admin}{controller} || 'admin'),
trust => hmac_sha1_sum('admin', $self->app->secrets->[0]),
role_admin => 'administrators',
},
lib/Mojolicious/Plugin/RoutesAuthDBI.pm view on Meta::CPAN
template => $Mojolicious::Plugin::RoutesAuthDBI::Schema::defaults,
model_namespace => PKG.'::Model',
guest => {# from Mojolicious::Plugin::Authentication
#~ autoload_user => 1,
session_key => 'guest_data',
stash_key => PKG."__guest__",
#~ current_user_fn => 'current_guest',# helper
#~ load_user => \&load_guest,
#~ validate_user => not need
#~ fail_render => not need
#######end Mojolicious::Plugin::Authentication conf#######
namespace => PKG,
module => 'Guest',
#~ import => [qw(load_guest)],
},
log=>{
namespace => PKG,
module => 'Log',
lib/Mojolicious/Plugin/RoutesAuthDBI.pm view on Meta::CPAN
Hashref options pass to base plugin L<Mojolicious::Plugin::Authentication>.
By default the option:
current_user_fn => 'auth_user',
stash_key => "Mojolicious::Plugin::RoutesAuthDBI__user__",
The options:
load_user => \&load_user,
validate_user => \&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 => {
module => 'Access',
namespace => 'Mojolicious::Plugin::RoutesAuthDBI',
lib/Mojolicious/Plugin/RoutesAuthDBI/Access.pm view on Meta::CPAN
package Mojolicious::Plugin::RoutesAuthDBI::Access;
use Mojo::Base -base;
use Exporter 'import';
our @EXPORT_OK = qw(load_user validate_user);
use Mojolicious::Plugin::RoutesAuthDBI::Util qw(load_class);
use Mojo::Util qw(md5_sum);
#~ use Mojo::Exception;
has [qw(app plugin)], undef, weak=>1;
has qw(model);
#~ has model_profiles => sub { shift->plugin->model('Profiles') };
#~ has model => sub {
#~ { map $_ => load_class("Mojolicious::Plugin::RoutesAuthDBI::Model::$_")->new, qw(Profiles Namespaces Routes Refs Controllers Actions Roles) }
lib/Mojolicious/Plugin/RoutesAuthDBI/Access.pm view on Meta::CPAN
unless $p && $p->{id};
#~ eval { Mojo::Exception->throw('load_user') };
#~ $c->app->log->debug($c->dumper($_)) for @{$@->frames};
$c->app->log->debug("Loading profile by id=$uid success");
$p->{pass} = '**********************';
return $p;
}
sub validate_user {# import for Mojolicious::Plugin::Authentication
my ($c, $login, $pass, $extradata) = @_;
return $extradata->{id}
if $extradata && $extradata->{id};
if (my $p = load_class("Mojolicious::Plugin::RoutesAuthDBI::Model::Profiles")->get_profile(undef, $login)) {
#~ if (my $p = $c->model_profiles->get_profile(undef, $login)) {
$c->app->log->debug("Success authenticate by login[$login]/pass[$pass] for profile id[$p->{id}]")
and return $p->{id}
if ($p->{pass} eq $pass || $p->{pass} eq md5_sum($pass))
lib/Mojolicious/Plugin/RoutesAuthDBI/Access.pm view on Meta::CPAN
Hashref of any DB tables names. See L<Mojolicious::Plugin::RoutesAuthDBI::Schema#Default-variables-for-SQL-templates>.
=head1 EXPORT SUBS
=head2 load_user($c, $uid)
Fetch user record from table profiles by COOKIES. Import for Mojolicious::Plugin::Authentication. Required.
=head2 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.
=head1 METHODS
As child of L<Mojolicious::Controller> inherits all parent methods and following ones:
=head2 new(app=> ..., plugin => ...)
Return new access object.
( run in 2.264 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )