NAME
App::ZofCMS::Plugin::UserLogin::ChangePassword - UserLogin plugin suppliment for changing user passwords
SYNOPSIS
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'>
DESCRIPTION
The module is a plugin for App::ZofCMS that provides means to display and process the "change password" form. This plugin was designed with an assumption that you are using App::ZofCMS::Plugin::UserLogin, but that's not a requirement.
This documentation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template
FIRST-LEVEL ZofCMS TEMPLATE AND MAIN CONFIG FILE KEYS
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 App::ZofCMS::Plugin::UserLogin 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 App::ZofCMS::Config 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 App::ZofCMS::Plugin::UserLogin 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 App::ZofCMS::Plugin::UserLogin'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 App::ZofCMS::Plugin::UserLogin. 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 App::ZofCMS::Config 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">
PLUGIN'S HTML AND OUTPUT
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>
SEE ALSO
DBI, App::ZofCMS::Plugin::UserLogin
REPOSITORY
Fork this module on GitHub: https://github.com/zoffixznet/App-ZofCMS
BUGS
To report bugs or request features, please use https://github.com/zoffixznet/App-ZofCMS/issues
If you can't access GitHub, you can email your request to bug-App-ZofCMS at rt.cpan.org
AUTHOR
Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)
LICENSE
You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.