[Catalyst] Re: Using htpasswd file : New Issue

Rohan M rohan7799 at gmail.com
Mon May 30 15:27:30 GMT 2011


Hi Tomas,

 I got carried away with the other work for the same app. Now I'm back to
this point again.

I created a file called User.pm and put it under Model directory.
After putting,  use base
"Catalyst::Authentication::Store::Htpasswd::User";  I am trying to use
around find_user or any method that is present in the base class but I ended
up getting following error.

"Couldn't load class (MyApp) because: The method 'check_password' was not
found in the inheritance hierarchy."

I'm sorry to ask you again but I'm not sure how the following subclassing
can be done.

Could you send few more details ( example) ?

=3D=3D=3D=3D
package MyApp::Model::User;
use Moose;
use namespace::autoclean;
use Switch;
use base "Catalyst::Authentication::Store::Htpasswd::User";
extends 'Catalyst::Model';


around check_password =3D> sub {
   my ($orig, $self, $authinfo, $c, @args) =3D @_;
   my $user =3D $self->$orig($authinfo, $c, @args);
   return $user;
};

OR

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

Thanks,
Rohan

On Sat, May 7, 2011 at 9:00 PM, Tomas Doran <bobtfish at bobtfish.net> wrote:

>
> 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 t=
he
>> 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 i=
nto
> 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 =3D> sub {
>    my ($orig, $self, $authinfo, $c, @args) =3D @_;
>    my $user =3D $self->$orig($authinfo, $c, @args);
>    $user->extra_field($c->model('DB::User')->find({ username =3D> $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
>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110530/7fb5b=
0e8/attachment.htm


More information about the Catalyst mailing list