c5bb6c082909bd92274ca3242a76c33b3764e574
3 /* eslint-disable no-unused-vars */
5 const { TemplateHelper: th
} = require('@squeep/html-template-helper');
6 const { TOTP
} = require('@squeep/totp');
8 function updatePasswordSection(ctx
, htmlOptions
) {
9 return `\t\t\t<section class="settings-update-password">
10 \t\t\t\t<h2>Password</h2>
11 \t\t\t\t<form method="POST">
13 \t\t\t\t\t\t<legend>Update Password</legend>
14 \t\t\t\t\t\t<label for="credential-current">Current Password:</label>
15 \t\t\t\t\t\t<input type="password" id="credential-current" name="credential-current" value="">
17 \t\t\t\t\t\t<label for="credential-new">New Password:</label>
18 \t\t\t\t\t\t<input type="password" id="credential-new" name="credential-new" value="">
20 \t\t\t\t\t\t<label for="credential-new-2">Confirm New Password:</label>
21 \t\t\t\t\t\t<input type="password" id="credential-new-2" name="credential-new-2" value="">
23 \t\t\t\t\t\t<button type="submit" name="credential" value="update">Update</button>
30 function enableOTPSection(ctx
, htmlOptions
) {
31 return `\t\t\t<section class="settings-otp">
32 \t\t\t\t<h2>OTP 2FA</h2>
33 \t\t\t\t<form method="POST">
35 \t\t\t\t\t\t<legend>Enable OTP</legend>
36 \t\t\t\t\t\t<button type="submit" name="otp" value="enable">Enable OTP</button>
43 function confirmOTPSection(ctx
, htmlOptions
) {
44 const { secret
, svg
, uri
} = TOTP
.createKeySVG({
45 accountname: ctx
.authenticationId
,
46 }, ctx
.otpConfirmKey
, 'base32');
47 return `\t\t\t<section class="settings-otp">
48 \t\t\t\t<h2>OTP 2FA</h2>
49 \t\t\t\t<form method="POST">
51 \t\t\t\t\t<legend>Confirm OTP Key</legend>
53 \t\t\t\t\t\t\t<details>
54 \t\t\t\t\t\t\t\t<summary>Show Key</summary>
55 \t\t\t\t\t\t\t\tOTP Key (base32): <code>${secret}</code>
57 \t\t\t\t\t\t\t\t\tURI: <code>${uri}</code>
58 \t\t\t\t\t\t\t\t</div>
59 \t\t\t\t\t\t\t</details>
61 \t\t\t\t\t\t<div class="otp-key-qr">
65 \t\t\t\t\t\t<label for="otp-token">Enter OTP token to enable:</label>
66 \t\t\t\t\t\t<input id="otp-token" name="otp-token" type="text" value="">
68 \t\t\t\t\t\t<input type="hidden" name="otp-box" value="${ctx.otpConfirmBox}">
69 \t\t\t\t\t\t<button type="submit" name="otp" value="confirm">Confirm OTP</button>
76 function disableOTPSection(ctx
, htmlOptions
) {
77 return `\t\t\t<section class="settings-otp">
78 \t\t\t\t<h2>OTP 2FA</h2>
79 \t\t\t\t<p>OTP is currrently enabled. It may be removed here.</p>
80 \t\t\t\t<form method="POST">
81 \t\t\t\t\t<button type="submit" name="otp" value="disable">Disable OTP</button>
87 function OTPSection(ctx
, htmlOptions
) {
88 const OTPToggle
= ctx
.otpKey
? disableOTPSection : enableOTPSection
;
89 const OTPContent
= ctx
.otpConfirmBox
? confirmOTPSection : OTPToggle
;
90 return '\t\t\t<section class="settings-otp">' +
91 OTPContent(ctx
, htmlOptions
) +
96 module
.exports
= (ctx
, options
) => {
98 pageTitle: options
.manager
.pageTitle
,
99 logoUrl: options
.manager
.logoUrl
,
100 footerEntries: options
.manager
.footerEntries
,
102 const mainContent
= [
103 OTPSection(ctx
, htmlOptions
),
104 updatePasswordSection(ctx
, htmlOptions
),
107 return th
.htmlPage(1, ctx
, htmlOptions
, mainContent
);