[Catalyst-commits] r6877 - in
trunk/Catalyst-Plugin-Authentication-Store-DBIC: .
lib/Catalyst/Plugin/Authentication/Store
lib/Catalyst/Plugin/Authentication/Store/DBIC t t/lib
bricas at dev.catalyst.perl.org
bricas at dev.catalyst.perl.org
Thu Sep 13 17:35:23 GMT 2007
Author: bricas
Date: 2007-09-13 17:35:22 +0100 (Thu, 13 Sep 2007)
New Revision: 6877
Modified:
trunk/Catalyst-Plugin-Authentication-Store-DBIC/Changes
trunk/Catalyst-Plugin-Authentication-Store-DBIC/lib/Catalyst/Plugin/Authentication/Store/DBIC.pm
trunk/Catalyst-Plugin-Authentication-Store-DBIC/lib/Catalyst/Plugin/Authentication/Store/DBIC/Backend.pm
trunk/Catalyst-Plugin-Authentication-Store-DBIC/lib/Catalyst/Plugin/Authentication/Store/DBIC/User.pm
trunk/Catalyst-Plugin-Authentication-Store-DBIC/t/04auth-clear.t
trunk/Catalyst-Plugin-Authentication-Store-DBIC/t/09authz-cdbi.t
trunk/Catalyst-Plugin-Authentication-Store-DBIC/t/11autocreate.t
trunk/Catalyst-Plugin-Authentication-Store-DBIC/t/lib/TestApp.pm
Log:
fix cdbi breaks from 0.08. expanded how components are loaded from values specified in the config. tabs/newslines.
Modified: trunk/Catalyst-Plugin-Authentication-Store-DBIC/Changes
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIC/Changes 2007-09-13 14:35:16 UTC (rev 6876)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIC/Changes 2007-09-13 16:35:22 UTC (rev 6877)
@@ -3,6 +3,8 @@
0.09 2007-09-13
- remove old DBIC class data tests
- force DBIx::Class and Catalyst::Model::DBIC::Schema pre-reqs
+ - fix broken CDBI code due to changes in 0.08
+ - cleaned up how components are loaded from values specified in the config
0.08 2007-09-06
- Made $c->user->id return the first field of user_field, rather than whatever was passed in.
Modified: trunk/Catalyst-Plugin-Authentication-Store-DBIC/lib/Catalyst/Plugin/Authentication/Store/DBIC/Backend.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIC/lib/Catalyst/Plugin/Authentication/Store/DBIC/Backend.pm 2007-09-13 14:35:16 UTC (rev 6876)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIC/lib/Catalyst/Plugin/Authentication/Store/DBIC/Backend.pm 2007-09-13 16:35:22 UTC (rev 6877)
@@ -32,9 +32,8 @@
my ( $self, $id, @rest ) = @_;
my $user = $self->{auth}{catalyst_user_class}->new( $id, { %{$self} } );
- $user->id($user->canonical_id);
+ $user->id($user->canonical_id);
-
if( $self->{auth}{auto_create_user} and !$user->obj ) {
$self->{auth}{user_class}->auto_create( $id, @rest ) and return $self->get_user( $id );
}
Modified: trunk/Catalyst-Plugin-Authentication-Store-DBIC/lib/Catalyst/Plugin/Authentication/Store/DBIC/User.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIC/lib/Catalyst/Plugin/Authentication/Store/DBIC/User.pm 2007-09-13 14:35:16 UTC (rev 6876)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIC/lib/Catalyst/Plugin/Authentication/Store/DBIC/User.pm 2007-09-13 16:35:22 UTC (rev 6877)
@@ -21,10 +21,10 @@
}
sub obj {
- my $self=shift;
- my $config=$self->config;
- my $id=$self->id;
- unless (ref $self->_obj) {
+ my $self=shift;
+ my $config=$self->config;
+ my $id=$self->id;
+ unless (ref $self->_obj) {
my $query = @{$config->{auth}{user_field}} > 1
? { -or => [ map { { $_ => $id } } @{$config->{auth}{user_field}} ] }
: { $config->{auth}{user_field}[0] => $id };
@@ -34,9 +34,10 @@
}
sub canonical_id {
- my $self=shift;
+ my $self=shift;
return undef unless $self->obj();
- return $self->obj->get_column($self->config->{auth}{user_field}[0]),
+ my $field = $self->config->{auth}{user_field}[0];
+ return $self->obj->$field,
}
Modified: trunk/Catalyst-Plugin-Authentication-Store-DBIC/lib/Catalyst/Plugin/Authentication/Store/DBIC.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIC/lib/Catalyst/Plugin/Authentication/Store/DBIC.pm 2007-09-13 14:35:16 UTC (rev 6876)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIC/lib/Catalyst/Plugin/Authentication/Store/DBIC.pm 2007-09-13 16:35:22 UTC (rev 6877)
@@ -6,6 +6,7 @@
our $VERSION = '0.09';
use Catalyst::Plugin::Authentication::Store::DBIC::Backend;
+use Catalyst::Utils ();
sub setup {
my $c = shift;
@@ -33,10 +34,7 @@
my $config = $c->default_auth_store;
if (my $user_class = $config->{auth}{user_class}) {
- my $model = $c->model($user_class) || $c->comp($user_class);
- $config->{auth}{user_class} = ref $model ? $model
- : $user_class->can('result_source_instance') ? $user_class->result_source_instance->resultset
- : $user_class;
+ $config->{auth}{user_class} = _get_instance( $c, $user_class );
if ($config->{auth}{user_class}->isa('Class::DBI') and
$config->{auth}{catalyst_user_class} eq 'Catalyst::Plugin::Authentication::Store::DBIC::User')
@@ -51,17 +49,59 @@
else {
Catalyst::Exception->throw( message => "You must provide a user_class" );
}
-
+
if (my $role_class = $config->{authz}{role_class}) {
- my $model = $c->model($role_class) || $c->comp($role_class);
- $config->{authz}{role_class} = ref $model ? $model
- : $role_class->can('result_source_instance') ? $role_class->result_source_instance->resultset
- : $role_class;
+ $config->{authz}{role_class} = _get_instance( $c, $role_class );
}
-
+
+ if (my $user_role_class = $config->{authz}{user_role_class}) {
+ $config->{authz}{user_role_class} = _get_instance( $c, $user_role_class );
+ }
+
$c->NEXT::setup_finished(@_);
}
+sub _get_instance {
+ my( $c, $class ) = @_;
+
+ # first see if there's a component already loaded. this means the user
+ # specified the full component name (MyApp::Model::Foo::Bar)
+ my $comp;
+ if( $comp = $c->components->{ $class } ) {
+ return $comp if ref $comp;
+ }
+
+ # second check to see if model() or comp() gives us something. this means
+ # the user specified the part after MyApp::Model only
+ my $model = $c->model($class) || $c->comp($class);
+
+ return $model if ref $model;
+
+ # now we're on to class names only
+
+ # if a component wasn't found, perhaps it's not been loaded yet.
+ if( !$comp ) {
+ eval { Catalyst::Utils::ensure_class_loaded( $class ); };
+ }
+
+ # if the class existed, check to see if it's a dbic class and return a
+ # resultset instance
+ if( $comp || !$@ ){
+ if( $class->can('resulset_instance') ) {
+ return $class->resultset_instance;
+ }
+ return $class;
+ }
+
+ # last case where the model gave us a non-ref which could be an old dbic
+ # class-data style setup
+ if( $model->can('resulset_instance') ) {
+ return $model->resultset_instance;
+ }
+
+ return $model;
+}
+
sub user_object {
my $c = shift;
@@ -88,7 +128,7 @@
# Authentication
__PACKAGE__->config->{authentication}{dbic} = {
- user_class => 'MyApp::Model::DB::User',
+ user_class => 'DB::User',
user_field => 'username',
password_field => 'password',
password_type => 'hashed',
@@ -99,11 +139,11 @@
# For more detailed instructions on setting up role-based auth, please
# see the section below titled L<Roles>.
__PACKAGE__->config->{authorization}{dbic} = {
- role_class => 'MyApp::Model::DB::Role',
+ role_class => 'DB::Role',
role_field => 'role',
role_rel => 'map_user_role', # DBIx::Class only
user_role_user_field => 'user',
- user_role_class => 'MyApp::Model::DB::UserRole', # Class::DBI only
+ user_role_class => 'DB::UserRole', # Class::DBI only
user_role_role_field => 'role', # Class::DBI only
};
@@ -440,9 +480,9 @@
this:
__PACKAGE__->config->{authorization}{dbic} = {
- role_class => 'MyApp::Model::DB::Role',
+ role_class => 'DB::Role',
role_field => 'role',
- user_role_class => 'MyApp::Model::DB::UserRole',
+ user_role_class => 'DB::UserRole',
user_role_user_field => 'user',
user_role_role_field => 'role',
};
Modified: trunk/Catalyst-Plugin-Authentication-Store-DBIC/t/04auth-clear.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIC/t/04auth-clear.t 2007-09-13 14:35:16 UTC (rev 6876)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIC/t/04auth-clear.t 2007-09-13 16:35:22 UTC (rev 6877)
@@ -1,67 +1,67 @@
-#!perl
-
-use strict;
-use warnings;
-use DBI;
-use File::Path;
-use FindBin;
-use Test::More;
-use lib "$FindBin::Bin/lib";
-
-BEGIN {
- eval { require DBD::SQLite }
- or plan skip_all =>
- "DBD::SQLite is required for this test";
-
- eval { require DBIx::Class }
- or plan skip_all =>
- "DBIx::Class is required for this test";
-
- plan tests => 6;
-
- $ENV{TESTAPP_DB_FILE} = "$FindBin::Bin/auth.db";
-
- $ENV{TESTAPP_CONFIG} = {
- name => 'TestApp',
- authentication => {
- dbic => {
- user_class => 'DBICSchema::User',
- user_field => 'username',
- password_field => 'password',
- password_type => 'clear',
- },
- },
- };
-
- $ENV{TESTAPP_PLUGINS} = [
- qw/Authentication
- Authentication::Store::DBIC
- Authentication::Credential::Password
- /
- ];
-}
-
-use SetupDB;
-
-use Catalyst::Test 'TestApp';
-
-# log a user in
-{
- ok( my $res = request('http://localhost/user_login?username=andyg&password=hackme'), 'request ok' );
- is( $res->content, 'logged in', 'user logged in ok' );
-}
-
-# invalid user
-{
- ok( my $res = request('http://localhost/user_login?username=foo&password=bar'), 'request ok' );
- is( $res->content, 'not logged in', 'user not logged in ok' );
-}
-
-# log the user out
-{
- ok( my $res = request('http://localhost/user_logout'), 'request ok' );
- is( $res->content, 'logged out', 'user logged out ok' );
-}
-
-# clean up
-unlink $ENV{TESTAPP_DB_FILE};
+#!perl
+
+use strict;
+use warnings;
+use DBI;
+use File::Path;
+use FindBin;
+use Test::More;
+use lib "$FindBin::Bin/lib";
+
+BEGIN {
+ eval { require DBD::SQLite }
+ or plan skip_all =>
+ "DBD::SQLite is required for this test";
+
+ eval { require DBIx::Class }
+ or plan skip_all =>
+ "DBIx::Class is required for this test";
+
+ plan tests => 6;
+
+ $ENV{TESTAPP_DB_FILE} = "$FindBin::Bin/auth.db";
+
+ $ENV{TESTAPP_CONFIG} = {
+ name => 'TestApp',
+ authentication => {
+ dbic => {
+ user_class => 'DBICSchema::User',
+ user_field => 'username',
+ password_field => 'password',
+ password_type => 'clear',
+ },
+ },
+ };
+
+ $ENV{TESTAPP_PLUGINS} = [
+ qw/Authentication
+ Authentication::Store::DBIC
+ Authentication::Credential::Password
+ /
+ ];
+}
+
+use SetupDB;
+
+use Catalyst::Test 'TestApp';
+
+# log a user in
+{
+ ok( my $res = request('http://localhost/user_login?username=andyg&password=hackme'), 'request ok' );
+ is( $res->content, 'logged in', 'user logged in ok' );
+}
+
+# invalid user
+{
+ ok( my $res = request('http://localhost/user_login?username=foo&password=bar'), 'request ok' );
+ is( $res->content, 'not logged in', 'user not logged in ok' );
+}
+
+# log the user out
+{
+ ok( my $res = request('http://localhost/user_logout'), 'request ok' );
+ is( $res->content, 'logged out', 'user logged out ok' );
+}
+
+# clean up
+unlink $ENV{TESTAPP_DB_FILE};
Modified: trunk/Catalyst-Plugin-Authentication-Store-DBIC/t/09authz-cdbi.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIC/t/09authz-cdbi.t 2007-09-13 14:35:16 UTC (rev 6876)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIC/t/09authz-cdbi.t 2007-09-13 16:35:22 UTC (rev 6877)
@@ -29,7 +29,7 @@
name => 'TestApp',
authentication => {
dbic => {
- user_class => 'TestApp::Model::CDBI::User',
+ user_class => 'CDBI::User',
user_field => 'username',
password_field => 'password',
password_type => 'clear',
@@ -37,9 +37,9 @@
},
authorization => {
dbic => {
- role_class => 'TestApp::Model::CDBI::Role',
+ role_class => 'CDBI::Role',
role_field => 'role',
- user_role_class => 'TestApp::Model::CDBI::UserRole',
+ user_role_class => 'CDBI::UserRole',
user_role_user_field => 'user',
user_role_role_field => 'role',
},
Modified: trunk/Catalyst-Plugin-Authentication-Store-DBIC/t/11autocreate.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIC/t/11autocreate.t 2007-09-13 14:35:16 UTC (rev 6876)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIC/t/11autocreate.t 2007-09-13 16:35:22 UTC (rev 6877)
@@ -1,56 +1,56 @@
-#!perl
-
-use strict;
-use warnings;
-use DBI;
-use File::Path;
-use FindBin;
-use Test::More;
-use lib "$FindBin::Bin/lib";
-
-BEGIN {
- eval { require DBD::SQLite }
- or plan skip_all =>
- "DBD::SQLite is required for this test";
-
- eval { require DBIx::Class }
- or plan skip_all =>
- "DBIx::Class is required for this test";
-
- plan tests => 2;
-
- $ENV{TESTAPP_DB_FILE} = "$FindBin::Bin/auth.db";
-
- $ENV{TESTAPP_CONFIG} = {
- name => 'TestApp',
- authentication => {
- dbic => {
- user_class => 'DBICSchema::User',
- user_field => 'username',
- password_field => 'password',
- password_type => 'clear',
- auto_create_user => 1,
- },
- },
- };
-
- $ENV{TESTAPP_PLUGINS} = [
- qw/Authentication
- Authentication::Store::DBIC
- Authentication::Credential::Password
- /
- ];
-}
-
-use SetupDB;
-
-use Catalyst::Test 'TestApp';
-
-# log a user in
-{
- ok( my $res = request('http://localhost/user_login?username=fred&password=derf'), 'request ok' );
- is( $res->content, 'logged in', 'autocreated user logged in ok' );
-}
-
-# clean up
-unlink $ENV{TESTAPP_DB_FILE};
+#!perl
+
+use strict;
+use warnings;
+use DBI;
+use File::Path;
+use FindBin;
+use Test::More;
+use lib "$FindBin::Bin/lib";
+
+BEGIN {
+ eval { require DBD::SQLite }
+ or plan skip_all =>
+ "DBD::SQLite is required for this test";
+
+ eval { require DBIx::Class }
+ or plan skip_all =>
+ "DBIx::Class is required for this test";
+
+ plan tests => 2;
+
+ $ENV{TESTAPP_DB_FILE} = "$FindBin::Bin/auth.db";
+
+ $ENV{TESTAPP_CONFIG} = {
+ name => 'TestApp',
+ authentication => {
+ dbic => {
+ user_class => 'DBICSchema::User',
+ user_field => 'username',
+ password_field => 'password',
+ password_type => 'clear',
+ auto_create_user => 1,
+ },
+ },
+ };
+
+ $ENV{TESTAPP_PLUGINS} = [
+ qw/Authentication
+ Authentication::Store::DBIC
+ Authentication::Credential::Password
+ /
+ ];
+}
+
+use SetupDB;
+
+use Catalyst::Test 'TestApp';
+
+# log a user in
+{
+ ok( my $res = request('http://localhost/user_login?username=fred&password=derf'), 'request ok' );
+ is( $res->content, 'logged in', 'autocreated user logged in ok' );
+}
+
+# clean up
+unlink $ENV{TESTAPP_DB_FILE};
Modified: trunk/Catalyst-Plugin-Authentication-Store-DBIC/t/lib/TestApp.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-DBIC/t/lib/TestApp.pm 2007-09-13 14:35:16 UTC (rev 6876)
+++ trunk/Catalyst-Plugin-Authentication-Store-DBIC/t/lib/TestApp.pm 2007-09-13 16:35:22 UTC (rev 6877)
@@ -1,93 +1,93 @@
-package TestApp;
-
-use strict;
-use Catalyst;
-use Data::Dumper;
-
-TestApp->config( $ENV{TESTAPP_CONFIG} );
-
-TestApp->setup( @{$ENV{TESTAPP_PLUGINS}} );
-
-sub user_login : Global {
- my ( $self, $c ) = @_;
-
- $c->login;
-
- if ( $c->user_exists ) {
- if ( $c->req->params->{detach} ) {
- $c->detach( $c->req->params->{detach} );
- }
- $c->res->body( 'logged in' );
- }
- else {
- $c->res->body( 'not logged in' );
- }
-}
-
-sub user_logout : Global {
- my ( $self, $c ) = @_;
-
- $c->logout;
-
- if ( ! $c->user ) {
- $c->res->body( 'logged out' );
- }
- else {
- $c->res->body( 'not logged ok' );
- }
-}
-
-sub user_login_session : Global {
- my ( $self, $c ) = @_;
-
- if ( $c->req->params->{username} && $c->req->params->{password} ) {
- $c->login(
- $c->req->params->{username},
- $c->req->params->{password}
- );
-
- if ( $c->user_exists ) {
- $c->res->body( $c->session->{__user} );
- }
- else {
- $c->res->body( 'not logged in' );
- }
- }
-}
-
-sub get_session_user : Global {
- my ( $self, $c ) = @_;
-
- if ( $c->session->{__user} ) {
- $c->res->body( $c->session->{__user} );
- }
-}
-
-sub is_admin : Global {
- my ( $self, $c ) = @_;
-
- if ( $c->check_user_roles( 'admin' ) ) {
- $c->res->body( 'ok' );
- }
-}
-
-sub is_admin_user : Global {
- my ( $self, $c ) = @_;
-
- if ( $c->check_user_roles( qw/admin user/ ) ) {
- $c->res->body( 'ok' );
- }
-}
-
-sub set_usersession : Global {
- my ( $self, $c, $value ) = @_;
- $c->user_session->{foo} = $value;
- $c->res->body( 'ok' );
-}
-
-sub get_usersession : Global {
- my ( $self, $c ) = @_;
- $c->res->body( $c->user_session->{foo} || '' );
-}
-
-1;
+package TestApp;
+
+use strict;
+use Catalyst;
+use Data::Dumper;
+
+TestApp->config( $ENV{TESTAPP_CONFIG} );
+
+TestApp->setup( @{$ENV{TESTAPP_PLUGINS}} );
+
+sub user_login : Global {
+ my ( $self, $c ) = @_;
+
+ $c->login;
+
+ if ( $c->user_exists ) {
+ if ( $c->req->params->{detach} ) {
+ $c->detach( $c->req->params->{detach} );
+ }
+ $c->res->body( 'logged in' );
+ }
+ else {
+ $c->res->body( 'not logged in' );
+ }
+}
+
+sub user_logout : Global {
+ my ( $self, $c ) = @_;
+
+ $c->logout;
+
+ if ( ! $c->user ) {
+ $c->res->body( 'logged out' );
+ }
+ else {
+ $c->res->body( 'not logged ok' );
+ }
+}
+
+sub user_login_session : Global {
+ my ( $self, $c ) = @_;
+
+ if ( $c->req->params->{username} && $c->req->params->{password} ) {
+ $c->login(
+ $c->req->params->{username},
+ $c->req->params->{password}
+ );
+
+ if ( $c->user_exists ) {
+ $c->res->body( $c->session->{__user} );
+ }
+ else {
+ $c->res->body( 'not logged in' );
+ }
+ }
+}
+
+sub get_session_user : Global {
+ my ( $self, $c ) = @_;
+
+ if ( $c->session->{__user} ) {
+ $c->res->body( $c->session->{__user} );
+ }
+}
+
+sub is_admin : Global {
+ my ( $self, $c ) = @_;
+
+ if ( $c->check_user_roles( 'admin' ) ) {
+ $c->res->body( 'ok' );
+ }
+}
+
+sub is_admin_user : Global {
+ my ( $self, $c ) = @_;
+
+ if ( $c->check_user_roles( qw/admin user/ ) ) {
+ $c->res->body( 'ok' );
+ }
+}
+
+sub set_usersession : Global {
+ my ( $self, $c, $value ) = @_;
+ $c->user_session->{foo} = $value;
+ $c->res->body( 'ok' );
+}
+
+sub get_usersession : Global {
+ my ( $self, $c ) = @_;
+ $c->res->body( $c->user_session->{foo} || '' );
+}
+
+1;
More information about the Catalyst-commits
mailing list