3 /* eslint-disable no-unused-vars */
5 const { TemplateHelper: th
} = require('@squeep/html-template-helper');
6 const { sessionNavLinks
} = require('./helpers');
7 const { TOTP
} = require('@squeep/totp');
9 function updatePasswordSection(ctx
, htmlOptions
) {
10 return `\t\t\t<section class="settings-update-password">
11 \t\t\t\t<h2>Password</h2>
12 \t\t\t\t<form method="POST">
14 \t\t\t\t\t\t<legend>Update Password</legend>
15 \t\t\t\t\t\t<label for="credential-current">Current Password:</label>
16 \t\t\t\t\t\t<input type="password" id="credential-current" name="credential-current" value="">
18 \t\t\t\t\t\t<label for="credential-new">New Password:</label>
19 \t\t\t\t\t\t<input type="password" id="credential-new" name="credential-new" value="">
21 \t\t\t\t\t\t<label for="credential-new-2">Confirm New Password:</label>
22 \t\t\t\t\t\t<input type="password" id="credential-new-2" name="credential-new-2" value="">
24 \t\t\t\t\t\t<button type="submit" name="credential" value="update">Update</button>
31 function enableOTPSection(ctx
, htmlOptions
) {
32 return `\t\t\t<section class="settings-otp">
33 \t\t\t\t<h2>OTP 2FA</h2>
34 \t\t\t\t<form method="POST">
36 \t\t\t\t\t\t<legend>Enable OTP</legend>
37 \t\t\t\t\t\t<button type="submit" name="otp" value="enable">Enable OTP</button>
44 function confirmOTPSection(ctx
, htmlOptions
) {
45 const { secret
, svg
, uri
} = TOTP
.createKeySVG({
46 accountname: ctx
.authenticationId
,
47 }, ctx
.otpConfirmKey
, 'base32');
48 return `\t\t\t<section class="settings-otp">
49 \t\t\t\t<h2>OTP 2FA</h2>
50 \t\t\t\t<form method="POST">
52 \t\t\t\t\t<legend>Confirm OTP Key</legend>
54 \t\t\t\t\t\t\t<details>
55 \t\t\t\t\t\t\t\t<summary>Show Key</summary>
56 \t\t\t\t\t\t\t\tOTP Key (base32): <code>${secret}</code>
58 \t\t\t\t\t\t\t\t\tURI: <code>${uri}</code>
59 \t\t\t\t\t\t\t\t</div>
60 \t\t\t\t\t\t\t</details>
62 \t\t\t\t\t\t<div class="otp-key-qr">
66 \t\t\t\t\t\t<label for="otp-token">Enter OTP token to enable:</label>
67 \t\t\t\t\t\t<input id="otp-token" name="otp-token" type="text" value="">
69 \t\t\t\t\t\t<input type="hidden" name="otp-box" value="${ctx.otpConfirmBox}">
70 \t\t\t\t\t\t<button type="submit" name="otp" value="confirm">Confirm OTP</button>
77 function disableOTPSection(ctx
, htmlOptions
) {
78 return `\t\t\t<section class="settings-otp">
79 \t\t\t\t<h2>OTP 2FA</h2>
80 \t\t\t\t<p>OTP is currrently enabled. It may be removed here.</p>
81 \t\t\t\t<form method="POST">
82 \t\t\t\t\t<button type="submit" name="otp" value="disable">Disable OTP</button>
88 function OTPSection(ctx
, htmlOptions
) {
89 const OTPToggle
= ctx
.otpKey
? disableOTPSection : enableOTPSection
;
90 const OTPContent
= ctx
.otpConfirmBox
? confirmOTPSection : OTPToggle
;
91 return '\t\t\t<section class="settings-otp">' +
92 OTPContent(ctx
, htmlOptions
) +
97 module
.exports
= (ctx
, options
, appCb
= () => {}) => {
98 const pagePathLevel
= 1;
100 pageIdentifier: 'account',
101 pageTitle: options
.manager
.pageTitle
,
102 logoUrl: options
.manager
.logoUrl
,
103 footerEntries: options
.manager
.footerEntries
,
105 appCb(pagePathLevel
, ctx
, htmlOptions
);
106 sessionNavLinks(pagePathLevel
, ctx
, htmlOptions
);
107 const mainContent
= [
108 OTPSection(ctx
, htmlOptions
),
109 updatePasswordSection(ctx
, htmlOptions
),
112 return th
.htmlPage(pagePathLevel
, ctx
, htmlOptions
, mainContent
);