Lines 58-90
if (
Link Here
|
58 |
} |
58 |
} |
59 |
); |
59 |
); |
60 |
|
60 |
|
61 |
my $patron_attrs = $m->unblessed; |
61 |
my $libraryhasverified = $cgi->param('approved'); |
62 |
$patron_attrs->{password} ||= Koha::AuthUtils::generate_password; |
62 |
my $needlibraryverification = C4::Context->preference('PatronSelfRegistrationVerifyByEmailToLibrary'); |
63 |
my $consent_dt = delete $patron_attrs->{gdpr_proc_consent}; |
63 |
|
64 |
$patron_attrs->{categorycode} ||= C4::Context->preference('PatronSelfRegistrationDefaultCategory'); |
64 |
my $action; |
65 |
delete $patron_attrs->{timestamp}; |
65 |
if ( $libraryhasverified && $needlibraryverification ) { |
66 |
delete $patron_attrs->{verification_token}; |
66 |
$action = 'libraryhasverified'; |
67 |
delete $patron_attrs->{changed_fields}; |
67 |
} elsif ( !$libraryhasverified && $needlibraryverification ) { |
68 |
my $patron = Koha::Patron->new( $patron_attrs )->store; |
68 |
$action = 'librarytoverify'; |
69 |
|
69 |
} else { |
70 |
Koha::Patron::Consent->new({ borrowernumber => $patron->borrowernumber, type => 'GDPR_PROCESSING', given_on => $consent_dt })->store if $consent_dt; |
70 |
$action = 'nolibraryverification'; |
71 |
|
71 |
} |
72 |
if ($patron) { |
72 |
|
73 |
$m->delete(); |
73 |
$template->param( action => $action ); |
74 |
C4::Form::MessagingPreferences::handle_form_action($cgi, { borrowernumber => $patron->borrowernumber }, $template, 1, C4::Context->preference('PatronSelfRegistrationDefaultCategory') ) if C4::Context->preference('EnhancedMessagingPreferences'); |
74 |
|
75 |
|
75 |
if ($action eq 'nolibraryverification' || $action eq 'libraryhasverified') { |
76 |
$template->param( password_cleartext => $patron->plain_text_password ); |
76 |
|
77 |
$template->param( borrower => $patron ); |
77 |
# Create account as library verification not required or already done |
78 |
$template->param( |
78 |
my $patron_attrs = $m->unblessed; |
79 |
PatronSelfRegistrationAdditionalInstructions => |
79 |
$patron_attrs->{password} ||= Koha::AuthUtils::generate_password; |
80 |
C4::Context->preference( |
80 |
my $consent_dt = delete $patron_attrs->{gdpr_proc_consent}; |
81 |
'PatronSelfRegistrationAdditionalInstructions') |
81 |
$patron_attrs->{categorycode} ||= C4::Context->preference('PatronSelfRegistrationDefaultCategory'); |
|
|
82 |
delete $patron_attrs->{timestamp}; |
83 |
delete $patron_attrs->{verification_token}; |
84 |
delete $patron_attrs->{changed_fields}; |
85 |
my $patron = Koha::Patron->new( $patron_attrs )->store; |
86 |
|
87 |
# If library verification required then send password reset email directly to patron |
88 |
if ($needlibraryverification) { |
89 |
my $letter = C4::Letters::GetPreparedLetter( |
90 |
module => 'members', |
91 |
letter_code => 'SELF_REG_APPROVED', |
92 |
lang => 'default', # Patron does not have a preferred language defined yet |
93 |
tables => { |
94 |
borrowers => $patron->borrowernumber, |
95 |
}, |
96 |
); |
97 |
|
98 |
C4::Letters::EnqueueLetter( |
99 |
{ |
100 |
letter => $letter, |
101 |
message_transport_type => 'email', |
102 |
to_address => $patron->email, |
103 |
from_address => C4::Context->preference('KohaAdminEmailAddress'), |
104 |
} |
105 |
); |
106 |
|
107 |
my $num_letters_attempted = C4::Letters::SendQueuedMessages( { |
108 |
letter_code => 'SELF_REG_APPROVED' |
109 |
} ); |
110 |
} |
111 |
|
112 |
Koha::Patron::Consent->new({ borrowernumber => $patron->borrowernumber, type => 'GDPR_PROCESSING', given_on => $consent_dt })->store if $consent_dt; |
113 |
|
114 |
if ($patron) { |
115 |
$m->delete(); |
116 |
C4::Form::MessagingPreferences::handle_form_action($cgi, { borrowernumber => $patron->borrowernumber }, $template, 1, C4::Context->preference('PatronSelfRegistrationDefaultCategory') ) if C4::Context->preference('EnhancedMessagingPreferences'); |
117 |
|
118 |
$template->param( password_cleartext => $patron->plain_text_password ); |
119 |
$template->param( borrower => $patron ); |
120 |
$template->param( |
121 |
PatronSelfRegistrationAdditionalInstructions => |
122 |
C4::Context->preference( |
123 |
'PatronSelfRegistrationAdditionalInstructions') |
124 |
); |
125 |
|
126 |
my ($theme, $news_lang, $availablethemes) = C4::Templates::themelanguage(C4::Context->config('opachtdocs'),'opac-registration-confirmation.tt','opac',$cgi); |
127 |
$template->param( news_lang => $news_lang ); |
128 |
} |
129 |
|
130 |
} else { |
131 |
|
132 |
# Send verification email to library to approve |
133 |
my $toaddress; |
134 |
if ($needlibraryverification eq "BranchEmailAddress" ) { |
135 |
my $library = Koha::Libraries->find( $m->branchcode ); |
136 |
$toaddress = $library->branchreplyto |
137 |
|| $library->branchemail |
138 |
|| C4::Context->preferences('ReplytoDefault') |
139 |
|| C4::Context->preferences('KohaAdminEmailAddress') |
140 |
} |
141 |
elsif ( $needlibraryverification eq "KohaAdminEmailAddress" ) { |
142 |
$toaddress = C4::Context->preference('ReplytoDefault') |
143 |
|| C4::Context->preference('KohaAdminEmailAddress'); |
144 |
} |
145 |
|
146 |
my $patron_attrs = $m->unblessed; |
147 |
my $letter; |
148 |
# Send verification email to library |
149 |
$letter = C4::Letters::GetPreparedLetter( |
150 |
module => 'members', |
151 |
letter_code => 'STAFF_VER_OPAC_REG', |
152 |
lang => 'default', # Patron does not have a preferred language defined yet |
153 |
tables => { |
154 |
borrower_modifications => $patron_attrs->{verification_token}, |
155 |
}, |
82 |
); |
156 |
); |
83 |
|
157 |
|
84 |
my ($theme, $news_lang, $availablethemes) = C4::Templates::themelanguage(C4::Context->config('opachtdocs'),'opac-registration-confirmation.tt','opac',$cgi); |
158 |
C4::Letters::EnqueueLetter( |
85 |
$template->param( news_lang => $news_lang ); |
159 |
{ |
|
|
160 |
letter => $letter, |
161 |
message_transport_type => 'email', |
162 |
to_address => $toaddress, |
163 |
from_address => |
164 |
C4::Context->preference('KohaAdminEmailAddress'), |
165 |
} |
166 |
); |
167 |
my $num_letters_attempted = C4::Letters::SendQueuedMessages( { |
168 |
letter_code => 'STAFF_VER_OPAC_REG' |
169 |
} ); |
86 |
} |
170 |
} |
87 |
|
|
|
88 |
} |
171 |
} |
89 |
else { |
172 |
else { |
90 |
( $template, $borrowernumber, $cookie ) = get_template_and_user( |
173 |
( $template, $borrowernumber, $cookie ) = get_template_and_user( |
91 |
- |
|
|