Bug 28805: (follow-up) Fix template logic error
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / members / two_factor_auth.tt
1 [% USE raw %]
2 [% USE Koha %]
3 [% USE Asset %]
4 [% PROCESS 'i18n.inc' %]
5 [% SET footerjs = 1 %]
6 [% INCLUDE 'doc-head-open.inc' %]
7 <title>[% FILTER collapse %]
8     [% t("Two-factor authentication") | html %] &rsaquo;
9     [% t("Patrons") | html %] &rsaquo;
10     [% t("Koha") | html %]
11 [% END %]</title>
12 [% INCLUDE 'doc-head-close.inc' %]
13 </head>
14 <body id="pat_two_factor_auth" class="pat">
15 [% WRAPPER 'header.inc' %]
16     [% INCLUDE 'patron-search-header.inc' %]
17 [% END %]
18 [% PROCESS 'auth-two-factor.inc' %]
19
20 [% WRAPPER 'sub-header.inc' %]
21     [% WRAPPER breadcrumbs %]
22         [% WRAPPER breadcrumb_item %]
23             <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>
24         [% END %]
25         [% WRAPPER breadcrumb_item %]
26             <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron.borrowernumber | uri %]">[% INCLUDE 'patron-title.inc' %]</a>
27         [% END %]
28         [% WRAPPER breadcrumb_item bc_active= 1 %]
29             <span>Manage two-factor authentication</span>
30         [% END %]
31     [% END #/ WRAPPER breadcrumbs %]
32 [% END #/ WRAPPER sub-header.inc %]
33
34 <div class="main container-fluid">
35     <div class="row">
36         <div class="col-sm-10 col-sm-push-2">
37             <main>
38
39                 [% INCLUDE 'members-toolbar.inc' %]
40
41                 <h1>Manage two-factor authentication</h1>
42
43                 [% IF ( missing_key ) %]
44                     <div id="error_message" class="dialog message">
45                         <p>
46                             Operation cannot proceed, please define an encryption key in your configuration.
47                         </p>
48                     </div>
49                 [% ELSE %]
50                     [% PROCESS registration_form %]
51
52                     <div id="registration-status">
53                         [% IF patron.auth_method == "two-factor" %]
54                         <div id="registration-status-enabled">
55                         [% ELSE %]
56                         <div id="registration-status-enabled" style="display: none;">
57                         [% END %]
58                             <div class="two-factor-status">Status: Enabled</div>
59
60                             <form id="two-factor-auth" action="/cgi-bin/koha/members/two_factor_auth.pl" method="post">
61                                 <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
62                                 <input type="hidden" name="op" value="disable-2FA" />
63                                 <input type="submit" value="Disable two-factor authentication" />
64                             </form>
65                         </div>
66
67                         [% IF patron.auth_method == "password" %]
68                         <div id="registration-status-disabled">
69                         [% ELSE %]
70                         <div id="registration-status-disabled" style="display: none;">
71                         [% END %]
72                             <div class="two-factor-status">Status: Disabled</div>
73                             [% IF Koha.Preference('TwoFactorAuthentication') == 'enforced' %]
74                                 <div>Two-factor authentication is mandatory to login. If you do not enable now it will be asked at your next login.</div>
75                             [% END %]
76
77                             <input id="enable-2FA" type="submit" value="Enable two-factor authentication" />
78                         </div>
79                     </div>
80                 [% END %]
81             </main>
82         </div> <!-- /.col-sm-10.col-sm-push-2 -->
83
84         <div class="col-sm-2 col-sm-pull-10">
85             <aside>
86                 [% INCLUDE 'circ-menu.inc' %]
87             </aside>
88         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
89     </div> <!-- /.row -->
90
91
92 [% MACRO jsinclude BLOCK %]
93     [% INCLUDE 'str/members-menu.inc' %]
94     [% Asset.js("js/members-menu.js") | $raw %]
95     <script>
96         $(document).ready(function(){
97             $("#enable-2FA").on("click", function(e){
98                 e.preventDefault();
99                 $.ajax({
100                     data: {},
101                     type: 'POST',
102                     url: '/api/v1/auth/two-factor/registration',
103                     success: function (data) {
104                         $("#qr_code").attr('src', data.qr_code);
105                         $("#secret32").val(data.secret32);
106                         $("#issuer").html(data.issuer);
107                         $("#key_id").html(data.key_id);
108                         $("#key_secret").html(data.secret32);
109                         $("#registration-form").show();
110                         $("#registration-status").hide();
111                     },
112                     error: function (data) {
113                         alert(data);
114                     },
115                 });
116             });
117
118             $("#register-2FA").on("click", function(e){
119                 e.preventDefault();
120                 const data = {
121                     secret32: $("#secret32").val(),
122                     pin_code: $("#pin_code").val(),
123                 };
124                 if (!data.pin_code) return;
125
126                 $.ajax({
127                     data: data,
128                     type: 'POST',
129                     url: '/api/v1/auth/two-factor/registration/verification',
130                     success: function (data) {
131                         window.location = "/cgi-bin/koha/members/two_factor_auth.pl";
132                     },
133                     error: function (data) {
134                         const error = data.responseJSON.error;
135                         if ( error == 'Invalid pin' ) {
136                             $("#errors").html(_("Invalid PIN code")).show();
137                         } else {
138                             alert(error);
139                         }
140                     },
141                 });
142             });
143
144         });
145     </script>
146 [% END %]
147
148 [% INCLUDE 'intranet-bottom.inc' %]