3 const { TemplateHelper: th
} = require('@squeep/html-template-helper');
4 const { sessionNavLinks
} = require('./helpers');
7 * @typedef {object} Context
8 * @property {string[]=} otpBlurb content accompanying otp entry
9 * @property {string} otpState packed otp state
13 * @alias {object} HtmlOptions
17 * @typedef {import('../session-manager').AppTemplateCallback} AppTemplateCallback
22 * Login form, continued.
27 * @param {Context} ctx context
28 * @param {HtmlOptions} options htmlOptions
29 * @returns {string} section
31 function otpSection(ctx
, options
) {
32 const otpBlurb
= (options
.otpBlurb
|| []).map((x
) => '\t'.repeat(6) + x
).join('\n');
33 return `\t\t\t<section class="otp">
34 \t\t\t\t<form method="POST">
36 \t\t\t\t\t\t<legend>Two-Factor Authentication</legend>
37 \t\t\t\t\t\t<label for="otp">OTP Code</label>
38 \t\t\t\t\t\t<input type="tel" id="otp" name="otp" value="">
40 \t\t\t\t\t\t<button type="submit">Confirm</button>
43 \t\t\t\t\t<input type="hidden" name="state" value="${ctx.otpState}">
51 * @param {Context} ctx context
52 * @param {object} options options
53 * @param {string[]=} options.authenticator.otpBlurb content accompanying otp entry
54 * @param {object} options.manager manager options
55 * @param {string} options.manager.pageTitle page title
56 * @param {string=} options.manager.logoUrl logo url
57 * @param {string=} options.manager.logoAlt logo alt text
58 * @param {object} options.dingus dingus options
59 * @param {string} options.dingus.selfBaseUrl root url
60 * @param {AppTemplateCallback} appCb function to mogrify htmlOptions
61 * @returns {string} page
63 module
.exports
= (ctx
, options
, appCb
= () => {}) => {
64 const pagePathLevel
= 1;
66 pageIdentifier: 'otp',
67 pageTitle: options
.manager
.pageTitle
,
68 logoUrl: options
.manager
.logoUrl
,
69 footerEntries: options
.manager
.footerEntries
,
70 otpBlurb: options
.authenticator
?.otpBlurb
,
72 appCb(pagePathLevel
, ctx
, htmlOptions
);
73 sessionNavLinks(pagePathLevel
, ctx
, htmlOptions
);
75 ...(options
.authenticator
?.loginBlurb
|| []),
76 otpSection(ctx
, htmlOptions
),
78 return th
.htmlPage(pagePathLevel
, ctx
, htmlOptions
, mainContent
);