Lines 8-14
Link Here
|
8 |
</head> |
8 |
</head> |
9 |
<body id="pat_two_factor_auth" class="pat"> |
9 |
<body id="pat_two_factor_auth" class="pat"> |
10 |
[% INCLUDE 'header.inc' %] |
10 |
[% INCLUDE 'header.inc' %] |
11 |
[% INCLUDE 'patron-search.inc' %] |
11 |
[% PROCESS 'auth-two-factor.inc' %] |
12 |
|
12 |
|
13 |
<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb"> |
13 |
<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb"> |
14 |
<ol> |
14 |
<ol> |
Lines 42-84
Link Here
|
42 |
</p> |
42 |
</p> |
43 |
</div> |
43 |
</div> |
44 |
[% ELSE %] |
44 |
[% ELSE %] |
|
|
45 |
[% PROCESS registration_form %] |
45 |
|
46 |
|
46 |
[% IF op == 'register' %] |
47 |
<div id="registration-status"> |
47 |
<div class="dialog message"> |
|
|
48 |
<p>We recommend cloud-based mobile authenticator apps such as Authy, Duo Mobile, and LastPass. They can restore access if you lose your hardware device.</p> |
49 |
<p>Can't scan the code?</p> |
50 |
<p>To add the entry manually, provide the following details to the application on your phone.</p> |
51 |
<p>Account: [% issuer | html %]</p> |
52 |
<p>Key: [% key_id | html %]</p> |
53 |
<p>Time based: Yes</p> |
54 |
</div> |
55 |
|
56 |
[% IF invalid_pin %] |
57 |
<div class="dialog error">Invalid PIN code</div> |
58 |
[% END %] |
59 |
<form id="two-factor-auth" action="/cgi-bin/koha/members/two_factor_auth.pl" method="post"> |
60 |
<fieldset class="rows"> |
61 |
<input type="hidden" name="csrf_token" value="[% csrf_token | html %]" /> |
62 |
<input type="hidden" name="op" value="register-2FA" /> |
63 |
<input type="hidden" name="secret32" value="[% secret32 | html %]" /> |
64 |
<ol> |
65 |
<li> |
66 |
<label for="qr_code">QR code: </label> |
67 |
<img id="qr_code" src="[% qr_code | $raw %]" /> |
68 |
</li> |
69 |
<li> |
70 |
<label for="pin_code">PIN code: </label> |
71 |
<input type="text" id="pin_code" name="pin_code" value="" /> |
72 |
</li> |
73 |
</ol> |
74 |
</fieldset> |
75 |
<fieldset class="action"> |
76 |
<input type="submit" value="Register with two-factor app" /> |
77 |
<a class="cancel" href="/cgi-bin/koha/members/two_factor_auth.pl">Cancel</a> |
78 |
</fieldset> |
79 |
</form> |
80 |
[% ELSE %] |
81 |
[% IF patron.auth_method == "two-factor" %] |
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 %] |
82 |
<div class="two-factor-status">Status: Enabled</div> |
53 |
<div class="two-factor-status">Status: Enabled</div> |
83 |
|
54 |
|
84 |
<form id="two-factor-auth" action="/cgi-bin/koha/members/two_factor_auth.pl" method="post"> |
55 |
<form id="two-factor-auth" action="/cgi-bin/koha/members/two_factor_auth.pl" method="post"> |
Lines 86-102
Link Here
|
86 |
<input type="hidden" name="op" value="disable-2FA" /> |
57 |
<input type="hidden" name="op" value="disable-2FA" /> |
87 |
<input type="submit" value="Disable two-factor authentication" /> |
58 |
<input type="submit" value="Disable two-factor authentication" /> |
88 |
</form> |
59 |
</form> |
|
|
60 |
</div> |
61 |
|
62 |
[% IF patron.auth_method == "password" %] |
63 |
<div id="registration-status-disabled"> |
89 |
[% ELSE %] |
64 |
[% ELSE %] |
|
|
65 |
<div id="registration-status-disabled" style="display: none;"> |
66 |
[% END %] |
90 |
<div class="two-factor-status">Status: Disabled</div> |
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 %] |
91 |
|
71 |
|
92 |
<form id="two-factor-auth" action="/cgi-bin/koha/members/two_factor_auth.pl" method="post"> |
72 |
<input id="enable-2FA" type="submit" value="Enable two-factor authentication" /> |
93 |
<input type="hidden" name="csrf_token" value="[% csrf_token | html %]" /> |
73 |
</div> |
94 |
<input type="hidden" name="op" value="enable-2FA" /> |
74 |
</div> |
95 |
<input type="submit" value="Enable two-factor authentication" /> |
|
|
96 |
</form> |
97 |
|
98 |
[% END %] |
99 |
[% END %] |
100 |
[% END %] |
75 |
[% END %] |
101 |
</main> |
76 |
</main> |
102 |
</div> <!-- /.col-sm-10.col-sm-push-2 --> |
77 |
</div> <!-- /.col-sm-10.col-sm-push-2 --> |
Lines 114-122
Link Here
|
114 |
[% Asset.js("js/members-menu.js") | $raw %] |
89 |
[% Asset.js("js/members-menu.js") | $raw %] |
115 |
<script> |
90 |
<script> |
116 |
$(document).ready(function(){ |
91 |
$(document).ready(function(){ |
117 |
$(".delete").on("click", function(e){ |
92 |
$("#enable-2FA").on("click", function(e){ |
118 |
return confirmDelete(_("Are you sure you want to delete this key?")); |
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 |
$("#registration-form").show(); |
104 |
$("#registration-status").hide(); |
105 |
}, |
106 |
error: function (data) { |
107 |
alert(data); |
108 |
}, |
109 |
}); |
119 |
}); |
110 |
}); |
|
|
111 |
|
112 |
$("#register-2FA").on("click", function(e){ |
113 |
e.preventDefault(); |
114 |
const data = { |
115 |
secret32: $("#secret32").val(), |
116 |
pin_code: $("#pin_code").val(), |
117 |
}; |
118 |
if (!data.pin_code) return; |
119 |
|
120 |
$.ajax({ |
121 |
data: data, |
122 |
type: 'POST', |
123 |
url: '/api/v1/auth/two-factor/registration/verification', |
124 |
success: function (data) { |
125 |
window.location = "/cgi-bin/koha/members/two_factor_auth.pl"; |
126 |
}, |
127 |
error: function (data) { |
128 |
const error = data.responseJSON.error; |
129 |
if ( error == 'Invalid pin' ) { |
130 |
$("#errors").html(_("Invalid PIN code")).show(); |
131 |
} else { |
132 |
alert(error); |
133 |
} |
134 |
}, |
135 |
}); |
136 |
}); |
137 |
|
120 |
}); |
138 |
}); |
121 |
</script> |
139 |
</script> |
122 |
[% END %] |
140 |
[% END %] |