/* eslint-disable no-unused-vars */
const { TemplateHelper: th } = require('@squeep/html-template-helper');
+const { sessionNavLinks } = require('./helpers');
const { TOTP } = require('@squeep/totp');
+/**
+ * @typedef {object} Context
+ * @property {string=} otpConfirmBox encrypted otp state
+ * @property {string=} otpConfirmKey otp key to confirm adding to identifier
+ * @property {string=} authenticationId identifier
+ */
+
+/**
+ * @alias {object} HtmlOptions
+ */
+
+/**
+ * @typedef {import('../session-manager').AppTemplateCallback} AppTemplateCallback
+ */
+
+/**
+ * Render password update section.
+ * @param {Context} ctx context
+ * @param {HtmlOptions} htmlOptions options
+ * @returns {string} section
+ */
function updatePasswordSection(ctx, htmlOptions) {
return `\t\t\t<section class="settings-update-password">
\t\t\t\t<h2>Password</h2>
}
+/**
+ *
+ * @param {Context} ctx context
+ * @param {HtmlOptions} htmlOptions options
+ * @returns {string} otp enable section
+ */
function enableOTPSection(ctx, htmlOptions) {
return `\t\t\t<section class="settings-otp">
\t\t\t\t<h2>OTP 2FA</h2>
}
+/**
+ *
+ * @param {Context} ctx context
+ * @param {htmlOptions} htmlOptions options
+ * @returns {string} otp confirm section
+ */
function confirmOTPSection(ctx, htmlOptions) {
const { secret, svg, uri } = TOTP.createKeySVG({
accountname: ctx.authenticationId,
}
+/**
+ *
+ * @param {Context} ctx context
+ * @param {HtmlOptions} htmlOptions options
+ * @returns {string} disable otp section
+ */
function disableOTPSection(ctx, htmlOptions) {
return `\t\t\t<section class="settings-otp">
\t\t\t\t<h2>OTP 2FA</h2>
}
+/**
+ *
+ * @param {Context} ctx context
+ * @param {HtmlOptions} htmlOptions options
+ * @returns {string} otp section
+ */
function OTPSection(ctx, htmlOptions) {
const OTPToggle = ctx.otpKey ? disableOTPSection : enableOTPSection;
const OTPContent = ctx.otpConfirmBox ? confirmOTPSection : OTPToggle;
'\t\t\t</section>';
}
-
-module.exports = (ctx, options) => {
+/**
+ * Render settings form for managing credential and otp key.
+ * @param {Context} ctx context
+ * @param {object} options options
+ * @param {AppTemplateCallback} appCb function to mogrify htmlOptions
+ * @returns {string} page
+ */
+module.exports = (ctx, options, appCb = () => {}) => {
+ const pagePathLevel = 1;
const htmlOptions = {
+ pageIdentifier: 'account',
pageTitle: options.manager.pageTitle,
logoUrl: options.manager.logoUrl,
footerEntries: options.manager.footerEntries,
};
+ appCb(pagePathLevel, ctx, htmlOptions);
+ sessionNavLinks(pagePathLevel, ctx, htmlOptions);
const mainContent = [
OTPSection(ctx, htmlOptions),
updatePasswordSection(ctx, htmlOptions),
];
- return th.htmlPage(1, ctx, htmlOptions, mainContent);
+ return th.htmlPage(pagePathLevel, ctx, htmlOptions, mainContent);
};