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