use inflate_result for inflating a user object from session data
Matt S Trout [Fri, 5 Oct 2012 15:55:28 +0000 (15:55 +0000)]
Changes
lib/Catalyst/Authentication/Store/DBIx/Class/User.pm

diff --git a/Changes b/Changes
index 4c3e99b..2ecc1c6 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 Revision history for Catalyst-Plugin-Authentication-Store-DBIx-Class
 
+        * Make use_userdata_from_session use inflate_result since this is
+          already-stored data, not a "new" object being created
+
 0.1503  2011-12-08
         * Change docs to show $c->config('Plugin::Authentication' => {...
           rather than $c->config->{authentication}. The new key, and method
index 7c6eb7c..0bc8b6f 100644 (file)
@@ -189,7 +189,17 @@ sub from_session {
 #
 ## if use_userdata_from_session is defined in the config, we fill in the user data from the session.
     if (exists($self->config->{'use_userdata_from_session'}) && $self->config->{'use_userdata_from_session'} != 0) {
-        my $obj = $self->resultset->new_result({ %$frozenuser });
+
+        # We need to use inflate_result here since we -are- inflating a
+        # result object from cached data, not creating a fresh one.
+        # Components such as EncodedColumn wrap new() to ensure that a
+        # provided password is hashed on the way in, and re-running the
+        # hash function on data being restored is expensive and incorrect.
+
+        my $class = $self->resultset->result_class;
+        my $source = $self->resultset->result_source;
+        my $obj = $class->inflate_result($source, { %$frozenuser });
+
         $obj->in_storage(1);
         $self->_user($obj);
         return $self;