Bug 35935: Ensure login branch will be used after incorrect login
[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         <input type="hidden" name="koha_login_context" value="intranet" />
127     [% FOREACH INPUT IN INPUTS %]
128         [% NEXT IF INPUT.name == "koha_login_context" %]
129         [% NEXT IF INPUT.name == "branch" %]
130         <input type="hidden" name="[% INPUT.name | html %]" value="[% INPUT.value | html %]" />
131     [% END %]
132     <p><label for="userid">Username:</label>
133     <input type="text" name="userid" id="userid" class="input focus" value="[% userid | html %]" size="20" tabindex="1" autocomplete="off" />
134     </p>
135     <p><label for="password">Password:</label>
136     <input type="password" name="password" id="password" class="input" value="" size="20" tabindex="2" autocomplete="off" />
137     </p>
138
139     [% UNLESS IndependentBranches %]
140         <p>
141             [% IF Koha.Preference('ForceLibrarySelection') %]
142                 <label for="branch" class="required">Library:</label>
143                 <select name="branch" id="branch" class="input" tabindex="3" required="required">
144                 <option value=""></option>
145             [% ELSE %]
146                 <label for="branch">Library:</label>
147                 <select name="branch" id="branch" class="input" tabindex="3">
148                 <option value="">My library</option>
149             [% END %]
150                 [% FOREACH l IN Branches.all( unfiltered => 1 ) %]
151                     <option value="[% l.branchcode | html %]">[% l.branchname | html %]</option>
152                  [% END %]
153             </select>
154             [% IF Koha.Preference('ForceLibrarySelection') %]
155                 <span class="required">Required</span>
156             [% END %]
157         </p>
158
159         [% IF Koha.Preference('UseCirculationDesks') && Desks.all %]
160         <p>
161             <label for="desk">Desk:</label>
162             <select name="desk_id" id="desk_id" class="input" tabindex="3">
163                 <option id="nodesk" value="">---</option>
164                     [% FOREACH d IN Desks.all %]
165                     <option class="[% d.branchcode | html %]" value="[% d.desk_id | html %]" disabled >[% d.desk_name | html %]</option>
166                     [% END %]
167             </select>
168         </p>
169         [% END %]
170
171         [% IF Koha.Preference('UseCashRegisters') && Registers.all().size %]
172         <p>
173             <label for="register_id">Cash register:</label>
174             <select name="register_id" id="register_id" class="input" tabindex="4">
175                 <option id="noregister" value="" selected="selected">Library default</option>
176                 [% PROCESS options_for_registers registers => Registers.all() %]
177             </select>
178         </p>
179         [% END %]
180
181     [% END %]
182
183     <!-- <p><label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="3" />Remember me</label></p> -->
184
185     <p class="submit"><input id="submit-button" type="submit" class="btn btn-primary" value="Log in" tabindex="4" /></p>
186     </form>
187
188     [% IF ( casAuthentication ) %]
189         <h4>Cas login</h4>
190
191         [% IF ( invalidCasLogin ) %]
192         <!-- This is what is displayed if cas login has failed -->
193         <p>Sorry, the CAS login failed.</p>
194         [% END %]
195
196         [% IF ( casServerUrl ) %]
197             <p><a href="[% casServerUrl | $raw %]">If you have a CAS account, please click here to login</a>.<p>
198         [% END %]
199
200         [% IF ( casServersLoop ) %]
201             <p>If you have a CAS account, please choose against which one you would like to authenticate:</p>
202         <ul>
203             [% FOREACH casServer IN casServersLoop %]
204                 <li><a href="[% casServer.value | $raw %]">[% casServer.name | html %]</a></li>
205             [% END %]
206         [% END %]
207     [% END %]
208 [% ELSIF TwoFA_prompt %]
209     <form action="[% script_name | html %]" method="post" name="loginform" id="loginform" autocomplete="off">
210         <input type="hidden" name="koha_login_context" value="intranet" />
211         [% FOREACH INPUT IN INPUTS %]
212             <input type="hidden" name="[% INPUT.name | html %]" value="[% INPUT.value | html %]" />
213         [% END %]
214         [% IF invalid_otp_token %]
215             <div id="login_error">Invalid two-factor code</div>
216         [% END %]
217
218         <div id="email_error" class="dialog alert" style="display: none;"></div>
219         <div id="email_success" class="dialog message" style="display: none;"></div>
220         <p>
221             <label for="otp_token">Two-factor authentication code:</label>
222             <input type="text" name="otp_token" id="otp_token" class="input focus" value="" size="20" tabindex="1" />
223         </p>
224         <p>
225             <input type="submit" id="submit-button" class="btn btn-primary" value="Verify code" />
226             <a class="send_otp" id="send_otp" href="#">Send the code by email</a>
227             <a class="cancel" id="logout" href="/cgi-bin/koha/mainpage.pl?logout.x=1">Cancel</a>
228         </p>
229
230     </form>
231 [% ELSIF TwoFA_setup %]
232     [% PROCESS registration_form %]
233 [% END %]
234
235 [% IF ( nopermission ) %]
236     <p><a id="previous_page" href="javascript:window.history.back()">[Previous page]</a>
237     <a id="mainpage" href="/">[Main page]</a></p>
238 [% END %]
239
240
241 <!--<ul> -->
242 <!--    <li><a href="/cgi-bin/koha/lostpassword.pl" title="Password lost and found">Lost your password?</a></li> -->
243 <!-- </ul> -->
244
245 </div>
246
247 [% MACRO jsinclude BLOCK %]
248     [% Asset.js("js/desk_selection.js") | $raw %]
249     [% Asset.js("js/register_selection.js") | $raw %]
250     <script>
251         $(document).ready( function() {
252             if ( document.location.hash ) {
253                 $( '#loginform' ).append( '<input name="auth_forwarded_hash" type="hidden" value="' + document.location.hash + '"/>' );
254             }
255             // Clear last borrowers, rememberd sql reports, carts, etc.
256             logOut();
257
258             $("#send_otp").on("click", function(e){
259                 e.preventDefault();
260                 [% UNLESS notice_email_address %]
261                     alert("Cannot send the notice, you don't have an email address defined.")
262                 [% ELSE %]
263                 $("#email_success").hide();
264                 $("#email_error").hide();
265                     $.ajax({
266                         url: '/api/v1/auth/otp/token_delivery',
267                         type: 'POST',
268                         success: function(data){
269                             let message = _("The code has been sent by email, please check your inbox.")
270                             $("#email_success").show().html(message);
271                         },
272                         error: function(data){
273                             let error = data.responseJSON && data.responseJSON.error == "email_not_sent"
274                                 ? _("Email not sent, please contact the Koha administrator")
275                                 : _("Something wrong happened, please contact the Koha administrator");
276                             $("#email_error").show().html(error);
277                         }
278                     });
279                 [% END %]
280             });
281
282             if( $("#registration-form").length ) {
283                 $.ajax({
284                     data: {},
285                     type: 'POST',
286                     url: '/api/v1/auth/two-factor/registration',
287                     success: function (data) {
288                         $("#qr_code").attr('src', data.qr_code);
289                         $("#secret32").val(data.secret32);
290                         $("#issuer").html(data.issuer);
291                         $("#key_id").html(data.key_id);
292                         $("#key_secret").html(data.secret32);
293                         $("#registration-form").show();
294                     },
295                     error: function (data) {
296                         alert(data);
297                     },
298                 });
299             };
300
301             $("#register-2FA").on("click", function(e){
302                 e.preventDefault();
303                 const data = {
304                     secret32: $("#secret32").val(),
305                     pin_code: $("#pin_code").val(),
306                 };
307                 if (!data.pin_code) return;
308
309                 $.ajax({
310                     data: data,
311                     type: 'POST',
312                     url: '/api/v1/auth/two-factor/registration/verification',
313                     success: function (data) {
314                         return;
315                     },
316                     error: function (data) {
317                         const error = data.responseJSON.error;
318                         if ( error == 'Invalid pin' ) {
319                             $("#errors").html(_("Invalid PIN code")).show();
320                         } else {
321                             alert(error);
322                         }
323                     },
324                 }).then(function(){
325                     alert(_("Two-factor authentication correctly configured. You will be redirected to the login screen."));
326                     window.location = "/cgi-bin/koha/mainpage.pl";
327                 });
328             });
329
330         });
331     </script>
332 [% END %]
333 <!-- the main div is closed in intranet-bottom.inc -->
334 [% INCLUDE 'intranet-bottom.inc' %]