[Catalyst] Re: Using htpasswd file : New Issue

Tomas Doran bobtfish at bobtfish.net
Sat May 7 15:30:29 GMT 2011


On 7 May 2011, at 14:29, Rohan M wrote:

> Yes. Now the Authentication part is working.
>
> I'm running into one more issue. Now, I'm able to get username from  
> the htpasswd file. But my user information like Name, Address is  
> stored in the database.
>
> Can I add this information (name, address coming from db) in the  
> user object generated from Catalyst::Authentication::Store::Htpasswd ?
>
> Does anyone has idea how to go about this?


http://search.cpan.org/~bobtfish/Catalyst-Authentication-Store-Htpasswd-1.003/lib/Catalyst/Authentication/Store/Htpasswd.pm#user_class

I.e. subclass Catalyst::Authentication::Store::Htpasswd::User as  
MyApp::User, change that config setting, and you can now put extra  
code into your user class...

This gets your part way, but you don't have $c here, so your user  
class can't lookup the extra info in the app..

The solution to that is to also subclass the Store itself, and wrap /  
use an around method modifier on the 'find_user' method - something  
like (in pseudocode):

around find_user => sub {
     my ($orig, $self, $authinfo, $c, @args) = @_;
     my $user = $self->$orig($authinfo, $c, @args);
     $user->extra_field($c->model('DB::User')->find({ username =>  
$user->id })->first->extra_field;
     return $user;
};

Sane error handling (e.g. user does not exist, or user in the htpasswd  
file, but not the DB) is left as an exercise for the reader.

Cheers
t0m




More information about the Catalyst mailing list