forked from tsai/budibase
12 changed files with 251 additions and 161 deletions
@ -0,0 +1,82 @@ |
|||||
|
<!doctype html> |
||||
|
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"> |
||||
|
<head> |
||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1"> |
||||
|
<head> |
||||
|
<meta charset="utf-8"> |
||||
|
<meta name="viewport" content="width=device-width"> |
||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
|
<meta name="x-apple-disable-message-reformatting"> |
||||
|
<style> |
||||
|
{{ styles }} |
||||
|
</style> |
||||
|
</head> |
||||
|
<body> |
||||
|
<table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%" style="margin: auto;"> |
||||
|
<tbody> |
||||
|
<tr> |
||||
|
<td class="bg_white logo" style="padding: 1em 2.5em; text-align: center"> |
||||
|
<h1><a href="{{ companyUrl }}">{{ company }}</a></h1> |
||||
|
</td> |
||||
|
</tr> |
||||
|
<tr> |
||||
|
<td class="bg_white logo" style="padding: 1em 2.5em; text-align: center"> |
||||
|
{{ body }} |
||||
|
</td> |
||||
|
</tr> |
||||
|
<tr> |
||||
|
<td class="bg_white logo" style="padding: 1em 2.5em; text-align: center"> |
||||
|
<table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%" style="margin: auto;"> |
||||
|
<tbody><tr> |
||||
|
<td valign="middle" class="bg_black footer email-section"> |
||||
|
<table> |
||||
|
<tbody><tr> |
||||
|
<td valign="top" width="50%" style="padding-top: 20px;"> |
||||
|
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%"> |
||||
|
<tbody><tr> |
||||
|
<td style="text-align: left; padding-right: 10px;"> |
||||
|
<h3 class="heading">{{ company }}</h3> |
||||
|
<p>Company information.</p> |
||||
|
</td> |
||||
|
</tr> |
||||
|
</tbody></table> |
||||
|
</td> |
||||
|
<td valign="top" width="50%" style="padding-top: 20px;"> |
||||
|
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%"> |
||||
|
<tbody><tr> |
||||
|
<td style="text-align: left; padding-left: 10px;"> |
||||
|
<h3 class="heading"><a href="{{ url }}">Budibase Platform</a></h3> |
||||
|
</td> |
||||
|
</tr> |
||||
|
</tbody></table> |
||||
|
</td> |
||||
|
</tr> |
||||
|
</tbody></table> |
||||
|
</td> |
||||
|
</tr> |
||||
|
<tr> |
||||
|
<td valign="middle" class="bg_black footer email-section"> |
||||
|
<table> |
||||
|
<tbody><tr> |
||||
|
<td valign="top" width="50%"> |
||||
|
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%"> |
||||
|
<tbody><tr> |
||||
|
<td style="text-align: left; padding-right: 10px;"> |
||||
|
<p>© 2021 Restobar. All Rights Reserved</p> |
||||
|
</td> |
||||
|
</tr> |
||||
|
</tbody></table> |
||||
|
</td> |
||||
|
</tr> |
||||
|
</tbody></table> |
||||
|
</td> |
||||
|
</tr> |
||||
|
</tbody> |
||||
|
</table> |
||||
|
</td> |
||||
|
</tr> |
||||
|
</tbody> |
||||
|
</table> |
||||
|
</body> |
||||
@ -1,48 +0,0 @@ |
|||||
<table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%" style="margin: auto;"> |
|
||||
<tbody><tr> |
|
||||
<td valign="middle" class="bg_black footer email-section"> |
|
||||
<table> |
|
||||
<tbody><tr> |
|
||||
<td valign="top" width="50%" style="padding-top: 20px;"> |
|
||||
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%"> |
|
||||
<tbody><tr> |
|
||||
<td style="text-align: left; padding-right: 10px;"> |
|
||||
<h3 class="heading">{{ company }}</h3> |
|
||||
<p>Company information.</p> |
|
||||
</td> |
|
||||
</tr> |
|
||||
</tbody></table> |
|
||||
</td> |
|
||||
<td valign="top" width="50%" style="padding-top: 20px;"> |
|
||||
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%"> |
|
||||
<tbody><tr> |
|
||||
<td style="text-align: left; padding-left: 10px;"> |
|
||||
<h3 class="heading">Budibase Portal</h3> |
|
||||
{{ portalUrl }} |
|
||||
</td> |
|
||||
</tr> |
|
||||
</tbody></table> |
|
||||
</td> |
|
||||
</tr> |
|
||||
</tbody></table> |
|
||||
</td> |
|
||||
</tr> |
|
||||
<tr> |
|
||||
<td valign="middle" class="bg_black footer email-section"> |
|
||||
<table> |
|
||||
<tbody><tr> |
|
||||
<td valign="top" width="50%"> |
|
||||
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%"> |
|
||||
<tbody><tr> |
|
||||
<td style="text-align: left; padding-right: 10px;"> |
|
||||
<p>© 2021 Restobar. All Rights Reserved</p> |
|
||||
</td> |
|
||||
</tr> |
|
||||
</tbody></table> |
|
||||
</td> |
|
||||
</tr> |
|
||||
</tbody></table> |
|
||||
</td> |
|
||||
</tr> |
|
||||
</tbody> |
|
||||
</table> |
|
||||
@ -1,36 +0,0 @@ |
|||||
<!doctype html> |
|
||||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"> |
|
||||
<head> |
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"> |
|
||||
<head> |
|
||||
<meta charset="utf-8"> |
|
||||
<meta name="viewport" content="width=device-width"> |
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|
||||
<meta name="x-apple-disable-message-reformatting"> |
|
||||
<style> |
|
||||
{{ styles }} |
|
||||
</style> |
|
||||
</head> |
|
||||
<body> |
|
||||
<table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%" style="margin: auto;"> |
|
||||
<tbody> |
|
||||
<tr> |
|
||||
<td class="bg_white logo" style="padding: 1em 2.5em; text-align: center"> |
|
||||
<h1><a href="{{ companyUrl }}">{{ company }}</a></h1> |
|
||||
</td> |
|
||||
</tr> |
|
||||
<tr> |
|
||||
<td class="bg_white logo" style="padding: 1em 2.5em; text-align: center"> |
|
||||
{{ body }} |
|
||||
</td> |
|
||||
</tr> |
|
||||
<tr> |
|
||||
<td class="bg_white logo" style="padding: 1em 2.5em; text-align: center"> |
|
||||
{{ footer }} |
|
||||
</td> |
|
||||
</tr> |
|
||||
</tbody> |
|
||||
</table> |
|
||||
</body> |
|
||||
@ -0,0 +1,36 @@ |
|||||
|
const { EmailTemplatePurpose, TemplateTypes } = require("../constants") |
||||
|
const { getTemplateByPurpose } = require("../constants/templates") |
||||
|
const { processString } = require("@budibase/string-templates") |
||||
|
const { getSettingsTemplateContext } = require("./templates") |
||||
|
|
||||
|
const TYPE = TemplateTypes.EMAIL |
||||
|
|
||||
|
const FULL_EMAIL_PURPOSES = [EmailTemplatePurpose.INVITATION, EmailTemplatePurpose.PASSWORD_RECOVERY] |
||||
|
|
||||
|
exports.buildEmail = async (email, user, purpose) => { |
||||
|
// this isn't a full email
|
||||
|
if (FULL_EMAIL_PURPOSES.indexOf(purpose) === -1) { |
||||
|
throw `Unable to build an email of type ${purpose}` |
||||
|
} |
||||
|
let [base, styles, body] = await Promise.all([ |
||||
|
getTemplateByPurpose(TYPE, EmailTemplatePurpose.BASE), |
||||
|
getTemplateByPurpose(TYPE, EmailTemplatePurpose.STYLES), |
||||
|
getTemplateByPurpose(TYPE, purpose), |
||||
|
]) |
||||
|
|
||||
|
// TODO: need to extend the context as much as possible
|
||||
|
const context = { |
||||
|
...await getSettingsTemplateContext(), |
||||
|
email, |
||||
|
user |
||||
|
} |
||||
|
|
||||
|
body = await processString(body, context) |
||||
|
styles = await processString(styles, context) |
||||
|
// this should now be the complete email HTML
|
||||
|
return processString(base, { |
||||
|
...context, |
||||
|
styles, |
||||
|
body, |
||||
|
}) |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
/** |
||||
|
* Makes sure that a URL has the correct number of slashes, while maintaining the |
||||
|
* http(s):// double slashes.
|
||||
|
* @param {string} url The URL to test and remove any extra double slashes. |
||||
|
* @return {string} The updated url. |
||||
|
*/ |
||||
|
exports.checkSlashesInUrl = url => { |
||||
|
return url.replace(/(https?:\/\/)|(\/)+/g, "$1$2") |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
const CouchDB = require("../../../db") |
||||
|
const { getConfigParams, StaticDatabases } = require("@budibase/auth").db |
||||
|
const { Configs, TemplateBindings, LOGO_URL } = require("../constants") |
||||
|
const { checkSlashesInUrl } = require("./index") |
||||
|
const env = require("../environment") |
||||
|
|
||||
|
const LOCAL_URL = `http://localhost:${env.PORT}` |
||||
|
const BASE_COMPANY = "Budibase" |
||||
|
|
||||
|
exports.getSettingsTemplateContext = async () => { |
||||
|
const db = new CouchDB(StaticDatabases.GLOBAL.name) |
||||
|
const response = await db.allDocs( |
||||
|
getConfigParams(Configs.SETTINGS, { |
||||
|
include_docs: true, |
||||
|
}) |
||||
|
) |
||||
|
let settings = response.rows.map(row => row.doc)[0] || {} |
||||
|
if (!settings.url) { |
||||
|
settings.url = LOCAL_URL |
||||
|
} |
||||
|
// TODO: need to fully spec out the context
|
||||
|
return { |
||||
|
[TemplateBindings.LOGO_URL]: settings.logoUrl || LOGO_URL, |
||||
|
[TemplateBindings.URL]: settings.url, |
||||
|
[TemplateBindings.REGISTRATION_URL]: checkSlashesInUrl(`${settings.url}/registration`), |
||||
|
[TemplateBindings.RESET_URL]: checkSlashesInUrl(`${settings.url}/reset`), |
||||
|
[TemplateBindings.COMPANY]: settings.company || BASE_COMPANY, |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue