X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Ftemplate%2Fsettings-html.js;h=aba75f921126dbb42682bd77adf5f43df2b976ed;hb=9c8e775e5ab96a1788f535760bfa72205c430d15;hp=42bfdcda4fedae3e6c12a25177cb87943f41bfbc;hpb=2c3ddf0a6f40b9d0a4e54fa12b84b8af33eaaadc;p=squeep-authentication-module diff --git a/lib/template/settings-html.js b/lib/template/settings-html.js index 42bfdcd..aba75f9 100644 --- a/lib/template/settings-html.js +++ b/lib/template/settings-html.js @@ -6,6 +6,27 @@ 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
\t\t\t\t

Password

@@ -28,6 +49,12 @@ function updatePasswordSection(ctx, htmlOptions) { } +/** + * + * @param {Context} ctx context + * @param {HtmlOptions} htmlOptions options + * @returns {string} otp enable section + */ function enableOTPSection(ctx, htmlOptions) { return `\t\t\t
\t\t\t\t

OTP 2FA

@@ -41,6 +68,12 @@ function enableOTPSection(ctx, htmlOptions) { } +/** + * + * @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, @@ -74,6 +107,12 @@ ${svg} } +/** + * + * @param {Context} ctx context + * @param {HtmlOptions} htmlOptions options + * @returns {string} disable otp section + */ function disableOTPSection(ctx, htmlOptions) { return `\t\t\t
\t\t\t\t

OTP 2FA

@@ -85,6 +124,12 @@ function disableOTPSection(ctx, htmlOptions) { } +/** + * + * @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; @@ -93,7 +138,13 @@ function OTPSection(ctx, htmlOptions) { '\t\t\t
'; } - +/** + * 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 = {