[Catalyst] Extending C::Plugin::Authentication::Store::DBIC for
additional constraints
Fernan Aguero
fernan at iib.unsam.edu.ar
Mon Mar 26 06:11:23 GMT 2007
+----[ Doran L. Barton <fozz at iodynamics.com> (26.Mar.2007 01:39):
|
| I'd like some advice on how to do this. I'm developing a single Cat app
| that will handle multiple sites by looking at the 'host' header. All
| sites will be associated with domain names under a specific domain. Think
| wildcard A records in DNS, if you will. For example, all of the following
| would be caught and handled by the app:
|
| foo.mycatalystsite.com
| bar.mycatalystsite.com
| foobar.mycatalystsite.com
|
| I want each site to have its own pool of users for authentication. The
| users table, therefore, has a site_id associated with each user.
|
| Herein lies the gotcha! I need to be able to tell the Authentication plugin
| to authenticate the user using $username, $password, and a site_id (as
| opposed to the usual $username and $password). After looking through the
| Catalyst::Plugin::Authentication::Store::DBIC code, I can't immediately see
| how I could subclass it and add this functionality.
|
| Thoughts, anyone?
|
+----]
Certainly not what you were asking (subclassing
store::dbic), but ...
sub login : Local {
my ( $self, $c ) = @_;
my $username = $c->req->params->{username} || "";
my $password = $c->req->params->{password} || "";
my $model = $c->model('Users');
if ( $username && $password ) {
# attempt to login
if ( $c->login( $username, $password ) ) {
# now we check site_id
$ok = $model->search(
{ username => $username,
password => $password,
site_id => $site_id } )->count();
$c->logout unless $ok > 0;
}
} else { ...
More information about the Catalyst
mailing list