From 3561614f9683b3082cc7bb0a38a36d6c7b90201b Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Sun, 12 Jul 2020 11:46:21 +0200 Subject: [PATCH] Promote some views to wms-core --- package.json | 14 +-- src/components/NunjucksComponent.ts | 6 +- test/views/layouts/widget.njk | 18 --- {test/views => views}/errors/400.njk | 2 +- {test/views => views}/errors/401.njk | 2 +- {test/views => views}/errors/403.njk | 2 +- {test/views => views}/errors/404.njk | 2 +- {test/views => views}/errors/429.njk | 2 +- {test/views => views}/errors/500.njk | 2 +- {test/views => views}/errors/503.njk | 2 +- {test/views => views}/errors/error.njk | 2 +- {test/views => views}/layouts/barebone.njk | 0 {test/views => views}/macros.njk | 0 views/magic_link.njk | 19 ++++ views/magic_link_lobby.njk | 58 ++++++++++ views/mails/account_review_notice.mjml.njk | 41 +++++++ views/mails/base_layout.mjml.njk | 115 ++++++++++++++++++++ views/mails/magic_link.mjml.njk | 66 +++++++++++ views/mails/pending_account_review.mjml.njk | 66 +++++++++++ 19 files changed, 385 insertions(+), 34 deletions(-) delete mode 100644 test/views/layouts/widget.njk rename {test/views => views}/errors/400.njk (52%) rename {test/views => views}/errors/401.njk (52%) rename {test/views => views}/errors/403.njk (52%) rename {test/views => views}/errors/404.njk (52%) rename {test/views => views}/errors/429.njk (52%) rename {test/views => views}/errors/500.njk (52%) rename {test/views => views}/errors/503.njk (52%) rename {test/views => views}/errors/error.njk (96%) rename {test/views => views}/layouts/barebone.njk (100%) rename {test/views => views}/macros.njk (100%) create mode 100644 views/magic_link.njk create mode 100644 views/magic_link_lobby.njk create mode 100644 views/mails/account_review_notice.mjml.njk create mode 100644 views/mails/base_layout.mjml.njk create mode 100644 views/mails/magic_link.mjml.njk create mode 100644 views/mails/pending_account_review.mjml.njk diff --git a/package.json b/package.json index 0be42e1..66b3d5f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wms-core", - "version": "0.13.2", + "version": "0.13.7", "description": "Node web framework", "repository": "git@gitlab.com:ArisuOngaku/wms-core.git", "author": "Alice Gaudon ", @@ -13,7 +13,7 @@ "types": "dist/index.d.ts", "scripts": { "test": "jest --verbose --runInBand", - "build": "(test ! -d dist || rm -r dist) && tsc && cp package.json dist/ && cp yarn.lock dist/ && mkdir dist/types && cp src/types/* dist/types/ && mv dist/src/* dist/ && rm -r dist/src", + "build": "(test ! -d dist || rm -r dist) && tsc && cp package.json dist/ && cp yarn.lock dist/ && cp -r views dist/ && mkdir dist/types && cp src/types/* dist/types/ && mv dist/src/* dist/ && rm -r dist/src", "build_and_publish": "yarn test && yarn build && cd dist && yarn publish" }, "devDependencies": { @@ -23,19 +23,19 @@ "@types/connect-redis": "^0.0.14", "@types/cookie": "^0.4.0", "@types/cookie-parser": "^1.4.2", + "@types/express": "^4.17.6", + "@types/express-session": "^1.17.0", "@types/formidable": "^1.0.31", "@types/geoip-lite": "^1.1.31", "@types/jest": "^26.0.4", "@types/mjml": "^4.0.4", - "@types/node-fetch": "^2.5.7", - "@types/on-finished": "^2.3.1", - "@types/uuid": "^8.0.0", - "@types/express": "^4.17.6", - "@types/express-session": "^1.17.0", "@types/mysql": "^2.15.10", + "@types/node-fetch": "^2.5.7", "@types/nodemailer": "^6.4.0", "@types/nunjucks": "^3.1.3", + "@types/on-finished": "^2.3.1", "@types/redis": "^2.8.18", + "@types/uuid": "^8.0.0", "@types/ws": "^7.2.4", "jest": "^26.1.0", "maildev": "^1.1.0", diff --git a/src/components/NunjucksComponent.ts b/src/components/NunjucksComponent.ts index b887506..4029d55 100644 --- a/src/components/NunjucksComponent.ts +++ b/src/components/NunjucksComponent.ts @@ -25,7 +25,11 @@ export default class NunjucksComponent extends ApplicationComponent { } } - this.env = nunjucks.configure(this.viewsPath, { + this.env = nunjucks.configure([ + this.viewsPath, + 'views', + 'node_modules/wms-core/views' + ], { autoescape: true, express: app, noCache: !config.get('view.cache'), diff --git a/test/views/layouts/widget.njk b/test/views/layouts/widget.njk deleted file mode 100644 index 9f467fc..0000000 --- a/test/views/layouts/widget.njk +++ /dev/null @@ -1,18 +0,0 @@ -{% extends './barebone.njk' %} - -{% block _stylesheets %} - {{ super() }} - {% block stylesheets %}{% endblock %} -{% endblock %} -{% block _scripts %} - {{ super() }} - {% block scripts %}{% endblock %} -{% endblock %} - -{% block header %}{% endblock %} - -{% block _body %} - {% block body %}{% endblock %} -{% endblock %} - -{% block footer %}{% endblock %} \ No newline at end of file diff --git a/test/views/errors/400.njk b/views/errors/400.njk similarity index 52% rename from test/views/errors/400.njk rename to views/errors/400.njk index a5bc022..aa8e1f7 100644 --- a/test/views/errors/400.njk +++ b/views/errors/400.njk @@ -1,2 +1,2 @@ -{% extends './error.njk' %} +{% extends 'errors/error.njk' %} {% import 'macros.njk' as macros %} diff --git a/test/views/errors/401.njk b/views/errors/401.njk similarity index 52% rename from test/views/errors/401.njk rename to views/errors/401.njk index a5bc022..aa8e1f7 100644 --- a/test/views/errors/401.njk +++ b/views/errors/401.njk @@ -1,2 +1,2 @@ -{% extends './error.njk' %} +{% extends 'errors/error.njk' %} {% import 'macros.njk' as macros %} diff --git a/test/views/errors/403.njk b/views/errors/403.njk similarity index 52% rename from test/views/errors/403.njk rename to views/errors/403.njk index a5bc022..aa8e1f7 100644 --- a/test/views/errors/403.njk +++ b/views/errors/403.njk @@ -1,2 +1,2 @@ -{% extends './error.njk' %} +{% extends 'errors/error.njk' %} {% import 'macros.njk' as macros %} diff --git a/test/views/errors/404.njk b/views/errors/404.njk similarity index 52% rename from test/views/errors/404.njk rename to views/errors/404.njk index a5bc022..aa8e1f7 100644 --- a/test/views/errors/404.njk +++ b/views/errors/404.njk @@ -1,2 +1,2 @@ -{% extends './error.njk' %} +{% extends 'errors/error.njk' %} {% import 'macros.njk' as macros %} diff --git a/test/views/errors/429.njk b/views/errors/429.njk similarity index 52% rename from test/views/errors/429.njk rename to views/errors/429.njk index a5bc022..aa8e1f7 100644 --- a/test/views/errors/429.njk +++ b/views/errors/429.njk @@ -1,2 +1,2 @@ -{% extends './error.njk' %} +{% extends 'errors/error.njk' %} {% import 'macros.njk' as macros %} diff --git a/test/views/errors/500.njk b/views/errors/500.njk similarity index 52% rename from test/views/errors/500.njk rename to views/errors/500.njk index a5bc022..aa8e1f7 100644 --- a/test/views/errors/500.njk +++ b/views/errors/500.njk @@ -1,2 +1,2 @@ -{% extends './error.njk' %} +{% extends 'errors/error.njk' %} {% import 'macros.njk' as macros %} diff --git a/test/views/errors/503.njk b/views/errors/503.njk similarity index 52% rename from test/views/errors/503.njk rename to views/errors/503.njk index a5bc022..aa8e1f7 100644 --- a/test/views/errors/503.njk +++ b/views/errors/503.njk @@ -1,2 +1,2 @@ -{% extends './error.njk' %} +{% extends 'errors/error.njk' %} {% import 'macros.njk' as macros %} diff --git a/test/views/errors/error.njk b/views/errors/error.njk similarity index 96% rename from test/views/errors/error.njk rename to views/errors/error.njk index 3d05ea9..fa0d99f 100644 --- a/test/views/errors/error.njk +++ b/views/errors/error.njk @@ -1,4 +1,4 @@ -{% extends '../layouts/barebone.njk' %} +{% extends 'layouts/barebone.njk' %} {% set title = error_code + ' - ' + error_message %} diff --git a/test/views/layouts/barebone.njk b/views/layouts/barebone.njk similarity index 100% rename from test/views/layouts/barebone.njk rename to views/layouts/barebone.njk diff --git a/test/views/macros.njk b/views/macros.njk similarity index 100% rename from test/views/macros.njk rename to views/macros.njk diff --git a/views/magic_link.njk b/views/magic_link.njk new file mode 100644 index 0000000..41e6e17 --- /dev/null +++ b/views/magic_link.njk @@ -0,0 +1,19 @@ +{% extends 'layouts/base.njk' %} +{% import 'macros.njk' as macros %} + +{% set actionType = magicLink.action_type %} +{% set title = 'WMS: Magic Link' + (' - ' + actionType if actionType) %} +{% set h1 = 'Magic Link' + (' - ' + actionType if actionType) %} + +{% block body %} +
+
+ {% if err %} + {{ macros.message('error', err) }} + {% else %} + {{ macros.message('success', 'Success!') }} +

You can now close this page.

+ {% endif %} +
+
+{% endblock %} \ No newline at end of file diff --git a/views/magic_link_lobby.njk b/views/magic_link_lobby.njk new file mode 100644 index 0000000..e1a15a4 --- /dev/null +++ b/views/magic_link_lobby.njk @@ -0,0 +1,58 @@ +{% extends 'layouts/base.njk' %} +{% import 'macros.njk' as macros %} + +{% set title = 'Authentication lobby' %} +{% set h1 = 'Authentication lobby' %} + +{% block body %} +
+
+ {{ macros.message('success', 'We sent a link to ' + email + '. To authenticate, open it from any device.') }} + {{ macros.message('info', 'This link will be valid for and can only be used once.', true, true) }} + +

Waiting for you to open the link...

+
+
+{% endblock %} + +{% block scripts %} + + + {{ macros.websocket(websocketUrl, 'websocketListen', 1, 'isValid') }} +{% endblock %} \ No newline at end of file diff --git a/views/mails/account_review_notice.mjml.njk b/views/mails/account_review_notice.mjml.njk new file mode 100644 index 0000000..43b1ae3 --- /dev/null +++ b/views/mails/account_review_notice.mjml.njk @@ -0,0 +1,41 @@ +{% extends 'mails/base_layout.mjml.njk' %} + +{% block body %} + + + + {% if approved %} + Your registration was approved! + {% else %} + Sorry, your registration was rejected. + {% endif %} + + + {% if approved %} + An administrator approved your registration. You can now log in to your account. + {% else %} + Your registration was rejected and your account was deleted from our database. + If you believe that this is an error, please contact us via email. + {% endif %} + + + {% if approved %} + Login + {% endif %} + + +{% endblock %} + +{% block text %} + {% if approved %} + Hi + Your registration was approved! + + You can now log in to your account by follwing this link: {{ link|safe }} + {% else %} + Hi + Sorry, your registration was rejected. Your account was deleted from our database. + + If you believe that this is an error, please contact us via email. + {% endif %} +{% endblock %} \ No newline at end of file diff --git a/views/mails/base_layout.mjml.njk b/views/mails/base_layout.mjml.njk new file mode 100644 index 0000000..fdae4b5 --- /dev/null +++ b/views/mails/base_layout.mjml.njk @@ -0,0 +1,115 @@ +{% if not text %} + + + {{ mail_subject }} + + + + + + + + + + + + + + + + + + + + + .link { + color: #00766c !important; + text-decoration: none; + } + + + .link:hover { + color: #00a99b !important; + } + + {% block head %}{% endblock %} + + + {% if mail_link %} + + + + Does this mail display improperly? + Open it in the browser + + + + {% endif %} + + + + + {{ app.name }} + + + + + {% block body %}{% endblock %} + + + + + All rights reserved. Contact us at + {{ app.contact_email }} + + + + + +{% else %} + {% block text %}{% endblock %} +{% endif %} \ No newline at end of file diff --git a/views/mails/magic_link.mjml.njk b/views/mails/magic_link.mjml.njk new file mode 100644 index 0000000..208fa4e --- /dev/null +++ b/views/mails/magic_link.mjml.njk @@ -0,0 +1,66 @@ +{% extends 'mails/base_layout.mjml.njk' %} + +{% block body %} + + + + {% if type == 'register' %} + Register an account on {{ app.name }} + {% else %} + Log in to {{ app.name }} + {% endif %} + + + {% if type == 'register' %} + Someone has requested an account registration for {{ mail_to }}. If it was not you, + please ignore this message. + {% else %} + Someone is attempting to log in to your account {{ mail_to }}. + {% endif %} + + + {% if type == 'register' %} + Finalize my account registration + {% else %} + If it is not you, DO NOT CLICK ON THIS BUTTON. + {% endif %} + + + + {% if type == 'login' %} + + + + IP: {{ ip }} + + + Location: {{ geo }} + + + + + Authorize log in + + + + {% endif %} +{% endblock %} + +{% block text %} + {% if type == 'register' %} + Hi! + Someone requested an account registration for {{ mail_to }}. If it was not you, + please ignore this message. + + To finalize your account registration, please follow this link: {{ link|safe }} + {% else %} + Hi! + Someone is attempting to log in to your account {{ mail_to }}. + + If it is not you, DO NOT FOLLOW THIS LINK. + + IP: {{ ip }} + Location: {{ geo }} + To authorize this log in, please follow this link: {{ link|safe }} + {% endif %} +{% endblock %} \ No newline at end of file diff --git a/views/mails/pending_account_review.mjml.njk b/views/mails/pending_account_review.mjml.njk new file mode 100644 index 0000000..208fa4e --- /dev/null +++ b/views/mails/pending_account_review.mjml.njk @@ -0,0 +1,66 @@ +{% extends 'mails/base_layout.mjml.njk' %} + +{% block body %} + + + + {% if type == 'register' %} + Register an account on {{ app.name }} + {% else %} + Log in to {{ app.name }} + {% endif %} + + + {% if type == 'register' %} + Someone has requested an account registration for {{ mail_to }}. If it was not you, + please ignore this message. + {% else %} + Someone is attempting to log in to your account {{ mail_to }}. + {% endif %} + + + {% if type == 'register' %} + Finalize my account registration + {% else %} + If it is not you, DO NOT CLICK ON THIS BUTTON. + {% endif %} + + + + {% if type == 'login' %} + + + + IP: {{ ip }} + + + Location: {{ geo }} + + + + + Authorize log in + + + + {% endif %} +{% endblock %} + +{% block text %} + {% if type == 'register' %} + Hi! + Someone requested an account registration for {{ mail_to }}. If it was not you, + please ignore this message. + + To finalize your account registration, please follow this link: {{ link|safe }} + {% else %} + Hi! + Someone is attempting to log in to your account {{ mail_to }}. + + If it is not you, DO NOT FOLLOW THIS LINK. + + IP: {{ ip }} + Location: {{ geo }} + To authorize this log in, please follow this link: {{ link|safe }} + {% endif %} +{% endblock %} \ No newline at end of file