FAQ

On 13/09/2007, Ian Docherty wrote:
I have found a thread on DBIx-class mailing list that throws some light
on this using


http://search.cpan.org/~ash/DBIx-Class-0.08006/lib/DBIx/Class/Schema.pm#load_namespaces

This seems to solve the problem for putting such logic into the
Model/Schema but would it be better to put this type of logic into a
business logic layer? In which case how would I obtain a $schema object?
Would I have to then pass this as a parameter to the method?

Regards
Ian


Ian Docherty wrote:
Hi

My existing Catalyst application is being extended. I want to keep a
record of previous passwords used by a user to prevent them being
re-used.

I have Model 'UsedPassword' to keep track of the previous 8 (say)
passwords as so-

package MyApp::Schema::UsedPassword;
use strict;
use base qw(DBIx::Class);

__PACKAGE__->load_components(qw(PK::Auto Core));
__PACKAGE__->table('used_password');
__PACKAGE__->add_columns(qw(id user password));
__PACKAGE__->set_primary_key('id');

So, if I want a method (create_limited) to create a new UsedPassword
object, that ensures no more that 8 (say) passwords are stored in the
database (against each User) where should it go?

Ideally (I think) I would like to do something like

$c->model('DBIC::UsedPassword')->create_limited({
user => $user->id,
password => $password,
});

but i can't see how to add it to MyApp::Schema::UsedPassword (since
$c->model('DBIC::UsedPassword') returns a ResultSet not a
MyApp::Schema::UsedPassword)

Any other suggestions where to put it (polite one's only please)?

Regards
Ian

Isn't this just a case of adding a create_limited() method to your model
class?

package MyApp::Schema::UsedPassword;
...
sub create_limited {
my( $self, $user, $password ) = @_;
# password checking logic here
}

In your controller:

$c->model('DBIC::UsedPassword')->create_limited( ... );
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070913/b07f8eeb/attachment.htm

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 17 | next ›
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedSep 13, '07 at 10:27a
activeSep 14, '07 at 1:35p
posts17
users6
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase