Making id_field dynamic - so that session storage works
[catagits/Catalyst-Authentication-Store-DBIx-Class.git] / lib / Catalyst / Plugin / Authentication / Store / DBIx / Class / User.pm
index 9a08fbe..61b46e7 100644 (file)
@@ -22,6 +22,9 @@ sub new {
     bless $self, $class;
     
 
+    if (!exists($self->config->{'id_field'})) {
+        $self->config->{'id_field'} = 'id';
+    }
     
     ## if we have lazyloading turned on - we should not query the DB unless something gets read.
     ## that's the idea anyway - still have to work out how to manage that - so for now we always force
@@ -72,7 +75,7 @@ sub load {
     }
 
     if ($self->get_object) {
-        return $self
+        return $self;
     } else {
         return undef;
     }
@@ -101,7 +104,7 @@ sub roles {
     
     my @roles = ();
     if (exists($self->config->{'role_column'})) {
-        @roles = split /[ ,\|]/, $self->get($self->config->{'role_column'});
+        @roles = split /[ ,\|]+/, $self->get($self->config->{'role_column'});
         $self->_roles(\@roles);
     } elsif (exists($self->config->{'role_relation'})) {
         my $relation = $self->config->{'role_relation'};
@@ -121,7 +124,7 @@ sub roles {
 sub for_session {
     my $self = shift;
     
-    return $self->get('id');
+    return $self->get($self->config->{'id_field'});
 }
 
 sub from_session {
@@ -129,7 +132,7 @@ sub from_session {
     
     # this could be a lot better.  But for now it just assumes $frozenuser is an id and uses find_user
     # XXX: hits the database on every request?  Not good...
-    return $self->load( { id => $frozenuser }, $c);
+    return $self->load( { $self->config->{'id_field'} => $frozenuser }, $c);
 }
 
 sub get {
@@ -175,7 +178,10 @@ This documentation refers to version 0.01.
 
 =head1 SYNOPSIS
 
-use Catalyst::Plugin::Authentication::Store::DBIx::Class::User;
+Internal - not used directly.  use Catalyst::Plugin::Authentication::Store::DBIx::Class::User;
+
+
+                
 
 =head1 DESCRIPTION