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