Bug 33568: Display library names instead of codes for recall
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / auth.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE Branches %]
5 [% USE Desks %]
6 [% USE Categories %]
7 [% USE Registers %]
8 [% USE AuthClient %]
9 [% PROCESS 'i18n.inc' %]
10 [% SET footerjs = 1 %]
11 [% INCLUDE 'doc-head-open.inc' %]
12 <title>[% FILTER collapse %]
13     [% IF TwoFA_prompt %]
14         [% t("Two-factor authentication") | html %] &rsaquo;
15     [% END %]
16     [% IF TwoFA_setup %]
17         [% t("Two-factor authentication setup") | html %] &rsaquo;
18     [% END %]
19     [% IF too_many_login_attempts %]
20         [% t("This account has been locked.") | html %] &rsaquo;
21     [% ELSIF invalid_username_or_password %]
22         [% t("Invalid username or password") | html %] &rsaquo;
23     [% END %]
24     [% IF ( different_ip ) %]
25         [% t("IP address change") | html %] &rsaquo;
26     [% END %]
27     [% IF ( timed_out ) %]
28         [% t("Session timed out") | html %] &rsaquo;
29     [% END %]
30     [% IF ( nopermission ) %]
31         [% t("Access denied") | html %] &rsaquo;
32     [% END %]
33     [% IF ( auth_error ) %]
34         [% t("Error authenticating with external provider") | html %] &rsaquo;
35     [% END %]
36     [% IF ( loginprompt ) %]
37         [% t("Log in to Koha") | html %] &rsaquo;
38     [% END %]
39     [% t("Koha") | html %]
40 [% END %]</title>
41 [% INCLUDE 'doc-head-close.inc' %]
42 [% PROCESS 'auth-two-factor.inc' %]
43 </head>
44 <body id="main_auth" class="main_main-auth">
45
46 <div class="main container-fluid">
47     [% INCLUDE 'messages.inc' %]
48
49 <div id="login">
50 <h1><a href="http://koha-community.org">Koha</a></h1>
51 [% IF (Koha.Preference('StaffLoginInstructions')) %]<div id="login_instructions">[% Koha.Preference('StaffLoginInstructions') | $raw %]</div>[% END %]
52 [% IF ( nopermission ) %]
53 <div id="login_error">
54     <strong>Error:</strong>
55     You do not have permission to access this page.
56 </div>
57 <p><strong>Log in as a different user</strong></p></h2>
58 [% END %]
59
60 [% IF ( timed_out ) %]
61 <div id="login_error"><strong>Error: </strong>Session timed out.<br /> Please log in again</div>
62 [% END %]
63
64 [% IF ( different_ip ) %]
65 <div id="login_error"><strong>Error: </strong>IP address has changed. Please log in again </div>
66 [% END %]
67
68 [% IF ( wrongip ) %]
69 <div id="login_error"><strong>Error: </strong>Autolocation is switched on and you are logging in with an IP address that doesn't match your library. </div>
70 [% END %]
71
72 [% IF too_many_login_attempts %]
73     <div id="login_error"><strong>Error: </strong>This account has been locked!</div>
74     [% IF Categories.can_any_reset_password && Koha.Preference('OpacBaseURL') %]
75         <a href="[% Koha.Preference('OpacBaseURL') | url %]/cgi-bin/koha/opac-password-recovery.pl">You must reset your password</a>.
76     [% END %]
77 [% ELSIF password_has_expired %]
78     <div id="login_error"><strong>Error: </strong>Your password has expired!</div>
79     [% IF Koha.Preference('EnableExpiredPasswordReset') && Koha.Preference('OpacBaseURL') %]
80         <a href="[% Koha.Preference('OpacBaseURL') | url %]/cgi-bin/koha/opac-reset-password.pl">You must reset your password</a>.
81     [% ELSIF Categories.can_any_reset_password && Koha.Preference('OpacBaseURL') %]
82         <a href="[% Koha.Preference('OpacBaseURL') | url %]/cgi-bin/koha/opac-password-recovery.pl">You must reset your password</a>.
83     [% ELSE %]
84         <p>You must contact the library to reset your password</p>
85     [% END %]
86 [% ELSIF invalid_username_or_password %]
87 <div id="login_error"><strong>Error: </strong>Invalid username or password</div>
88 [% END %]
89
90 [% IF auth_error %]
91     <div id="login_error" class="alert alert-danger">
92         <p>There was an error authenticating to external identity provider</p>
93         <p>[% auth_error | html %]</p>
94     </div>
95 [% END %]
96
97 [% IF (shibbolethAuthentication) %]
98 <!-- This is what is displayed if shib login has failed -->
99 [% IF (invalidShibLogin ) %]
100 <div id="login_error"><Strong>Error: </strong>Shibboleth login failed</div>
101 [% END %]
102 <p><a href="[% shibbolethLoginUrl | $raw %]">Log in using a Shibboleth account</a>.</p>
103 [% END %]
104
105 [% IF !TwoFA_prompt && !TwoFA_setup && !Koha.Preference('staffShibOnly') %]
106     <!-- login prompt time-->
107     [% SET identity_providers = AuthClient.get_providers('staff') %]
108     [% IF ( ! identity_providers.empty ) %]
109         [% FOREACH provider IN identity_providers %]
110             <p class="clearfix">
111                 <a href="[% provider.url | url %]" class="btn btn-light col-xs-12" id="provider_[% provider.code | html %]">
112                     [% IF provider.icon_url %]
113                     <img src="[% provider.icon_url | url %]"  style="max-height: 20px; max-width: 20px;"/>
114                     [% ELSE %]
115                     <i class="fa fa-user" aria-hidden="true"></i>
116                     [% END %]
117                     Log in with [% provider.description | html %]
118                 </a>
119             </p>
120         [% END %]
121         <hr/>
122         <p>If you do not have an external account, but do have a local account, you can still log in: </p>
123     [% END # /IF  identity_providers.size %]
124
125     <form action="[% script_name | html %]" method="post" name="loginform" id="loginform" class="validated">
126         [% INCLUDE 'csrf-token.inc' %]
127         <input type="hidden" name="op" value="cud-login" />
128         <input type="hidden" name="koha_login_context" value="intranet" />
129     [% FOREACH INPUT IN INPUTS %]
130         [% NEXT IF INPUT.name == "op" %]
131         [% NEXT IF INPUT.name == "csrf_token" %]
132         [% NEXT IF INPUT.name == "koha_login_context" %]
133         [% NEXT IF INPUT.name == "branch" %]
134         <input type="hidden" name="[% INPUT.name | html %]" value="[% INPUT.value | html %]" />
135     [% END %]
136     <p><label for="userid">Username:</label>
137     <input type="text" name="login_userid" id="userid" class="input focus" value="[% userid | html %]" size="20" tabindex="1" autocomplete="off" />
138     </p>
139     <p><label for="password">Password:</label>
140     <input type="password" name="login_password" id="password" class="input" value="" size="20" tabindex="2" autocomplete="off" />
141     </p>
142
143     [% UNLESS IndependentBranches %]
144         <p>
145             [% IF Koha.Preference('ForceLibrarySelection') %]
146                 <label for="branch" class="required">Library:</label>
147                 <select name="branch" id="branch" class="input" tabindex="3" required="required">
148                 <option value=""></option>
149             [% ELSE %]
150                 <label for="branch">Library:</label>
151                 <select name="branch" id="branch" class="input" tabindex="3">
152                 <option value="">My library</option>
153             [% END %]
154                 [% FOREACH l IN Branches.all( unfiltered => 1 ) %]
155                     <option value="[% l.branchcode | html %]">[% l.branchname | html %]</option>
156                  [% END %]
157             </select>
158             [% IF Koha.Preference('ForceLibrarySelection') %]
159                 <span class="required">Required</span>
160             [% END %]
161         </p>
162
163         [% IF Koha.Preference('UseCirculationDesks') && Desks.all %]
164         <p>
165             <label for="desk">Desk:</label>
166             <select name="desk_id" id="desk_id" class="input" tabindex="3">
167                 <option id="nodesk" value="">---</option>
168                     [% FOREACH d IN Desks.all %]
169                     <option class="[% d.branchcode | html %]" value="[% d.desk_id | html %]" disabled >[% d.desk_name | html %]</option>
170                     [% END %]
171             </select>
172         </p>
173         [% END %]
174
175         [% IF Koha.Preference('UseCashRegisters') && Registers.all().size %]
176         <p>
177             <label for="register_id">Cash register:</label>
178             <select name="register_id" id="register_id" class="input" tabindex="4">
179                 <option id="noregister" value="" selected="selected">Library default</option>
180                 [% PROCESS options_for_registers registers => Registers.all() %]
181             </select>
182         </p>
183         [% END %]
184
185     [% END %]
186
187     <!-- <p><label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="3" />Remember me</label></p> -->
188
189     <p class="submit"><input id="submit-button" type="submit" class="btn btn-primary" value="Log in" tabindex="4" /></p>
190     </form>
191
192     [% IF ( casAuthentication ) %]
193         <h4>Cas login</h4>
194
195         [% IF ( invalidCasLogin ) %]
196         <!-- This is what is displayed if cas login has failed -->
197         <p>Sorry, the CAS login failed.</p>
198         [% END %]
199
200         [% IF ( casServerUrl ) %]
201             <p><a href="[% casServerUrl | $raw %]">If you have a CAS account, please click here to login</a>.<p>
202         [% END %]
203
204         [% IF ( casServersLoop ) %]
205             <p>If you have a CAS account, please choose against which one you would like to authenticate:</p>
206         <ul>
207             [% FOREACH casServer IN casServersLoop %]
208                 <li><a href="[% casServer.value | $raw %]">[% casServer.name | html %]</a></li>
209             [% END %]
210         [% END %]
211     [% END %]
212 [% ELSIF TwoFA_prompt %]
213     <form action="[% script_name | html %]" method="post" name="loginform" id="loginform" autocomplete="off">
214         [% INCLUDE 'csrf-token.inc' %]
215         <input type="hidden" name="op" value="cud-login" />
216         <input type="hidden" name="koha_login_context" value="intranet" />
217         [% FOREACH INPUT IN INPUTS %]
218             [% NEXT IF INPUT.name == "op" %]
219             [% NEXT IF INPUT.name == "csrf_token" %]
220             [% NEXT IF INPUT.name == "koha_login_context" %]
221             [% NEXT IF INPUT.name == "branch" %]
222             <input type="hidden" name="[% INPUT.name | html %]" value="[% INPUT.value | html %]" />
223         [% END %]
224         [% IF invalid_otp_token %]
225             <div id="login_error">Invalid two-factor code</div>
226         [% END %]
227
228         <div id="email_error" class="dialog alert" style="display: none;"></div>
229         <div id="email_success" class="dialog message" style="display: none;"></div>
230         <p>
231             <label for="otp_token">Two-factor authentication code:</label>
232             <input type="text" name="otp_token" id="otp_token" class="input focus" value="" size="20" tabindex="1" />
233         </p>
234         <p>
235             <input type="submit" id="submit-button" class="btn btn-primary" value="Verify code" />
236             <a class="send_otp" id="send_otp" href="#">Send the code by email</a>
237             <a class="cancel" id="logout" href="/cgi-bin/koha/mainpage.pl?logout.x=1">Cancel</a>
238         </p>
239
240     </form>
241 [% ELSIF TwoFA_setup %]
242     [% PROCESS registration_form %]
243 [% END %]
244
245 [% IF ( nopermission ) %]
246     <p><a id="previous_page" href="javascript:window.history.back()">[Previous page]</a>
247     <a id="mainpage" href="/">[Main page]</a></p>
248 [% END %]
249
250
251 <!--<ul> -->
252 <!--    <li><a href="/cgi-bin/koha/lostpassword.pl" title="Password lost and found">Lost your password?</a></li> -->
253 <!-- </ul> -->
254
255 </div>
256
257 [% MACRO jsinclude BLOCK %]
258     [% Asset.js("js/desk_selection.js") | $raw %]
259     [% Asset.js("js/register_selection.js") | $raw %]
260     <script>
261         $(document).ready( function() {
262             if ( document.location.hash ) {
263                 const input = $('<input name="auth_forwarded_hash" type="hidden">')
264                 input.val(document.location.hash);
265                 $( '#loginform' ).append( input );
266             }
267             // Clear last borrowers, rememberd sql reports, carts, etc.
268             logOut();
269
270             $("#send_otp").on("click", function(e){
271                 e.preventDefault();
272                 [% UNLESS notice_email_address %]
273                     alert("Cannot send the notice, you don't have an email address defined.")
274                 [% ELSE %]
275                 $("#email_success").hide();
276                 $("#email_error").hide();
277                     $.ajax({
278                         url: '/api/v1/auth/otp/token_delivery',
279                         type: 'POST',
280                         success: function(data){
281                             let message = _("The code has been sent by email, please check your inbox.")
282                             $("#email_success").show().html(message);
283                         },
284                         error: function(data){
285                             let error = data.responseJSON && data.responseJSON.error == "email_not_sent"
286                                 ? _("Email not sent, please contact the Koha administrator")
287                                 : _("Something wrong happened, please contact the Koha administrator");
288                             $("#email_error").show().html(error);
289                         }
290                     });
291                 [% END %]
292             });
293
294             if( $("#registration-form").length ) {
295                 $.ajax({
296                     data: {},
297                     type: 'POST',
298                     url: '/api/v1/auth/two-factor/registration',
299                     success: function (data) {
300                         $("#qr_code").attr('src', data.qr_code);
301                         $("#secret32").val(data.secret32);
302                         $("#issuer").html(data.issuer);
303                         $("#key_id").html(data.key_id);
304                         $("#key_secret").html(data.secret32);
305                         $("#registration-form").show();
306                     },
307                     error: function (data) {
308                         alert(data);
309                     },
310                 });
311             };
312
313             $("#register-2FA").on("click", function(e){
314                 e.preventDefault();
315                 const data = {
316                     secret32: $("#secret32").val(),
317                     pin_code: $("#pin_code").val(),
318                 };
319                 if (!data.pin_code) return;
320
321                 $.ajax({
322                     data: data,
323                     type: 'POST',
324                     url: '/api/v1/auth/two-factor/registration/verification',
325                     success: function (data) {
326                         return;
327                     },
328                     error: function (data) {
329                         const error = data.responseJSON.error;
330                         if ( error == 'Invalid pin' ) {
331                             $("#errors").html(_("Invalid PIN code")).show();
332                         } else {
333                             alert(error);
334                         }
335                     },
336                 }).then(function(){
337                     alert(_("Two-factor authentication correctly configured. You will be redirected to the login screen."));
338                     window.location = "/cgi-bin/koha/mainpage.pl";
339                 });
340             });
341
342         });
343     </script>
344 [% END %]
345 <!-- the main div is closed in intranet-bottom.inc -->
346 [% INCLUDE 'intranet-bottom.inc' %]