bump package version to 1.5.0
[squeep-authentication-module] / lib / template / otp-html.js
index cf7cef686ba7582fe659e36831b69a3e3b70a4ae..5777d3981219ad1ba851e7001f98b8b3b3bfe4ae 100644 (file)
@@ -1,54 +1,79 @@
 'use strict';
 
 const { TemplateHelper: th } = require('@squeep/html-template-helper');
+const { sessionNavLinks } = require('./helpers');
+
+/**
+ * @typedef {object} Context
+ * @property {string[]=} otpBlurb content accompanying otp entry
+ * @property {string} otpState packed otp state
+ */
+
+/**
+ * @alias {object} HtmlOptions
+ */
+
+/**
+ * @typedef {import('../session-manager').AppTemplateCallback} AppTemplateCallback
+ */
+
 
 /**
  * Login form, continued.
  */
 
+/**
+ *
+ * @param {Context} ctx context
+ * @param {HtmlOptions} options htmlOptions
+ * @returns {string} section
+ */
 function otpSection(ctx, options) {
   const otpBlurb = (options.otpBlurb || []).map((x) => '\t'.repeat(6) + x).join('\n');
   return `\t\t\t<section class="otp">
-\t\t\t\t<form action="" method="POST">
+\t\t\t\t<form method="POST">
 \t\t\t\t\t<fieldset>
 \t\t\t\t\t\t<legend>Two-Factor Authentication</legend>
 \t\t\t\t\t\t<label for="otp">OTP Code</label>
-\t\t\t\t\t\t<input id="otp" name="otp" value="">
+\t\t\t\t\t\t<input type="tel" id="otp" name="otp" value="">
 \t\t\t\t\t\t<br>
-\t\t\t\t\t\t<button>Confirm</button>
+\t\t\t\t\t\t<button type="submit">Confirm</button>
 ${otpBlurb}
 \t\t\t\t\t</fieldset>
 \t\t\t\t\t<input type="hidden" name="state" value="${ctx.otpState}">
 \t\t\t\t</form>
-\t\t\t</section`;
+\t\t\t</section>`;
 }
 
 
 /**
  * Render 2fs form.
- * @param {Object} ctx
- * @param {String[]=} ctx.errors
- * @param {String} ctx.otpState
- * @param {Object} options
- * @param {String[]=} options.authenticator.otpBlurb
- * @param {String[]=} options.authenticator.loginBlurb
- * @param {Object} options.manager
- * @param {String} options.manager.pageTitle
- * @param {String=} options.manager.logoUrl
- * @param {Object} options.dingus
- * @param {String} options.dingus.selfBaseUrl
- * @returns {String}
+ * @param {Context} ctx context
+ * @param {object} options options
+ * @param {string[]=} options.authenticator.otpBlurb content accompanying otp entry
+ * @param {object} options.manager manager options
+ * @param {string} options.manager.pageTitle page title
+ * @param {string=} options.manager.logoUrl logo url
+ * @param {string=} options.manager.logoAlt logo alt text
+ * @param {object} options.dingus dingus options
+ * @param {string} options.dingus.selfBaseUrl root url
+ * @param {AppTemplateCallback} appCb function to mogrify htmlOptions
+ * @returns {string} page
  */
-module.exports = (ctx, options) => {
+module.exports = (ctx, options, appCb = () => {}) => {
+  const pagePathLevel = 1;
   const htmlOptions = {
+    pageIdentifier: 'otp',
     pageTitle: options.manager.pageTitle,
     logoUrl: options.manager.logoUrl,
     footerEntries: options.manager.footerEntries,
     otpBlurb: options.authenticator?.otpBlurb,
   };
+  appCb(pagePathLevel, ctx, htmlOptions);
+  sessionNavLinks(pagePathLevel, ctx, htmlOptions);
   const mainContent = [
     ...(options.authenticator?.loginBlurb || []),
     otpSection(ctx, htmlOptions),
   ];
-  return th.htmlPage(2, ctx, htmlOptions, mainContent);
+  return th.htmlPage(pagePathLevel, ctx, htmlOptions, mainContent);
 };
\ No newline at end of file