[Catalyst] Advice for Catalyst::Plugin::Authentication::Store::DBIC needed

leonard.a.jaffe at jpmchase.com leonard.a.jaffe at jpmchase.com
Wed Oct 4 20:44:29 CEST 2006


------------------------------------------------------------------------------
Leonard A. Jaffe      (614)213-4283
JP Morgan Chase, Columbus, OH 
DSS Monitoring Instrumentation Services
leonard.a.jaffe at jpmchase.com



Bernhard Graf wrote:
> In a Cat application I use C:P::Authentication::Store::DBIC and it works 

> well.
> 
> But now I need to modify authentication a little bit:
> A status field of the user object should also be checked, e.g. grant 
> access only if status is set to "active".
> 
> Documentation of the module mentions a configuration field named 
> "catalyst_user_class":
> 
> <cite>
> If using a plain model class which has username and password fields is 
> not working for you, because you have more complex objects, or you need 
> to do something else odd to fetch those values or your role fields, you 
> can subclass Catalyst::Plugin::Authentication::Store::DBIC::User, and 
> supply your class name here.
> </cite>
> 
> Is that the way I have to go? If so an example would be helpful, because 

> documentation for C:P::Authentication::Store::DBIC::User is a little 
> sparse. ;-)


What you need to do is subclass C::P::A::Credential, and override the 
login() method.

The login method is where the username and password are checked, so 
you probably want to  do something like the following (probably borrowing
the password check form C::P::Authentication::CDBI):

sub login {
  my ( $c, $user, $password, @rest ) = @_;

  unless ($user) {
     $c->log->error("Can't login a user without a user object or user 
ID");
     return;
  }

  unless ( Scalar::Util::blessed($user) and 
 $user->isa("Catalyst::Plugin::Authentication::User") ) {
    if ( my $user_obj = $c->get_user( $user ) ) {
      $user = $user_obj;
    } else {
      $c->log->error("User '$user' doesn't exist in the default store");
      return;
    }
  }

  # check the password...
  unless (some_password_check && $user->status eq 'Acitve') {
    # some error message:  "I'm sorry Dave, I can't do that."
  }

 
  $c->set_authenticated($user);
  $c->log->debug("Successfully authenticated user " . $user->id) if 
$c->debug;
  return 1;
}


Len.


-----------------------------------------
This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law.  If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED.  Although this transmission and
any attachments are believed to be free of any virus or other
defect that might affect any computer system into which it is
received and opened, it is the responsibility of the recipient to
ensure that it is virus free and no responsibility is accepted by
JPMorgan Chase & Co., its subsidiaries and affiliates, as
applicable, for any loss or damage arising in any way from its use.
If you received this transmission in error, please immediately
contact the sender and destroy the material in its entirety,
whether in electronic or hard copy format. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20061004/e1fe3f5d/attachment.htm 


More information about the Catalyst mailing list