Dancer-Plugin-Auth-RBAC-Credentials-DBIC

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

            "File::Temp" : 0,
            "SQL::Translator" : "0.11006",
            "Test::More" : 0,
            "ok" : 0
         }
      }
   },
   "release_status" : "stable",
   "resources" : {
      "bugtracker" : {
         "mailto" : "bug-dancer-plugin-auth-rbac-credentials-dbic at rt.cpan.org",
         "web" : "http://rt.cpan.org/Public/Dist/Display.html?Name=Dancer-Plugin-Auth-RBAC-Credentials-DBIC"
      },
      "repository" : {
         "type" : "git",
         "url" : "git://github.com/ilmari/Dancer-Plugin-Auth-RBAC-Credentials-DBIC.git",
         "web" : "http://github.com/ilmari/Dancer-Plugin-Auth-RBAC-Credentials-DBIC"
      }
   },
   "version" : "0.003"
}

README  view on Meta::CPAN

    supplied arguments and configuration file options.

CONFIGURATION
    Minimal example:

        plugins:
          DBIC:
            Auth:
              dsn: "dbi:SQLite:dbname=./foo.db"
          Auth::RBAC:
            credentials:
              class: DBIC

    The following config options are avaialable:

    handle
        The handle of the Dancer::Plugin::DBIC schema to use. Only needed if
        you have more than one schema defined.

    user_moniker
        The moniker for the result source which holds your users. Default

lib/Dancer/Plugin/Auth/RBAC/Credentials/DBIC.pm  view on Meta::CPAN

        my $password_field = $options->{password_field} ||= "password";
        my $password_type = $options->{password_type} ||= "clear";
        my $id_field = $options->{id_field} ||= "id";
        my $name_field = $options->{name_field} ||= "name";
        my $role_relation = exists($options->{role_relation}) ? $options->{role_relation} : "roles";
        my $role_name_field = $options->{role_name_field} ||= "name";
        my $user_rs = schema($options->{handle})->resultset($moniker);

        if (my $user = $user_rs->find({ $login_field => $login })) {
            if ($self->_check_password($options, $user, $password)) {
                return $self->credentials({
                    id => $user->$id_field,
                    name => $user->$name_field,
                    login => $user->$login_field,
                    roles => defined($role_relation) ? [ $user->$role_relation->get_column($role_name_field)->all ] : [],
                    error => [],
                });
            }
        }

        $self->errors('login and/or password is invalid');
        return 0;
    }
    else {
        my $user = $self->{credentials};
        if ($user->{id} || $user->{login} && !@{$user->{error}}) {
            return $user;
        }
        else {
            $self->errors('you are not authorized', 'your session may have ended');
            return 0;
        }
    }
}

lib/Dancer/Plugin/Auth/RBAC/Credentials/DBIC.pm  view on Meta::CPAN


=head1 CONFIGURATION

Minimal example:

    plugins:
      DBIC:
        Auth:
          dsn: "dbi:SQLite:dbname=./foo.db"
      Auth::RBAC:
        credentials:
          class: DBIC

The following config options are avaialable:

=over

=item handle

The handle of the L<Dancer::Plugin::DBIC> schema to use.
Only needed if you have more than one schema defined.

t/basic.t  view on Meta::CPAN


done_testing;

__DATA__
---
DBIC:
  Auth:
    schema_class: TestSchema
    dsn: "dbi:SQLite:dbname=:memory:"
Auth::RBAC:
  credentials:
    class: DBIC
    options:
      role_relation:

t/custom.t  view on Meta::CPAN


done_testing();

__DATA__
---
DBIC:
  Auth:
    schema_class: TestSchema
    dsn: "dbi:SQLite:dbname=:memory:"
Auth::RBAC:
  credentials:
    class: DBIC
    options:
      user_moniker: CustomUser
      id_field: uid
      name_field: nickname
      login_field: username
      password_field: passphrase
      password_type: self_check
      role_name_field: rolename



( run in 0.247 second using v1.01-cache-2.11-cpan-4d50c553e7e )