| App::ZofCMS::Plugin::UserLogin::ChangePassword - UserLogin plugin suppliment for changing user passwords |
App::ZofCMS::Plugin::UserLogin::ChangePassword - UserLogin plugin suppliment for changing user passwords
In your Main Config File or ZofCMS Template:
plugins => [
{ UserLogin => 200 },
{ 'UserLogin::ChangePassword' => 1000 },
],
plug_user_login_change_password => {
dsn => "DBI:mysql:database=hl;host=localhost",
login => 'test',
pass => 'test',
},
# UserLogin plugin's configuration skipped for brevity
In your HTML::Template template:
<tmpl_var name='change_pass_form'>
The module is a plugin for the App::ZofCMS manpage that provides means to display and process the "change password" form. This plugin was designed with an assumption that you are using the App::ZofCMS::Plugin::UserLogin manpage, but that's not a requirement.
This documentation assumes you've read the App::ZofCMS manpage, the App::ZofCMS::Config manpage and the App::ZofCMS::Template manpage
plugins
plugins => [
{ 'UserLogin::ChangePassword' => 2000 },
],
Mandatory. You need to include the plugin in the list of plugins to execute. By default this plugin is configured to interface with the App::ZofCMS::UserLogin manpage plugin, thus you'd include UserLogin plugin with lower priority sequence to execute earlier.
plug_user_login_change_password
plug_user_login_change_password => {
dsn => "DBI:mysql:database=test;host=localhost",
user => 'test',
pass => 'test',
opt => { RaiseError => 1, AutoCommit => 1 },
table => 'users',
login => sub { $_[0]{d}{user}{login} },
key => 'change_pass_form',
min => 4,
submit_button => q|<input type="submit" class="input_submit"|
. q| name="plug_user_login_change_password_submit"|
. q| value="Change password">|,
},
# or set arguments via a subref
plug_user_login_change_password => sub {
my ( $t, $q, $config ) = @_;
return {
dsn => "DBI:mysql:database=test;host=localhost",
},
},
Mandatory. Takes either a hashref or a subref as a value. If subref is specified,
its return value will be assigned to plug_user_login_change_password as if it was already
there. If sub returns
an undef, then plugin will stop further processing. The @_ of the subref will
contain (in that order): ZofCMS Tempalate hashref, query parameters hashref and
the App::ZofCMS::Config manpage object. To run with all the defaults (which won't be the case for
nearly everything but testing environment) set to empty hashref.
Possible keys/values for the hashref are as follows:
dsn
plug_user_login_change_password => sub {
dsn => "DBI:mysql:database=test;host=localhost",
},
Optional. Specifies DBI's "dsn" (driver, database and host) for the plugin to use.
See the App::ZofCMS::UserLogin manpage for more details; this one needs to point to the
same database that UserLogin plugin uses so the right password could be changed.
Defaults to: DBI:mysql:database=test;host=localhost (as I've said, useful only for
testing enviroment)
user
plug_user_login_change_password => sub {
user => 'test',
},
Optional. Specifies the username for database access. Defaults to: test
pass
plug_user_login_change_password => sub {
pass => 'test',
},
Optional. Specifies the password for database access. Defaults to: test
opt
plug_user_login_change_password => sub {
opt => { RaiseError => 1, AutoCommit => 1 },
},
Optional. Specifies additional DBI options. See the App::ZofCMS::Plugin::UserLogin manpage's
opt argument for more details. Defaults to: { RaiseError => 1, AutoCommit => 1 }
table
plug_user_login_change_password => sub {
table => 'users',
},
Optional. Specifies the SQL table used in the App::ZofCMS::Plugin::UserLogin manpage. Actually,
you do not have to use UserLogin plugin, but the passwords must be stored in a column
named password. Defaults to: users
login
plug_user_login_change_password => sub {
login => 'admin',
},
plug_user_login_change_password => sub {
login => sub { $_[0]{d}{user}{login} },
},
Optional. Specifies the login of the user whose password to chagne.
Takes either a string or a subref as a value. If subref is specified, its
return value will be assigned to login as if it was already there.
The @_ of the subref will contain (in that order): ZofCMS Template hashref, query
parameters hashref and the App::ZofCMS::Config manpage object.
Defaults to: sub { $_[0]{d}{user}{login} } (my common way of storing $user_ref from
UserLogin plugin)
key
plug_user_login_change_password => sub {
key => 'change_pass_form',
},
Optional. Specifies the name of the key inside {t} special key into which
the plugin will put the password change form (see PLUGIN'S HTML AND OUTPUT section for
details).
Defaults to: change_pass_form
min
plug_user_login_change_password => sub {
min => 4,
},
Optional. Takes a positive intereger or zero as a value. Specifies
the minimum length() of the new password. Defaults to: 4
submit_button
plug_user_login_change_password => sub {
submit_button => q|<input type="submit" class="input_submit"|
. q| name="plug_user_login_change_password_submit"|
. q| value="Change password">|,
},
Optional. Takes a string of HTML code as a value. Specifies the
code for the submit button of the form; feel free to add any extra
code you might require as well. Defaults to:
<input type="submit" class="input_submit" name="plug_user_login_change_password_submit" value="Change password">
The plugin uses key in {t} special key that is specified via key plugin's configuration
argument (defaults to change_pass_form). That key will contain either the HTML
form for password changing or the message that password was successfully changed.
If an error occured (such as mismatching passwords), plugin will set
$t->{t}{plug_user_login_change_password_error} to a true value (where $t is
ZofCMS Template hashref). If password was successfully changed, plugin will set
$t->{t}{plug_user_login_change_password_ok} to a true value (where $t is
ZofCMS Template hashref). You do not have to use these, as they are set only if you have
a large page and want to hide/show different bits depending on what is going on.
Below is the HTML::Template template that plugin uses for the form as well as successfully password changes. It is shown here for you to know how to style your password changing form/success message properly:
<tmpl_if name='change_ok'>
<p id="plug_user_login_change_password_ok" class="success-message">Your password has been successfully changed</p>
<tmpl_else>
<form action="" method="POST" id="plug_user_login_change_password_form">
<div>
<tmpl_if name='error'>
<p class="error"><tmpl_var escape='html' name='error'></p>
</tmpl_if>
<input type="hidden" name="page" value="<tmpl_var escape='html' name='page'>">
<input type="hidden" name="dir" value="<tmpl_var escape='html' name='dir'>">
<ul>
<li>
<label for="plug_user_login_change_password_pass">Current password: </label
><input type="password" class="input_password" name="plug_user_login_change_password_pass" id="plug_user_login_change_password_pass">
</li>
<li>
<label for="plug_user_login_change_password_newpass">New password: </label
><input type="password" class="input_password" name="plug_user_login_change_password_newpass" id="plug_user_login_change_password_newpass">
</li>
<li>
<label for="plug_user_login_change_password_repass">Retype new password: </label
><input type="password" class="input_password" name="plug_user_login_change_password_repass" id="plug_user_login_change_password_repass">
</li>
</ul>
<input type="submit" class="input_submit" name="plug_user_login_change_password_submit" value="Change password">
</div>
</form>
</tmpl_if>
DBI, the App::ZofCMS::Plugin::UserLogin manpage
'Zoffix, <'zoffix at cpan.org'>
(http://haslayout.net/, http://zoffix.com/, http://zofdesign.com/)
Please report any bugs or feature requests to bug-app-zofcms-plugin-userlogin-changepassword at rt.cpan.org, or through
the web interface at http://rt.cpan.org/NoAuth/ReportBug.html. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc App::ZofCMS::Plugin::UserLogin::ChangePassword
You can also look for information at:
http://annocpan.org/dist/App-ZofCMS-Plugin-UserLogin-ChangePassword
http://cpanratings.perl.org/d/App-ZofCMS-Plugin-UserLogin-ChangePassword
http://search.cpan.org/dist/App-ZofCMS-Plugin-UserLogin-ChangePassword/
Copyright 2009 'Zoffix, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| App::ZofCMS::Plugin::UserLogin::ChangePassword - UserLogin plugin suppliment for changing user passwords |