+ $borrower{password} ||= Koha::AuthUtils::generate_password(Koha::Patron::Categories->find($borrower{categorycode}));
+ my $consent_dt = delete $borrower{gdpr_proc_consent};
+ my $patron = Koha::Patron->new( \%borrower )->store;
+ Koha::Patron::Consent->new({ borrowernumber => $patron->borrowernumber, type => 'GDPR_PROCESSING', given_on => $consent_dt })->store if $consent_dt;
+ if ( $patron ) {
+ $patron->extended_attributes->filter_by_branch_limitations->delete;
+ $patron->extended_attributes($attributes);
+ if ( C4::Context->preference('EnhancedMessagingPreferences') ) {
+ C4::Form::MessagingPreferences::handle_form_action(
+ $cgi,
+ { borrowernumber => $patron->borrowernumber },
+ $template,
+ 1,
+ C4::Context->preference('PatronSelfRegistrationDefaultCategory')
+ );
+ }
+
+ $template->param( password_cleartext => $patron->plain_text_password );
+ $template->param( borrower => $patron->unblessed );
+
+ # If 'AutoEmailNewUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
+ if ( C4::Context->preference("AutoEmailNewUser") ) {
+ #look for defined primary email address, if blank - attempt to use borr.email and borr.emailpro instead
+ my $emailaddr = $patron->notice_email_address;
+ # if we manage to find a valid email address, send notice
+ if ($emailaddr) {
+ eval {
+ my $letter = GetPreparedLetter(
+ module => 'members',
+ letter_code => 'WELCOME',
+ branchcode => $patron->branchcode,,
+ lang => $patron->lang || 'default',
+ tables => {
+ 'branches' => $patron->branchcode,
+ 'borrowers' => $patron->borrowernumber,
+ },
+ want_librarian => 1,
+ ) or return;
+
+ my $message_id = EnqueueLetter(
+ {
+ letter => $letter,
+ borrowernumber => $patron->id,
+ to_address => $emailaddr,
+ message_transport_type => 'email'
+ }
+ );
+ SendQueuedMessages({ message_id => $message_id });
+ };
+ }
+ }