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