# constant->import(have_want => eval { require Want });
#}
-our $VERSION = "0.04";
+our $VERSION = "0.09";
sub set_authenticated {
my ( $c, $user ) = @_;
return $c->_user(@_);
}
- my $user = $c->_user;
-
- if ( $user and !Scalar::Util::blessed($user) ) {
-# return 1 if have_want() && Want::want("BOOL");
- return $c->auth_restore_user($user);
+ if ( defined(my $user = $c->_user) ) {
+ return $user;
+ } else {
+ return $c->auth_restore_user;
}
-
- return $user;
}
sub user_exists {
my $c = shift;
- return defined($c->_user);
+ return defined($c->_user) || defined($c->_user_in_session);
}
sub save_user_in_session {
$c->user(undef);
- if ( $c->isa("Catalyst::Plugin::Session")
- and $c->config->{authentication}{use_session} )
- {
+ if (
+ $c->isa("Catalyst::Plugin::Session")
+ and $c->config->{authentication}{use_session}
+ and $c->session_is_valid
+ ) {
delete @{ $c->session }{qw/__user __user_store/};
}
}
sub get_user {
- my ( $c, $uid ) = @_;
+ my ( $c, $uid, @rest ) = @_;
if ( my $store = $c->default_auth_store ) {
- return $store->get_user($uid);
+ return $store->get_user( $uid, @rest );
}
else {
Catalyst::Exception->throw(
}
}
-sub prepare {
- my $c = shift->NEXT::prepare(@_);
+sub _user_in_session {
+ my $c = shift;
- if ( $c->isa("Catalyst::Plugin::Session")
- and !$c->user )
- {
- if ( $c->sessionid and my $frozen_user = $c->session->{__user} ) {
- $c->_user($frozen_user);
- }
- }
+ return unless
+ $c->isa("Catalyst::Plugin::Session")
+ and $c->config->{authentication}{use_session}
+ and $c->session_is_valid;
+
+ return $c->session->{__user};
- return $c;
+ return;
}
sub auth_restore_user {
my ( $c, $frozen_user, $store_name ) = @_;
- return
- unless $c->isa("Catalyst::Plugin::Session")
- and $c->config->{authentication}{use_session}
- and $c->sessionid;
+ $frozen_user ||= $c->_user_in_session;
+ return unless defined($frozen_user);
$store_name ||= $c->session->{__user_store};
- $frozen_user ||= $c->session->{__user};
+ return unless $store_name; # FIXME die unless? This is an internal inconsistency
my $store = $c->get_auth_store($store_name);
$c->_user( my $user = $store->from_session( $c, $frozen_user ) );
}
}
-Since the C<login> method knows how to find logically named parameters on it's
+Since the C<login> method knows how to find logically named parameters on its
own.
The credential verifier will ask the default store to get the user whose ID is
If you're just going to say
- if ( $c->user_user ) {
+ if ( $c->user_exists ) {
# foo
} else {
$c->forward("login");
}
-it should be more efficient than C<< $c->user >> when a user is marked in the session
-but C<< $c->user >> hasn't been called yet.
+it should be more efficient than C<< $c->user >> when a user is marked in the
+session but C<< $c->user >> hasn't been called yet.
=item logout