X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=opac%2Fopac-passwd.pl;h=f7f384616c930d3c453c8c7f10916adc2947b3c0;hb=fc1342f73df868410e0ab670981f25ba2e1acd74;hp=bf139236d7effa797131d8000b93b20d6aa28b8d;hpb=a3999812e691110f2e16fffd91ce0ed82d69178c;p=koha.git diff --git a/opac/opac-passwd.pl b/opac/opac-passwd.pl index bf139236d7..f7f384616c 100755 --- a/opac/opac-passwd.pl +++ b/opac/opac-passwd.pl @@ -22,71 +22,83 @@ use strict; require Exporter; use CGI; -use C4::Auth; # checkauth, getborrowernumber. +use C4::Auth; # checkauth, getborrowernumber. use C4::Context; use Digest::MD5 qw(md5_base64); use C4::Circulation::Circ2; -use HTML::Template; + use C4::Interface::CGI::Output; my $query = new CGI; -my $dbh = C4::Context->dbh; +my $dbh = C4::Context->dbh; -my ($template, $borrowernumber, $cookie) - = get_template_and_user({template_name => "opac-passwd.tmpl", - query => $query, - type => "opac", - authnotrequired => 0, - flagsrequired => {borrow => 1}, - debug => 1, - }); +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => "opac-passwd.tmpl", + query => $query, + type => "opac", + authnotrequired => 0, + flagsrequired => { borrow => 1 }, + debug => 1, + } +); # get borrower information .... -my ($borr, $flags) = getpatroninformation(undef, $borrowernumber); -my $sth = $dbh->prepare("UPDATE borrowers SET password = ? WHERE borrowernumber=?"); +my ( $borr, $flags ) = getpatroninformation( undef, $borrowernumber ); +my $sth = + $dbh->prepare("UPDATE borrowers SET password = ? WHERE borrowernumber=?"); -if ( $query->param('Oldkey') && $query->param('Newkey') && $query->param('Confirm') ){ - if ( goodkey($dbh,$borrowernumber, $query->param('Oldkey')) ){ - if ( $query->param('Newkey') eq $query->param('Confirm') && - length($query->param('Confirm')) > 5 ){ # Record password - my $clave = md5_base64($query->param('Newkey')); - $sth->execute($clave,$borrowernumber); - $template->param('password_updated' => '1'); - $template->param('borrowernumber' => $borrowernumber); - }elsif ( $query->param('Newkey') ne $query->param('Confirm') ){ - $template->param('Ask_data' => '1'); - $template->param('Error_messages' => '1'); - $template->param('PassMismatch' => '1'); - }elsif (length($query->param('Confirm')) <= 5 ){ - $template->param('Ask_data' => '1'); - $template->param('Error_messages' => '1'); - $template->param('ShortPass' => '1'); - }else{ - $template->param('Error_messages' => '1'); - } - }else{ - $template->param('Ask_data' => '1'); - $template->param('Error_messages' => '1'); - $template->param('WrongPass' => '1'); - } -}else { -# Called Empty, Ask for data. - $template->param('Ask_data' => '1'); +if ( $query->param('Oldkey') + && $query->param('Newkey') + && $query->param('Confirm') ) +{ + if ( goodkey( $dbh, $borrowernumber, $query->param('Oldkey') ) ) { + if ( $query->param('Newkey') eq $query->param('Confirm') + && length( $query->param('Confirm') ) > 5 ) + { # Record password + my $clave = md5_base64( $query->param('Newkey') ); + $sth->execute( $clave, $borrowernumber ); + $template->param( 'password_updated' => '1' ); + $template->param( 'borrowernumber' => $borrowernumber ); + } + elsif ( $query->param('Newkey') ne $query->param('Confirm') ) { + $template->param( 'Ask_data' => '1' ); + $template->param( 'Error_messages' => '1' ); + $template->param( 'PassMismatch' => '1' ); + } + elsif ( length( $query->param('Confirm') ) <= 5 ) { + $template->param( 'Ask_data' => '1' ); + $template->param( 'Error_messages' => '1' ); + $template->param( 'ShortPass' => '1' ); + } + else { + $template->param( 'Error_messages' => '1' ); + } + } + else { + $template->param( 'Ask_data' => '1' ); + $template->param( 'Error_messages' => '1' ); + $template->param( 'WrongPass' => '1' ); + } } +else { -$template->param(LibraryName => C4::Context->preference("LibraryName"), -); + # Called Empty, Ask for data. + $template->param( 'Ask_data' => '1' ); +} output_html_with_http_headers $query, $cookie, $template->output; - sub goodkey { -my ($dbh, $borrowernumber, $key) = @_; + my ( $dbh, $borrowernumber, $key ) = @_; - my $sth=$dbh->prepare("SELECT password FROM borrowers WHERE borrowernumber=?"); - $sth->execute($borrowernumber); - if ($sth->rows){ - my ($md5password) = $sth->fetchrow; - if (md5_base64($key) eq $md5password) { return 1; } else { return 0; } - }else{ return 0; } + my $sth = + $dbh->prepare("SELECT password FROM borrowers WHERE borrowernumber=?"); + $sth->execute($borrowernumber); + if ( $sth->rows ) { + my ($md5password) = $sth->fetchrow; + if ( md5_base64($key) eq $md5password ) { return 1; } + else { return 0; } + } + else { return 0; } }