Bug 28787: Don't request a token if no email address defined
[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 [% SET footerjs = 1 %]
9 [% INCLUDE 'doc-head-open.inc' %]
10 <title>
11     [% IF TwoFA_prompt %]Two-factor authentication[% END %]
12     [% IF ( loginprompt ) %]Log in to Koha[% END %]
13     [% IF too_many_login_attempts %]This account has been locked.
14     [% ELSIF invalid_username_or_password %]Invalid username or password[% END %]
15     [% IF ( different_ip ) %]IP address change[% END %]
16     [% IF ( timed_out ) %]Session timed out[% END %]
17     [% IF ( nopermission ) %]Access denied[% END %] &rsaquo; Koha
18 </title>
19 [% INCLUDE 'doc-head-close.inc' %]
20 </head>
21 <body id="main_auth" class="main_main-auth">
22
23 <div class="main container-fluid">
24
25 <div id="login">
26 <h1><a href="http://koha-community.org">Koha</a></h1>
27 [% IF (Koha.Preference('StaffLoginInstructions')) %]<div id="login_instructions">[% Koha.Preference('StaffLoginInstructions') | $raw %]</div>[% END %]
28 [% IF ( nopermission ) %]
29 <div id="login_error">
30     <strong>Error:</strong>
31     You do not have permission to access this page.
32 </div>
33 <p><strong>Log in as a different user</strong></p></h2>
34 [% END %]
35
36 [% IF ( timed_out ) %]
37 <div id="login_error"><strong>Error: </strong>Session timed out.<br /> Please log in again</div>
38 [% END %]
39
40 [% IF ( different_ip ) %]
41 <div id="login_error"><strong>Error: </strong>IP address has changed. Please log in again </div>
42 [% END %]
43
44 [% IF ( wrongip ) %]
45 <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>
46 [% END %]
47
48 [% IF too_many_login_attempts %]
49     <div id="login_error"><strong>Error: </strong>This account has been locked!</div>
50     [% IF Categories.can_any_reset_password && Koha.Preference('OpacBaseURL') %]
51         <a href="[% Koha.Preference('OpacBaseURL') | url %]/cgi-bin/koha/opac-password-recovery.pl">You must reset your password</a>.
52     [% END %]
53 [% ELSIF password_has_expired %]
54     <div id="login_error"><strong>Error: </strong>Your password has expired!</div>
55     [% IF Koha.Preference('EnableExpiredPasswordReset') && Koha.Preference('OpacBaseURL') %]
56         <a href="[% Koha.Preference('OpacBaseURL') | url %]/cgi-bin/koha/opac-reset-password.pl">You must reset your password</a>.
57     [% ELSIF Categories.can_any_reset_password && Koha.Preference('OpacBaseURL') %]
58         <a href="[% Koha.Preference('OpacBaseURL') | url %]/cgi-bin/koha/opac-password-recovery.pl">You must reset your password</a>.
59     [% ELSE %]
60         <p>You must contact the library to reset your password</p>
61     [% END %]
62 [% ELSIF invalid_username_or_password %]
63 <div id="login_error"><strong>Error: </strong>Invalid username or password</div>
64 [% END %]
65
66 [% IF (shibbolethAuthentication) %]
67 <!-- This is what is displayed if shib login has failed -->
68 [% IF (invalidShibLogin ) %]
69 <div id="login_error"><Strong>Error: </strong>Shibboleth login failed</div>
70 [% END %]
71 <p><a href="[% shibbolethLoginUrl | $raw %]">Log in using a Shibboleth account</a>.</p>
72 [% END %]
73
74 [% IF !TwoFA_prompt && !Koha.Preference('staffShibOnly') %]
75     <!-- login prompt time-->
76     <form action="[% script_name | html %]" method="post" name="loginform" id="loginform">
77         <input type="hidden" name="koha_login_context" value="intranet" />
78     [% FOREACH INPUT IN INPUTS %]
79         <input type="hidden" name="[% INPUT.name | html %]" value="[% INPUT.value | html %]" />
80     [% END %]
81     <p><label for="userid">Username:</label>
82     <input type="text" name="userid" id="userid" class="input focus" value="[% userid | html %]" size="20" tabindex="1" autocomplete="off" />
83     </p>
84     <p><label for="password">Password:</label>
85     <input type="password" name="password" id="password" class="input" value="" size="20" tabindex="2" autocomplete="off" />
86     </p>
87
88     [% UNLESS IndependentBranches %]
89         <p>
90             <label for="branch">Library:</label>
91             <select name="branch" id="branch" class="input" tabindex="3">
92                 <option value="">My library</option>
93                 [% FOREACH l IN Branches.all( unfiltered => 1 ) %]
94                     <option value="[% l.branchcode | html %]">[% l.branchname | html %]</option>
95                  [% END %]
96             </select>
97         </p>
98
99         [% IF Koha.Preference('UseCirculationDesks') && Desks.all %]
100         <p>
101             <label for="desk">Desk:</label>
102             <select name="desk_id" id="desk_id" class="input" tabindex="3">
103                 <option id="nodesk" value="">---</option>
104                     [% FOREACH d IN Desks.all %]
105                     <option class="[% d.branchcode | html %]" value="[% d.desk_id | html %]" disabled >[% d.desk_name | html %]</option>
106                     [% END %]
107             </select>
108         </p>
109         [% END %]
110
111         [% IF Koha.Preference('UseCashRegisters') && Registers.all().size %]
112         <p>
113             <label for="register_id">Cash register:</label>
114             <select name="register_id" id="register_id" class="input" tabindex="4">
115                 <option id="noregister" value="" selected="selected">Library default</option>
116                 [% PROCESS options_for_registers registers => Registers.all() %]
117             </select>
118         </p>
119         [% END %]
120
121     [% END %]
122
123     <!-- <p><label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="3" />Remember me</label></p> -->
124
125     <p class="submit"><input id="submit-button" type="submit" value="Log in" tabindex="4" /></p>
126     </form>
127
128     [% IF ( casAuthentication ) %]
129         <h4>Cas login</h4>
130
131         [% IF ( invalidCasLogin ) %]
132         <!-- This is what is displayed if cas login has failed -->
133         <p>Sorry, the CAS login failed.</p>
134         [% END %]
135
136         [% IF ( casServerUrl ) %]
137             <p><a href="[% casServerUrl | $raw %]">If you have a CAS account, please click here to login</a>.<p>
138         [% END %]
139
140         [% IF ( casServersLoop ) %]
141             <p>If you have a CAS account, please choose against which one you would like to authenticate:</p>
142         <ul>
143             [% FOREACH casServer IN casServersLoop %]
144                 <li><a href="[% casServer.value | $raw %]">[% casServer.name | html %]</a></li>
145             [% END %]
146         [% END %]
147     [% END %]
148 [% ELSIF TwoFA_prompt %]
149     <form action="[% script_name | html %]" method="post" name="loginform" id="loginform">
150         <input type="hidden" name="koha_login_context" value="intranet" />
151         [% FOREACH INPUT IN INPUTS %]
152             <input type="hidden" name="[% INPUT.name | html %]" value="[% INPUT.value | html %]" />
153         [% END %]
154         [% IF invalid_otp_token %]
155             <div id="login_error">Invalid two-factor code</div>
156         [% END %]
157
158         <div id="email_error" class="dialog alert" style="display: none;"></div>
159         <div id="email_success" class="dialog message" style="display: none;"></div>
160         <p>
161             <label for="otp_token">Two-factor authentication code:</label>
162             <input type="text" name="otp_token" id="otp_token" class="input focus" value="" size="20" tabindex="1" />
163         </p>
164         <p>
165             <input id="submit-button" type="submit" value="Verify code" />
166             <a class="send_otp" id="send_otp" href="#">Send the code by email</a>
167             <a class="cancel" id="logout" href="/cgi-bin/koha/mainpage.pl?logout.x=1">Cancel</a>
168         </p>
169
170     </form>
171 [% END %]
172
173 [% IF ( nopermission ) %]
174     <p><a id="previous_page" href="javascript:window.history.back()">[Previous page]</a>
175     <a id="mainpage" href="/">[Main page]</a></p>
176 [% END %]
177
178
179 <!--<ul> -->
180 <!--    <li><a href="/cgi-bin/koha/lostpassword.pl" title="Password lost and found">Lost your password?</a></li> -->
181 <!-- </ul> -->
182
183 </div>
184
185 [% MACRO jsinclude BLOCK %]
186     [% Asset.js("js/desk_selection.js") | $raw %]
187     [% Asset.js("js/register_selection.js") | $raw %]
188     <script>
189         $(document).ready( function() {
190             if ( document.location.hash ) {
191                 $( '#loginform' ).append( '<input name="auth_forwarded_hash" type="hidden" value="' + document.location.hash + '"/>' );
192             }
193             // Clear last borrowers, rememberd sql reports, carts, etc.
194             logOut();
195
196             $("#send_otp").on("click", function(e){
197                 e.preventDefault();
198                 [% UNLESS notice_email_address %]
199                     alert("Cannot send the notice, you don't have an email address defined.")
200                 [% ELSE %]
201                 $("#email_success").hide();
202                 $("#email_error").hide();
203                     $.ajax({
204                         url: '/api/v1/auth/otp/token_delivery',
205                         type: 'POST',
206                         success: function(data){
207                             let message = _("The code has been sent by email, please check your inbox.")
208                             $("#email_success").show().html(message);
209                         },
210                         error: function(data){
211                             let error = data.responseJSON && data.responseJSON.error == "email_not_sent"
212                                 ? _("Email not sent, please contact the Koha administrator")
213                                 : _("Something wrong happened, please contact the Koha administrator");
214                             $("#email_error").show().html(error);
215                         }
216                     });
217                 [% END %]
218             });
219         });
220     </script>
221 [% END %]
222 <!-- the main div is closed in intranet-bottom.inc -->
223 [% INCLUDE 'intranet-bottom.inc' %]