jifty::plugin::authentication::password::mixin::model::user(3pm) [debian man page]
Jifty::Plugin::Authentication::Password::Mixin::Model::UUser3Contributed Perl DocuJifty::Plugin::Authentication::Password::Mixin::Model::User(3pm)NAME
Jifty::Plugin::Authentication::Password::Mixin::Model::User - password plugin user mixin model
SYNOPSIS
package MyApp::Model::User;
use Jifty::DBI::Schema;
use MyApp::Record schema {
# custom column definitions
};
use Jifty::Plugin::User::Mixin::Model::User; # name, email, email_confirmed
use Jifty::Plugin::Authentication::Password::Mixin::Model::User;
# ^^ password, auth_token
DESCRIPTION
This mixin model is added to the application's account model for use with the password authentication plugin. This mixin should be used in
combination with Jifty::Plugin::User::Mixin::Model::User.
SCHEMA
This mixin adds the following columns to the model schema:
auth_token
This is a unique identifier used when confirming a user's email account and recovering a lost password.
password
This is the user's password. It will be stored in the database after being processed through Digest::MD5, so the password cannot be
directly recovered from the database.
METHODS
register_triggers
Adds the triggers to the model this mixin is added to.
password_is PASSWORD
Checks if the user's password matches the provided PASSWORD.
hashed_password_is HASH TOKEN
Check if the given HASH is the result of hashing our (already salted and hashed) password with TOKEN.
This can be used in cases where the pre-hashed password is sent during login as an additional security precaution (such as could be done
via Javascript).
validate_password
Makes sure that the password is six characters long or longer, unless we have alternative means to authenticate.
after_create
This trigger is added to the account model. It automatically sends a notification email to the user for password confirmation.
See Jifty::Plugin::Authentication::Password::Notification::ConfirmEmail.
has_alternative_auth
If your model supports other means of authentication, you should have this method return true, so the "password" field can optionally be
null and authentication with password is disabled in that case.
after_set_password
Regenerate authentication tokens on password change
regenerate_auth_token
Generate a new auth_token for this user. This will invalidate any existing feed URLs.
SEE ALSO
Jifty::Plugin::Authentication::Password, Jifty::Plugin::User::Mixin::Model
LICENSE
Jifty is Copyright 2005-2010 Best Practical Solutions, LLC. Jifty is distributed under the same terms as Perl itself.
perl v5.14.2 2010-12-10 Jifty::Plugin::Authentication::Password::Mixin::Model::User(3pm)
Check Out this Related Man Page
Jifty::DBI::Record::Plugin(3pm) User Contributed Perl Documentation Jifty::DBI::Record::Plugin(3pm)NAME
Jifty::DBI::Record::Plugin - Record model mixins for Jifty::DBI
SYNOPSIS
# Define a mixin
package MyApp::FavoriteColor;
use base qw/ Jifty::DBI::Record::Plugin /;
# Define which methods you want to put in the host model
our @EXPORT = qw(
favorite_complementary_color
);
use Jifty::DBI::Schema;
use Jifty::DBI::Record schema {
column favorite_color =>
type is 'text',
label is 'Favorite Color',
valid_values are qw/ red green blue yellow /;
};
sub favorite_complementary_color {
my $self = shift; # whatever host object thing we've mixed with
my $color = $self->favorite_color;
return $color eq 'red' ? 'green'
: $color eq 'green' ? 'red'
: $color eq 'blue' ? 'orange'
: $color eq 'yellow' ? 'purple'
: undef;
}
# Use the mixin
package MyApp::Model::User;
use Jifty::DBI::Schema;
use Jifty::DBI::Record schema {
column name =>
type is 'text',
label is 'Name';
};
# Mixins
use MyApp::FavoriteColor;
sub name_and_color {
my $self = shift;
my $name = $self->name;
my $color = $self->favorite_color;
return "The favorite color of $name is $color.";
}
sub name_and_complementary_color {
my $self = shift;
my $name = $self->name;
my $color = $self->favorite_complementary_color;
return "The complement of $name's favorite color is $color.";
}
DESCRIPTION
By using this package you may provide models that are built from one or more mixins. In fact, your whole table could be defined in the
mixins without a single column declared within the model class itself.
MODEL MIXINS
To build a mixin, just create a model that inherits from this package, "Jifty::DBI::Record::Plugin". Then, add the schema definitions you
want inherited.
package MyApp::FasterSwallow;
use base qw/ Jifty::DBI::Record::Plugin /;
use Jifty::DBI::Schema;
use Jifty::DBI::Record schema {
column swallow_type =>
type is 'text',
valid are qw/ african european /,
default is 'african';
};
@EXPORT
A mixin may define an @EXPORT variable, which works exactly as advertised in Exporter. That is, given the name of any methods or variable
names in the mixin, the host model will gain those methods.
our @EXPORT = qw( autocomplete_swallow_type );
sub autocomplete_swallow_type {
my $self = shift;
my $value = quotemeta(shift);
# You should probably find a better way than actually doing this...
my @values;
push @values, 'african' if 'african' =~ /$value/;
push @values, 'european' if 'european' =~ /$value/;
return @values;
}
That way if you have any custom methods you want to throw into the host model, just define them in the mixin and add them to the @EXPORT
variable.
register_triggers
Your mixin may also want to register triggers for the records to which it will be added. You can do this by defining a method named
"register_triggers":
sub register_triggers {
my $self = shift;
$self->add_trigger(
name => 'before_create',
callback => &before_create,
abortable => 1,
);
}
sub before_create {
# do something...
}
See Class::Trigger.
register_triggers_for_column
In addition to the general "register_triggers" method described above, the mixin may also implement a "register_triggers_for_column"
method. This is called for each column in the table. This is primarily helpful for registering the "after_set_*" and "before_set_*"
columns.
For example:
sub register_triggers_for_column {
my $self = shift;
my $column = shift;
return unless $column ne 'updated_on';
$self->add_trigger(
name => 'after_set_'.$column,
callback => &touch_update_time,
abortable => 1,
);
}
sub touch_update_time {
my $self = shift;
$self->set_updated_on(DateTime->now);
}
This has the additional advantage of being callable when new columns are added to a table while the application is running. This can happen
when using database-backed models in Jifty (which, as of this writing, has not been released or made part of the development trunk of
Jifty, but is part of the virtual-models branch).
See Class::Trigger.
MODELS USING MIXINS
To use your model plugin, just use the mixins you want to get columns from. You should still include a schema definition, even if it's
empty:
package MyApp::Model::User;
use Jifty::DBI::Schema;
use MyApp::Record schema {
};
# Mixins
use MyApp::FavoriteColor;
use MyApp::FasterSwallow;
use Jifty::Plugin::User::Mixin::Model::User;
use Jifty::Plugin::Authentication::Password::Mixin::Model::User;
SEE ALSO
Jifty::DBI::Record, Class::Trigger
LICENSE
Jifty::DBI is Copyright 2005-2007 Best Practical Solutions, LLC. Jifty is distributed under the same terms as Perl itself.
perl v5.14.2 2010-09-21 Jifty::DBI::Record::Plugin(3pm)