=head2 find_user( $userinfo )
-Takes a hashref of C<username>, and possibly openIDish results from
+Takes a hashref of C<username> or C<email>, and possibly openIDish results from
L<Net::OpenID::Consumer>.
Fetches the user object for the given username and returns it.
sub find_user {
my ($self, $userinfo) = @_;
- ## No username means probably an OpenID based user
- if(!exists $userinfo->{username}) {
+ ## A URL field means probably an OpenID based user
+ if( exists $userinfo->{url} ) {
_extract_openid_data($userinfo);
}
- my $username = $userinfo->{username};
-
- ## No logins if user is deactivated (use lookup to fetch to re-activate)
- my $user = $self->lookup(Text::Tradition::User->id_for_user($username));
- return if(!$user || !$user->active);
-
+ my $user;
+ if( exists $userinfo->{username} ) {
+ my $username = $userinfo->{username};
+ ## No logins if user is deactivated (use lookup to fetch to re-activate)
+ $user = $self->lookup(Text::Tradition::User->id_for_user($username));
+ ## If there is an inactive user, skip it
+ return if( $user && !$user->active );
+ } elsif( exists $userinfo->{email} ) {
+ ## Scan the users looking for a matching email
+ my @matches;
+ $self->scan( sub { push( @matches, @_ )
+ if $_[0]->isa('Text::Tradition::User')
+ && $_[0]->email eq $userinfo->{email} } );
+ $user = shift @matches;
+ }
# print STDERR "Found user, $username, email is :", $user->email, ":\n";
-
return $user;
}
is($get_openid_user->id, 'http://blahblah.com/foo/bar/baz/lotsofjunk', 'Set id to unique url from openid');
is($get_openid_user->email, 'fredbloggs@blahblah.com', 'Set email value to email from extension');
}
+
+{
+ ## Find the same openid user just by email
+ my $search_user = $user_store->find_user({ email => 'fredbloggs@blahblah.com' });
+ ok( $search_user, 'Found an OpenID user by email' );
+ is( $search_user->id, 'http://blahblah.com/foo/bar/baz/lotsofjunk', 'User has correct URL ID' );
+ is( $search_user->email, 'fredbloggs@blahblah.com', 'User has correct email' );
+}
\ No newline at end of file