Support e.g. ->roles in User::Hash if set appropriately
[catagits/Catalyst-Plugin-Authentication.git] / lib / Catalyst / Plugin / Authentication.pm
index 8f78848..d5173ae 100644 (file)
@@ -2,17 +2,17 @@
 
 package Catalyst::Plugin::Authentication;
 
-use base qw/Class::Accessor::Fast/;
+use base qw/Class::Accessor::Fast Class::Data::Inheritable/;
 
-BEGIN { __PACKAGE__->mk_accessors(qw/user/) }
+BEGIN {
+    __PACKAGE__->mk_accessors(qw/user/);
+    __PACKAGE__->mk_classdata(qw/default_auth_store/);
+}
 
 use strict;
 use warnings;
 
-sub default_auth_store {
-       my $c = shift;
-       $c->config->{authentication}{store};
-}
+our $VERSION = "0.01";
 
 sub set_authenticated {
     my ( $c, $user ) = @_;
@@ -32,7 +32,12 @@ sub logout {
     my $c = shift;
 
     $c->user(undef);
-    delete @{ $c->session }{qw/__user __user_class/};
+
+    if (    $c->isa("Catalyst::Plugin::Session")
+        and $c->config->{authentication}{use_session} )
+    {
+        delete @{ $c->session }{qw/__user __user_class/};
+    }
 }
 
 sub get_user {
@@ -52,7 +57,7 @@ sub prepare {
     my $c = shift->NEXT::prepare(@_);
 
     if (    $c->isa("Catalyst::Plugin::Session")
-        and $c->config->{authentication}{use_session}
+        and $c->default_auth_store
         and !$c->user )
     {
         if ( $c->sessionid and my $user = $c->session->{__user} ) {
@@ -72,6 +77,8 @@ sub setup {
         use_session => 1,
         %$cfg,
     );
+
+    $c->NEXT::setup(@_);
 }
 
 __PACKAGE__;