From 7345d59117d7db7351537606bd02b2cfcd9e0726 Mon Sep 17 00:00:00 2001 From: berick Date: Thu, 7 Apr 2011 15:10:24 -0400 Subject: [PATCH] Support for password update --- .../src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 1 + .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 47 +++++++++++++++ .../web/templates/default/opac/myopac/prefs.tt2 | 67 +--------------------- .../default/opac/myopac/update_password.tt2 | 33 +++++++++++ 4 files changed, 84 insertions(+), 64 deletions(-) create mode 100644 Open-ILS/web/templates/default/opac/myopac/update_password.tt2 diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index 9ba54a71ad..ad8ec8fd15 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -124,6 +124,7 @@ sub load { return $self->load_myopac_payments if $path =~ m|opac/myopac/main_payments|; return $self->load_myopac_main if $path =~ m|opac/myopac/main|; return $self->load_myopac_update_email if $path =~ m|opac/myopac/update_email|; + return $self->load_myopac_update_password if $path =~ m|opac/myopac/update_password|; return $self->load_myopac_update_username if $path =~ m|opac/myopac/update_username|; return $self->load_myopac_bookbags if $path =~ m|opac/myopac/lists|; return $self->load_myopac_bookbag_update if $path =~ m|opac/myopac/list/update|; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm index 3bde775fe7..9dee8b9959 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -652,6 +652,9 @@ sub load_myopac_update_email { my $ctx = $self->ctx; my $email = $self->cgi->param('email') || ''; + return Apache2::Const::OK + unless $self->cgi->request_method eq 'POST'; + unless($email =~ /.+\@.+\..+/) { # TODO better regex? $ctx->{invalid_email} = $email; return Apache2::Const::OK; @@ -674,6 +677,9 @@ sub load_myopac_update_username { my $ctx = $self->ctx; my $username = $self->cgi->param('username') || ''; + return Apache2::Const::OK + unless $self->cgi->request_method eq 'POST'; + unless($username and $username !~ /\s/) { # any other username restrictions? $ctx->{invalid_username} = $username; return Apache2::Const::OK; @@ -698,6 +704,47 @@ sub load_myopac_update_username { return $self->generic_redirect($url); } +sub load_myopac_update_password { + my $self = shift; + my $e = $self->editor; + my $ctx = $self->ctx; + + return Apache2::Const::OK + unless $self->cgi->request_method eq 'POST'; + + my $current_pw = $self->cgi->param('current_pw') || ''; + my $new_pw = $self->cgi->param('new_pw') || ''; + my $new_pw2 = $self->cgi->param('new_pw2') || ''; + + unless($new_pw eq $new_pw2) { + $ctx->{password_nomatch} = 1; + return Apache2::Const::OK; + } + + my $pw_regex = $ctx->{get_org_setting}->($e->requestor->home_ou, 'global.password_regex'); + + if($pw_regex and $new_pw !~ /$pw_regex/) { + $ctx->{password_invalid} = 1; + return Apache2::Const::OK; + } + + my $evt = $U->simplereq( + 'open-ils.actor', + 'open-ils.actor.user.password.update', + $e->authtoken, $new_pw, $current_pw); + + + if($U->event_equals($evt, 'INCORRECT_PASSWORD')) { + $ctx->{password_incorrect} = 1; + return Apache2::Const::OK; + } + + my $url = $self->apache->unparsed_uri; + $url =~ s/update_password/prefs/; + + return $self->generic_redirect($url); +} + sub load_myopac_bookbags { my $self = shift; my $e = $self->editor; diff --git a/Open-ILS/web/templates/default/opac/myopac/prefs.tt2 b/Open-ILS/web/templates/default/opac/myopac/prefs.tt2 index 37cce3dee4..8ceeec3c42 100644 --- a/Open-ILS/web/templates/default/opac/myopac/prefs.tt2 +++ b/Open-ILS/web/templates/default/opac/myopac/prefs.tt2 @@ -157,75 +157,14 @@ [% l("Username") %] - [% ctx.user.usrname | html %] [% l("Change") %] - - - [% l("Enter new username:") %] - - - - - - - [% l("Password") %] - - [% l("(not shown)") %] - [% l("Change") %] + [% l("Password") %] + [% l("(not shown)") %] + [% l("Change") %] - - - - - - - - - - - - - - - - - - - - - -
- - [% l("Enter current password:") %] - - - -
[% l("Enter new password:") %] -
[% l("Re-enter new password:") %] - -
- - - - [% l("Email Address") %] [% ctx.user.email | html %] diff --git a/Open-ILS/web/templates/default/opac/myopac/update_password.tt2 b/Open-ILS/web/templates/default/opac/myopac/update_password.tt2 new file mode 100644 index 0000000000..d248cdfcb7 --- /dev/null +++ b/Open-ILS/web/templates/default/opac/myopac/update_password.tt2 @@ -0,0 +1,33 @@ +[% PROCESS "default/opac/parts/header.tt2"; + PROCESS "default/opac/parts/misc_util.tt2"; + WRAPPER "default/opac/parts/myopac/base.tt2"; + myopac_page = "prefs" %] + +
+ +[% IF ctx.password_invalid %] +
+ [% |l %] New password is invalid. Please try a different password. [% END %] +
+ +[% ELSIF ctx.password_nomatch %] +
+ [% |l %] Passwords do not match. [% END %] +
+ +[% ELSIF ctx.password_incorrect %] +
+ [% |l %] Your current password was not correct. [% END %] +
+[% END %] + +
+ + + + + +
[% l('Current Password') %]
[% l('New Password') %]
[% l('New Password Again') %]
+
+ +[% END %] -- 2.11.0