nunjucks wtv-register
This commit is contained in:
@@ -0,0 +1,30 @@
|
|||||||
|
const nunjucks = require('nunjucks');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
class WTVRegisterTemplate {
|
||||||
|
page_args = {};
|
||||||
|
|
||||||
|
constructor(page_args) {
|
||||||
|
this.page_args = page_args;
|
||||||
|
}
|
||||||
|
|
||||||
|
getTemplatePage() {
|
||||||
|
// Configure nunjucks with the templates directory
|
||||||
|
const templatesPath = path.join(__dirname, '../templates');
|
||||||
|
const env = nunjucks.configure(templatesPath, {
|
||||||
|
autoescape: false, // Disabled to allow HTML content in main_content and form_buttons
|
||||||
|
throwOnUndefined: false
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Render the template with the provided arguments
|
||||||
|
const rendered = env.render(this.page_args.template_name, this.page_args);
|
||||||
|
return rendered;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error rendering Nunjucks template:', error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = WTVRegisterTemplate;
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>
|
||||||
|
{{ title }}
|
||||||
|
</title>
|
||||||
|
<display nooptions noscroll NoScroll>
|
||||||
|
</head>
|
||||||
|
<body noscroll
|
||||||
|
bgcolor="#171726" text="#D1D3D3" link=#FFEA9C vlink=#FFEA9C
|
||||||
|
hspace=0 vspace=0 fontsize="large"
|
||||||
|
>
|
||||||
|
<table cellspacing=0 cellpadding=0 border=0 width=560 bgcolor=#171726>
|
||||||
|
<tr>
|
||||||
|
<td align=middle bgcolor="#5b6c81" border=0 colspan= 3 width="100" height="80">
|
||||||
|
<img src="{{ service_logo }}" WIDTH="87" HEIGHT="67">
|
||||||
|
<td colspan= 6 bgcolor="#5b6c81" border=0 width=100% absheight="80" valign=bottom >
|
||||||
|
<img src="images/head_registration.gif" >
|
||||||
|
<tr>
|
||||||
|
<td bgcolor="#5b6c81" border=0 rowspan=2 width=21 height= 220></td>
|
||||||
|
<td bgcolor="#171726" border=0 width=9 height=25 align=left valign=top>
|
||||||
|
<img src="images/L_corner.gif" width=8 height=8>
|
||||||
|
<td bgcolor="#171726" border=1 colspan=1 width=70 height=25>
|
||||||
|
<td colspan=6 bgcolor="#171726" border=1 height=25 align=left valign=bottom gradcolor=#262E3D gradangle=90>
|
||||||
|
<font color=#d1d3d3 size=+1>
|
||||||
|
<blackface>
|
||||||
|
{{ title }}
|
||||||
|
</blackface></font>
|
||||||
|
<tr> <td border=0 width=40 bgcolor="#171726" rowspan="2" >
|
||||||
|
<td absheight=20 width=100 bgcolor="#171726" colspan=6>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<table cellspacing=0 cellpadding=0 border=0 width=560 bgcolor=#171726>
|
||||||
|
<tr>
|
||||||
|
<td bgcolor= "#5b6c81" border=0 rowspan=6 abswidth=21 height= 220></td>
|
||||||
|
<td border=0 abswidth=40 bgcolor="#171726" rowspan="6" >
|
||||||
|
<td height=230 width= 300 bgcolor="#171726" colspan=5 valign=top align=left>
|
||||||
|
{{ main_content | safe }}
|
||||||
|
<td abswidth=20 bgcolor=#171726 >
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td valign= bottom height=15 colspan=7 bgcolor=#171726>
|
||||||
|
<shadow>
|
||||||
|
<hr size=5 valign=bottom></shadow>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td border=2 colspan=4 width=100 height=50 bgcolor=#171726 valign=top align=left>
|
||||||
|
<font size=-1><i>
|
||||||
|
</i></font>
|
||||||
|
<td bgcolor=#171726 height=50 width=560 valign=top align=right>
|
||||||
|
<font size=-1 color=#e7ce4a>
|
||||||
|
{{ form_buttons | safe }}
|
||||||
|
<td abswidth=13 absheight=50 bgcolor=#171726>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>
|
||||||
|
{{ title }}
|
||||||
|
</title>
|
||||||
|
<display nooptions>
|
||||||
|
</head>
|
||||||
|
<body bgcolor=#191919 text=#42CC55 fontsize=large hspace=0 vspace=0>
|
||||||
|
<table cellspacing=0 cellpadding=0>
|
||||||
|
<tr>
|
||||||
|
<td width=104 height=74 valign=middle align=center bgcolor=#3B3A4D>
|
||||||
|
<img src="{{ service_logo }}" width=86 height=64>
|
||||||
|
<td width=20 valign=top align=left bgcolor=#3B3A4D>
|
||||||
|
<spacer>
|
||||||
|
<td colspan=2 width=100% align=left bgcolor=#3B3A4D>
|
||||||
|
<font color=D6DFD0 size=+2>
|
||||||
|
<blackface>
|
||||||
|
<shadow>
|
||||||
|
<spacer type=block width=1 height=4>
|
||||||
|
<br>
|
||||||
|
{{ title }}
|
||||||
|
</shadow>
|
||||||
|
</blackface>
|
||||||
|
</font>
|
||||||
|
</tr>
|
||||||
|
</td>
|
||||||
|
</table>
|
||||||
|
<table width=520 align=center cellspacing=0 cellpadding=0>
|
||||||
|
<tr>
|
||||||
|
<td height=242>
|
||||||
|
<font size=+1>
|
||||||
|
{{ main_content | safe }}
|
||||||
|
<p>
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<hr>
|
||||||
|
<p>
|
||||||
|
<table align=right cellspacing=0 cellpadding=0>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<spacer type=block height=10>
|
||||||
|
{{ form_buttons | safe }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -5,11 +5,14 @@ class WTVRegister {
|
|||||||
minisrv_config = [];
|
minisrv_config = [];
|
||||||
service_owner = "a minisrv user";
|
service_owner = "a minisrv user";
|
||||||
session_store_dir = null;
|
session_store_dir = null;
|
||||||
|
wtvshared = null;
|
||||||
|
|
||||||
constructor(minisrv_config, session_store_dir = null) {
|
constructor(minisrv_config, session_store_dir = null) {
|
||||||
this.minisrv_config = minisrv_config;
|
this.minisrv_config = minisrv_config;
|
||||||
this.service_owner = minisrv_config.config.service_owner || "a minisrv user";
|
this.service_owner = minisrv_config.config.service_owner || "a minisrv user";
|
||||||
this.session_store_dir = session_store_dir || this.minisrv_config.config.SessionStore;
|
this.session_store_dir = session_store_dir || this.minisrv_config.config.SessionStore;
|
||||||
|
const WTVShared = require("./WTVShared.js")['WTVShared'];
|
||||||
|
this.wtvshared = new WTVShared(minisrv_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
getServiceOperator(first_letter_lower = false) {
|
getServiceOperator(first_letter_lower = false) {
|
||||||
@@ -108,7 +111,7 @@ class WTVRegister {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generations regnstration template
|
* Generates registration template using Nunjucks
|
||||||
* @param {string} title HTML Page Title
|
* @param {string} title HTML Page Title
|
||||||
* @param {string} main_content Main center content
|
* @param {string} main_content Main center content
|
||||||
* @param {string} form_buttons Form and buttons
|
* @param {string} form_buttons Form and buttons
|
||||||
@@ -116,120 +119,33 @@ class WTVRegister {
|
|||||||
* @returns {string} HTML Page
|
* @returns {string} HTML Page
|
||||||
*/
|
*/
|
||||||
getHTMLTemplate(title, main_content, form_buttons, is_old_build) {
|
getHTMLTemplate(title, main_content, form_buttons, is_old_build) {
|
||||||
var data;
|
try {
|
||||||
if (is_old_build) {
|
var template = this.wtvshared.getTemplate("wtv-register", "templates/NunjucksTemplate.js", true);
|
||||||
data = `<html>
|
if (this.fs.existsSync(template)) {
|
||||||
<head>
|
const WTVRegisterTemplate = require(template);
|
||||||
<title>
|
|
||||||
${title}
|
// Determine which template to use based on build type
|
||||||
</title>
|
const template_name = is_old_build ? 'register_old_build.njk' : 'register_new_build.njk';
|
||||||
<display nooptions>
|
|
||||||
</head>
|
const template_args = {
|
||||||
<body bgcolor=#191919 text=#42CC55 fontsize=large hspace=0 vspace=0>
|
template_name: template_name,
|
||||||
<table cellspacing=0 cellpadding=0>
|
title: title,
|
||||||
<tr>
|
main_content: main_content,
|
||||||
<td width=104 height=74 valign=middle align=center bgcolor=#3B3A4D>
|
form_buttons: form_buttons,
|
||||||
<img src="${this.minisrv_config.config.service_logo}" width=86 height=64>
|
service_logo: this.minisrv_config.config.service_logo
|
||||||
<td width=20 valign=top align=left bgcolor=#3B3A4D>
|
};
|
||||||
<spacer>
|
|
||||||
<td colspan=2 width=100% align=left bgcolor=#3B3A4D>
|
const wtvt = new WTVRegisterTemplate(template_args);
|
||||||
<font color=D6DFD0 size=+2>
|
const data = wtvt.getTemplatePage();
|
||||||
<blackface>
|
|
||||||
<shadow>
|
if (data) {
|
||||||
<spacer type=block width=1 height=4>
|
return data;
|
||||||
<br>
|
}
|
||||||
${title}
|
}
|
||||||
</shadow>
|
} catch (error) {
|
||||||
</blackface>
|
console.error('Error using Nunjucks template for registration:', error);
|
||||||
</font>
|
|
||||||
</tr>
|
|
||||||
</td>
|
|
||||||
</table>
|
|
||||||
<table width=520 align=center cellspacing=0 cellpadding=0>
|
|
||||||
<tr>
|
|
||||||
<td height=242>
|
|
||||||
<font size=+1>
|
|
||||||
${main_content}
|
|
||||||
<p>
|
|
||||||
</font>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<hr>
|
|
||||||
<p>
|
|
||||||
<table align=right cellspacing=0 cellpadding=0>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<spacer type=block height=10>
|
|
||||||
${form_buttons}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
`;
|
|
||||||
} else {
|
|
||||||
data = `<html>
|
|
||||||
<head>
|
|
||||||
<title>
|
|
||||||
${title}
|
|
||||||
</title>
|
|
||||||
<display nooptions noscroll NoScroll>
|
|
||||||
</head>
|
|
||||||
<body noscroll
|
|
||||||
bgcolor="#171726" text="#D1D3D3" link=#FFEA9C vlink=#FFEA9C
|
|
||||||
hspace=0 vspace=0 fontsize="large"
|
|
||||||
>
|
|
||||||
<table cellspacing=0 cellpadding=0 border=0 width=560 bgcolor=#171726>
|
|
||||||
<tr>
|
|
||||||
<td align=middle bgcolor="#5b6c81" border=0 colspan= 3 width="100" height="80">
|
|
||||||
<img src="${this.minisrv_config.config.service_logo}" WIDTH="87" HEIGHT="67">
|
|
||||||
<td colspan= 6 bgcolor="#5b6c81" border=0 width=100% absheight="80" valign=bottom >
|
|
||||||
<img src="images/head_registration.gif" >
|
|
||||||
<tr>
|
|
||||||
<td bgcolor="#5b6c81" border=0 rowspan=2 width=21 height= 220></td>
|
|
||||||
<td bgcolor="#171726" border=0 width=9 height=25 align=left valign=top>
|
|
||||||
<img src="images/L_corner.gif" width=8 height=8>
|
|
||||||
<td bgcolor="#171726" border=1 colspan=1 width=70 height=25>
|
|
||||||
<td colspan=6 bgcolor="#171726" border=1 height=25 align=left valign=bottom gradcolor=#262E3D gradangle=90>
|
|
||||||
<font color=#d1d3d3 size=+1>
|
|
||||||
<blackface>
|
|
||||||
${title}
|
|
||||||
</blackface></font>
|
|
||||||
<tr> <td border=0 width=40 bgcolor="#171726" rowspan="2" >
|
|
||||||
<td absheight=20 width=100 bgcolor="#171726" colspan=6>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<table cellspacing=0 cellpadding=0 border=0 width=560 bgcolor=#171726>
|
|
||||||
<tr>
|
|
||||||
<td bgcolor= "#5b6c81" border=0 rowspan=6 abswidth=21 height= 220></td>
|
|
||||||
<td border=0 abswidth=40 bgcolor="#171726" rowspan="6" >
|
|
||||||
<td height=230 width= 300 bgcolor="#171726" colspan=5 valign=top align=left>
|
|
||||||
${main_content}
|
|
||||||
<td abswidth=20 bgcolor=#171726 >
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td valign= bottom height=15 colspan=7 bgcolor=#171726>
|
|
||||||
<shadow>
|
|
||||||
<hr size=5 valign=bottom></shadow>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td border=2 colspan=4 width=100 height=50 bgcolor=#171726 valign=top align=left>
|
|
||||||
<font size=-1><i>
|
|
||||||
</i></font>
|
|
||||||
<td bgcolor=#171726 height=50 width=560 valign=top align=right>
|
|
||||||
<font size=-1 color=#e7ce4a>
|
|
||||||
${form_buttons}
|
|
||||||
<td abswidth=13 absheight=50 bgcolor=#171726>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>`;
|
|
||||||
}
|
}
|
||||||
return data;
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user