X-Git-Url: https://git.squeep.com/?p=squeep-authentication-module;a=blobdiff_plain;f=lib%2Ftemplate%2Fsettings-html.js;fp=lib%2Ftemplate%2Fsettings-html.js;h=c5bb6c082909bd92274ca3242a76c33b3764e574;hp=0000000000000000000000000000000000000000;hb=53ef948ea83106e82d55e60d6695a15e94bf725e;hpb=842a3da269de1ab82e9a2a12aae8ed5677f064d8 diff --git a/lib/template/settings-html.js b/lib/template/settings-html.js new file mode 100644 index 0000000..c5bb6c0 --- /dev/null +++ b/lib/template/settings-html.js @@ -0,0 +1,108 @@ +'use strict'; + +/* eslint-disable no-unused-vars */ + +const { TemplateHelper: th } = require('@squeep/html-template-helper'); +const { TOTP } = require('@squeep/totp'); + +function updatePasswordSection(ctx, htmlOptions) { + return `\t\t\t
+\t\t\t\t

Password

+\t\t\t\t
+\t\t\t\t\t
+\t\t\t\t\t\tUpdate Password +\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 +\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
`; +} + + +function enableOTPSection(ctx, htmlOptions) { + return `\t\t\t
+\t\t\t\t

OTP 2FA

+\t\t\t\t
+\t\t\t\t\t
+\t\t\t\t\t\tEnable OTP +\t\t\t\t\t\t +\t\t\t\t\t
+\t\t\t\t
+\t\t\t
`; +} + + +function confirmOTPSection(ctx, htmlOptions) { + const { secret, svg, uri } = TOTP.createKeySVG({ + accountname: ctx.authenticationId, + }, ctx.otpConfirmKey, 'base32'); + return `\t\t\t
+\t\t\t\t

OTP 2FA

+\t\t\t\t
+\t\t\t\t\t
+\t\t\t\t\tConfirm OTP Key +\t\t\t\t\t\t
+\t\t\t\t\t\t\t
+\t\t\t\t\t\t\t\tShow Key +\t\t\t\t\t\t\t\tOTP Key (base32): ${secret} +\t\t\t\t\t\t\t\t
+\t\t\t\t\t\t\t\t\tURI: ${uri} +\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
+${svg} +\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 +\t\t\t\t\t
+\t\t\t\t
+\t\t\t
`; +} + + +function disableOTPSection(ctx, htmlOptions) { + return `\t\t\t
+\t\t\t\t

OTP 2FA

+\t\t\t\t

OTP is currrently enabled. It may be removed here.

+\t\t\t\t
+\t\t\t\t\t +\t\t\t\t
+\t\t\t
`; +} + + +function OTPSection(ctx, htmlOptions) { + const OTPToggle = ctx.otpKey ? disableOTPSection : enableOTPSection; + const OTPContent = ctx.otpConfirmBox ? confirmOTPSection : OTPToggle; + return '\t\t\t
' + + OTPContent(ctx, htmlOptions) + + '\t\t\t
'; +} + + +module.exports = (ctx, options) => { + const htmlOptions = { + pageTitle: options.manager.pageTitle, + logoUrl: options.manager.logoUrl, + footerEntries: options.manager.footerEntries, + }; + const mainContent = [ + OTPSection(ctx, htmlOptions), + updatePasswordSection(ctx, htmlOptions), + ]; + + return th.htmlPage(1, ctx, htmlOptions, mainContent); +};