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