| 1 | package Catalyst::Authentication::Store::DBI::ButMaintained::User; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | extends 'Catalyst::Authentication::User'; | |||||||||
| 8 | |||||||||||
| 9 | 1 | has 'store' => ( | |||||||||
| 10 | isa => 'Object' | ||||||||||
| 11 | , is => 'ro' | ||||||||||
| 12 | , required => 1 | ||||||||||
| 13 | , handles => [qw/get_config _safe_escape/] | ||||||||||
| 14 | ); | ||||||||||
| 15 | |||||||||||
| 16 | 1 | has 'authinfo' => ( isa => 'HashRef', is => 'ro', required => 1 ); | |||||||||
| 17 | |||||||||||
| 18 | 1 | has 'user' => ( | |||||||||
| 19 | isa => 'HashRef' | ||||||||||
| 20 | , is => 'ro' | ||||||||||
| 21 | , required => 1 | ||||||||||
| 22 | , traits => ['Hash'] | ||||||||||
| 23 | , handles => { 'get' => 'get' } | ||||||||||
| 24 | ); | ||||||||||
| 25 | |||||||||||
| 26 | ## Currently requires user-role to be joined on single key | ||||||||||
| 27 | ## TODO If we have user_role_table, and role_table AND role_key behave old way | ||||||||||
| 28 | ## Provide option to have no role_table, and to handle composite key roles | ||||||||||
| 29 | ## Append the conditionals in find_user | ||||||||||
| 30 | ## Current workaround is to just subclass this and override the default | ||||||||||
| 31 | ## Now possible with store_user_class | ||||||||||
| 32 | 1 | has 'dbi_model' => ( isa => 'Object', is => 'ro' ); | |||||||||
| 33 | has 'roles' => ( | ||||||||||
| 34 | isa => 'ArrayRef' | ||||||||||
| 35 | , is => 'ro' | ||||||||||
| 36 | , auto_deref => 1 | ||||||||||
| 37 | , lazy => 1 | ||||||||||
| 38 | 0 | ▶ | , default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||
| 39 | 0 | my $self = shift; | |||||||||
| 40 | 0 | my $dbh = $self->dbi_model->dbh; | |||||||||
| 41 | |||||||||||
| 42 | 0 | my @field = ( | |||||||||
| 43 | 'role_table', 'role_name', | ||||||||||
| 44 | 'role_table', | ||||||||||
| 45 | 'user_role_table', | ||||||||||
| 46 | 'user_role_table', 'user_role_role_key', | ||||||||||
| 47 | 'role_table', 'role_key', | ||||||||||
| 48 | 'user_role_table', 'user_role_user_key' | ||||||||||
| 49 | ); | ||||||||||
| 50 | |||||||||||
| 51 | my $sql = sprintf( | ||||||||||
| 52 | 'SELECT %s.%s FROM %s ' | ||||||||||
| 53 | . 'INNER JOIN %s ON %s.%s = %s.%s ' | ||||||||||
| 54 | . 'WHERE %s.%s = ?' | ||||||||||
| 55 | 0 | , map { $dbh->quote_identifier($self->get_config($_)) } @field | |||||||||
| 56 | ); | ||||||||||
| 57 | |||||||||||
| 58 | 0 | ▶ | my $sth = $dbh->prepare_cached($sql) or die($dbh->errstr()); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | |||||||||||
| 60 | 0 | my $role; | |||||||||
| 61 | 0 | ▶ | $sth->execute( $self->get($self->get_config('user_key')) ) or die($dbh->errstr()); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | ▶ | $sth->bind_columns(\$role) or die($dbh->errstr()); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | |||||||||||
| 64 | 0 | my @roles; | |||||||||
| 65 | 0 | ▶ | while ($sth->fetch()) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | push @roles, $role; | |||||||||
| 67 | } | ||||||||||
| 68 | 0 | $sth->finish(); | |||||||||
| 69 | |||||||||||
| 70 | 0 | return \@roles; | |||||||||
| 71 | } | ||||||||||
| 72 | 1 | ); | |||||||||
| 73 | |||||||||||
| 74 | 0 | ▶ | sub id { | ||||||||
|
Subroutine
id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 75 | 0 | my $self = shift; | |||||||||
| 76 | 0 | return $self->get( $self->get_config('user_key') ); | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | # sub supports is implemented by the base class, so supported_features is enough | ||||||||||
| 80 | 0 | ▶ | sub supported_features { +{ session => 1, roles => 1 } } | ||||||||
|
Subroutine
supported_features: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 81 | |||||||||||
| 82 | 0 | ▶ | sub BUILDARGS { | ||||||||
|
Subroutine
BUILDARGS: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 83 | 0 | my $class = shift; | |||||||||
| 84 | 0 | my ( $store, $user ) = @_; | |||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | scalar @_ == 1 | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | ? $class->SUPER::BUILDARGS(@_) | ||||||||||
| 88 | : { store => $store, user => $user } | ||||||||||
| 89 | ; | ||||||||||
| 90 | |||||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | |||||||||||
| 94 | ## These are used in the base class for defaults | ||||||||||
| 95 | ## Deprecated | ||||||||||
| 96 | 0 | ▶ | sub get_object { +shift->user } | ||||||||
|
Subroutine
get_object: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 97 | ## Deprecated | ||||||||||
| 98 | 0 | ▶ | sub obj { +shift->user } | ||||||||
|
Subroutine
obj: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 99 | |||||||||||
| 100 | 1 | 1; | |||||||||
| 101 | |||||||||||
| 102 | __END__ | ||||||||||