Bug 18936: (follow-up) Adjust circ rule related tests so that they pass
[koha.git] / opac / opac-passwd.pl
blobbff0214a9f227a09f2ec4655922b2e0ff75db86f
1 #!/usr/bin/perl
2 # This script lets the users change the passwords by themselves.
4 # (c) 2005 Universidad ORT Uruguay.
6 # This file is part of the extensions and enhacments made to koha by Universidad ORT Uruguay
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Modern::Perl;
23 use CGI qw ( -utf8 );
25 use C4::Auth; # checkauth, getborrowernumber.
26 use C4::Context;
27 use C4::Circulation;
28 use C4::Members;
29 use C4::Output;
30 use Koha::Patrons;
32 use Try::Tiny;
34 my $query = new CGI;
36 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
38 template_name => "opac-passwd.tt",
39 query => $query,
40 type => "opac",
41 authnotrequired => 0,
42 debug => 1,
46 my $patron = Koha::Patrons->find( $borrowernumber );
47 if ( $patron->category->effective_change_password ) {
48 if ( $query->param('Oldkey')
49 && $query->param('Newkey')
50 && $query->param('Confirm') )
52 my $error;
53 my $new_password = $query->param('Newkey');
54 my $confirm_password = $query->param('Confirm');
55 if ( C4::Auth::checkpw_hash( scalar $query->param('Oldkey'), $patron->password ) ) {
57 if ( $new_password ne $confirm_password ) {
58 $template->param( 'Ask_data' => '1' );
59 $template->param( 'Error_messages' => '1' );
60 $template->param( 'passwords_mismatch' => '1' );
61 } else {
62 try {
63 $patron->set_password({ password => $new_password });
64 $template->param( 'password_updated' => '1' );
65 $template->param( 'borrowernumber' => $borrowernumber );
67 catch {
68 $error = 'password_too_short'
69 if $_->isa('Koha::Exceptions::Password::TooShort');
70 $error = 'password_too_weak'
71 if $_->isa('Koha::Exceptions::Password::TooWeak');
72 $error = 'password_has_whitespaces'
73 if $_->isa('Koha::Exceptions::Password::WhitespaceCharacters');
77 else {
78 $error = 'WrongPass';
80 if ($error) {
81 $template->param(
82 Ask_data => 1,
83 Error_messages => 1,
84 $error => 1,
89 else {
91 # Called Empty, Ask for data.
92 $template->param( 'Ask_data' => '1' );
93 if (!$query->param('Oldkey') && ($query->param('Newkey') || $query->param('Confirm'))){
94 # Old password is empty but one of the others isn't
95 $template->param( 'Error_messages' => '1' );
96 $template->param( 'WrongPass' => '1' );
98 elsif ($query->param('Oldkey') && (!$query->param('Newkey') || !$query->param('Confirm'))){
99 # Oldpassword is entered but one of the other fields is empty
100 $template->param( 'Error_messages' => '1' );
101 $template->param( 'PassMismatch' => '1' );
105 $template->param(
106 firstname => $patron->firstname,
107 surname => $patron->surname,
108 passwdview => 1,
112 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };