But actually we could remove it if it does not make sense for other use.
Callers could deal with it since the password is not generated here
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
&changepassword
);
- #Insert data
- push @EXPORT, qw(
- &AddMember_Opac
- );
-
#Check data
push @EXPORT, qw(
&checkuserpassword
);
}
-=head2 AddMember_Opac
-
-=cut
-
-sub AddMember_Opac {
- my ( %borrower ) = @_;
-
- $borrower{'categorycode'} //= C4::Context->preference('PatronSelfRegistrationDefaultCategory');
- my $password = $borrower{password};
- if (not defined $password){
- my $sr = new String::Random;
- $sr->{'A'} = [ 'A'..'Z', 'a'..'z' ];
- $password = $sr->randpattern("AAAAAAAAAA");
- $borrower{'password'} = $password;
- }
-
- my $patron = Koha::Patron->new(\%borrower)->store;
-
- return ( $patron->borrowernumber, $password );
-}
-
=head2 DeleteExpiredOpacRegistrations
Delete accounts that haven't been upgraded from the 'temporary' category
return $self;
}
+sub plain_text_password {
+ my ( $self, $password ) = @_;
+ if ( $password ) {
+ $self->{_plain_text_password} = $password;
+ return $self;
+ }
+ return $self->{_plain_text_password}
+ if $self->{_plain_text_password};
+
+ return;
+}
+
sub store {
my ($self) = @_;
}
# Make a copy of the plain text password for later use
- my $plain_text_password = $self->password;
+ $self->plain_text_password( $self->password );
# Create a disabled account if no password provided
$self->password( $self->password
'sync' => 1,
'syncstatus' => 'new',
'hashed_pin' =>
- Koha::NorwegianPatronDB::NLEncryptPIN(
- $plain_text_password),
+ Koha::NorwegianPatronDB::NLEncryptPIN($self->plain_text_password),
}
);
}
$verification_token = md5_hex( time().{}.rand().{}.$$ );
}
- $borrower{password} = Koha::AuthUtils::generate_password unless $borrower{password};
+ $borrower{password} = Koha::AuthUtils::generate_password unless $borrower{password};
$borrower{verification_token} = $verification_token;
Koha::Patron::Modification->new( \%borrower )->store();
$template->param( OpacPasswordChange =>
C4::Context->preference('OpacPasswordChange') );
+ $borrower{categorycode} ||= C4::Context->preference('PatronSelfRegistrationDefaultCategory');
+ $borrower{password} ||= Koha::AuthUtils::generate_password;
my $patron = Koha::Patron->new( \%borrower )->store;
if ( $patron ) {
C4::Members::Attributes::SetBorrowerAttributes( $patron->borrowernumber, $attributes );
);
}
- $template->param( password_cleartext => $password );
+ $template->param( password_cleartext => $patron->plain_text_password );
$template->param( borrower => $patron->unblessed );
} else {
# FIXME Handle possible errors here
use C4::Output;
use C4::Members;
use C4::Form::MessagingPreferences;
+use Koha::AuthUtils;
use Koha::Patrons;
use Koha::Patron::Modifications;
$template->param(
OpacPasswordChange => C4::Context->preference('OpacPasswordChange') );
- my $borrower = $m->unblessed();
+ my $patron_attrs = $m->unblessed;
+ $patron_attrs->{password} ||= Koha::AuthUtils::generate_password;
- my $password;
- ( $borrowernumber, $password ) = AddMember_Opac(%$borrower);
+ $patron_attrs->{categorycode} ||= C4::Context->preference('PatronSelfRegistrationDefaultCategory');
+ my $patron = Koha::Patron->new( $patron_attrs )->store;
- if ($borrowernumber) {
+ if ($patron) {
$m->delete();
- C4::Form::MessagingPreferences::handle_form_action($cgi, { borrowernumber => $borrowernumber }, $template, 1, C4::Context->preference('PatronSelfRegistrationDefaultCategory') ) if C4::Context->preference('EnhancedMessagingPreferences');
+ C4::Form::MessagingPreferences::handle_form_action($cgi, { borrowernumber => $patron->borrowernumber }, $template, 1, C4::Context->preference('PatronSelfRegistrationDefaultCategory') ) if C4::Context->preference('EnhancedMessagingPreferences');
- $template->param( password_cleartext => $password );
- my $patron = Koha::Patrons->find( $borrowernumber );
+ $template->param( password_cleartext => $patron->plain_text_password );
$template->param( borrower => $patron->unblessed );
$template->param(
PatronSelfRegistrationAdditionalInstructions =>
use Modern::Perl;
-use Test::More tests => 50;
+use Test::More tests => 47;
use Test::MockModule;
use Test::Exception;
return $found;
}
-# Regression tests for BZ15343
-my $password="";
-( $borrowernumber, $password ) = AddMember_Opac(surname=>"Dick",firstname=>'Philip',branchcode => $library2->{branchcode});
-is( $password =~ /^[a-zA-Z]{10}$/ , 1, 'Test for autogenerated password if none submitted');
-( $borrowernumber, $password ) = AddMember_Opac(surname=>"Deckard",firstname=>"Rick",password=>"Nexus-6",branchcode => $library2->{branchcode});
-is( $password eq "Nexus-6", 1, 'Test password used if submitted');
-$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
-my $hashed_up = Koha::AuthUtils::hash_password("Nexus-6", $borrower->{password});
-is( $borrower->{password} eq $hashed_up, 1, 'Check password hash equals hash of submitted password' );
-
$schema->storage->txn_rollback;
subtest 'Koha::Patron->store (invalid categorycode) tests' => sub {