On 13/09/2007, <b class="gmail_sendername">Ian Docherty</b> <<a href="mailto:catalyst@iandocherty.com">catalyst@iandocherty.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have found a thread on DBIx-class mailing list that throws some light<br>on this using<br><br><a href="http://search.cpan.org/~ash/DBIx-Class-0.08006/lib/DBIx/Class/Schema.pm#load_namespaces">http://search.cpan.org/~ash/DBIx-Class-0.08006/lib/DBIx/Class/Schema.pm#load_namespaces
</a><br><br>This seems to solve the problem for putting such logic into the<br>Model/Schema but would it be better to put this type of logic into a<br>business logic layer? In which case how would I obtain a $schema object?
<br>Would I have to then pass this as a parameter to the method?<br><br>Regards<br>Ian<br><br><br>Ian Docherty wrote:<br>> Hi<br>><br>> My existing Catalyst application is being extended. I want to keep a<br>> record of previous passwords used by a user to prevent them being
<br>> re-used.<br>><br>> I have Model 'UsedPassword' to keep track of the previous 8 (say)<br>> passwords as so-<br>><br>> package MyApp::Schema::UsedPassword;<br>> use strict;<br>> use base qw(DBIx::Class);
<br>><br>> __PACKAGE__->load_components(qw(PK::Auto Core));<br>> __PACKAGE__->table('used_password');<br>> __PACKAGE__->add_columns(qw(id user password));<br>> __PACKAGE__->set_primary_key('id');
<br>><br>> So, if I want a method (create_limited) to create a new UsedPassword<br>> object, that ensures no more that 8 (say) passwords are stored in the<br>> database (against each User) where should it go?<br>
><br>> Ideally (I think) I would like to do something like<br>><br>> $c->model('DBIC::UsedPassword')->create_limited({<br>> user => $user->id,<br>> password => $password,
<br>> });<br>><br>> but i can't see how to add it to MyApp::Schema::UsedPassword (since<br>> $c->model('DBIC::UsedPassword') returns a ResultSet not a<br>> MyApp::Schema::UsedPassword)<br>>
<br>> Any other suggestions where to put it (polite one's only please)?<br>><br>> Regards<br>> Ian</blockquote><div><br>Isn't this just a case of adding a create_limited() method to your model class?<br>
<br>package MyApp::Schema::UsedPassword;<br>...<br>sub create_limited {<br> my( $self, $user, $password ) = @_;<br> # password checking logic here<br>}<br><br>In your controller:<br><br>$c->model('DBIC::UsedPassword')->create_limited( ... );
<br></div></div>