X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Ftemplate%2Flogin-html.js;fp=lib%2Ftemplate%2Flogin-html.js;h=7d059e0d505caf4d4fb503f554dcd91d9d05ccc3;hb=dd173e6b450cbba8100883514610c9fde83d050a;hp=0000000000000000000000000000000000000000;hpb=7442dd9aef45fe74dc7abe4d111c734068ef2f7d;p=squeep-authentication-module diff --git a/lib/template/login-html.js b/lib/template/login-html.js new file mode 100644 index 0000000..7d059e0 --- /dev/null +++ b/lib/template/login-html.js @@ -0,0 +1,85 @@ +'use strict'; + +const { TemplateHelper: th } = require('@squeep/html-template-helper'); + +/** + * Login form. + */ +function indieAuthSection(ctx, options) { + const indieAuthBlurb = (options.indieAuthBlurb || []).map((x) => '\t'.repeat(6) + x).join('\n'); + const showIndieAuthForm = options.authnEnabled.includes('indieAuth'); + return showIndieAuthForm ? `\t\t\t
+\t\t\t\t

Login

+\t\t\t\t
+\t\t\t\t\t
+\t\t\t\t\t\tIndieAuth +\t\t\t\t\t\t +\t\t\t\t\t\t +\t\t\t\t\t\t +${indieAuthBlurb} +\t\t\t\t\t
+\t\t\t\t
+\t\t\t
` + : ''; +} + + +const userAuthn = ['argon2', 'pam', 'DEBUG_ANY']; +function userSection(ctx, options) { + const userBlurb = (options.userBlurb || []).map((x) => '\t'.repeat(6) + x).join('\n'); + const secure = (ctx.clientProtocol || '').toLowerCase() === 'https'; + const showUserForm = options.authnEnabled.filter((x) => userAuthn.includes(x)).length + && (secure || !options.secureAuthOnly); + return showUserForm ? `\t\t\t
+\t\t\t\t
+\t\t\t\t\t
+\t\t\t\t\t\tUser Account +\t\t\t\t\t\t +\t\t\t\t\t\t +\t\t\t\t\t\t
+\t\t\t\t\t\t +\t\t\t\t\t\t +\t\t\t\t\t\t
+\t\t\t\t\t\t +${userBlurb} +\t\t\t\t\t
+\t\t\t\t
+\t\t\t
` + : ''; +} + + +/** + * Render login form for both local and profile authentication. + * @param {Object} ctx + * @param {String[]=} ctx.errors + * @param {String} ctx.clientProtocol + * @param {Object} options + * @param {Boolean} options.authenticator.secureAuthOnly + * @param {String[]=} options.authenticator.loginBlurb + * @param {String[]=} options.authenticator.indieAuthBlurb + * @param {String[]=} options.authenticator.userBlurb + * @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} + */ +module.exports = (ctx, options) => { + const htmlOptions = { + pageTitle: options.manager.pageTitle, + logoUrl: options.manager.logoUrl, + footerEntries: options.manager.footerEntries, + secureAuthOnly: options.authenticator.secureAuthOnly, + authnEnabled: options.authenticator.authnEnabled, + indieAuthBlurb: options.authenticator.indieAuthBlurb, + userBlurb: options.authenticator.userBlurb, + }; + const mainContent = [ + ...(options.authenticator.loginBlurb || []), + indieAuthSection(ctx, htmlOptions), + userSection(ctx, htmlOptions), + ]; + return th.htmlPage(2, ctx, htmlOptions, mainContent); +}; \ No newline at end of file