From 8c336a97d7431056c2369c22ddf22ad6f9afd19c Mon Sep 17 00:00:00 2001
From: Alina Beck
Date: Wed, 11 Sep 2019 12:27:56 +0100
Subject: [PATCH 01/21] install mustache
---
backend/package.json | 7 ++++---
backend/yarn.lock | 5 +++++
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/backend/package.json b/backend/package.json
index dd75b54d9..fecfe3441 100644
--- a/backend/package.json
+++ b/backend/package.json
@@ -89,6 +89,7 @@
"metascraper-video": "^5.6.5",
"metascraper-youtube": "^5.6.7",
"minimatch": "^3.0.4",
+ "mustache": "^3.0.3",
"neo4j-driver": "~1.7.6",
"neo4j-graphql-js": "^2.7.2",
"neode": "^0.3.3",
@@ -100,8 +101,8 @@
"slug": "~1.1.0",
"trunc-html": "~1.1.2",
"uuid": "~3.3.3",
- "xregexp": "^4.2.4",
- "wait-on": "~3.3.0"
+ "wait-on": "~3.3.0",
+ "xregexp": "^4.2.4"
},
"devDependencies": {
"@babel/cli": "~7.6.0",
@@ -131,4 +132,4 @@
"prettier": "~1.18.2",
"supertest": "~4.0.2"
}
-}
\ No newline at end of file
+}
diff --git a/backend/yarn.lock b/backend/yarn.lock
index b1a1e0368..d59891c1c 100644
--- a/backend/yarn.lock
+++ b/backend/yarn.lock
@@ -6104,6 +6104,11 @@ ms@^2.1.1:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
+mustache@^3.0.3:
+ version "3.0.3"
+ resolved "https://registry.yarnpkg.com/mustache/-/mustache-3.0.3.tgz#ee4fb971887fa6cc1b6b6d219a74b5e3c7535f32"
+ integrity sha512-vM5FkMHamTYmVYeAujypihuPrJQDtaUIlKeeVb1AMJ73OZLtWiF7GprqrjxD0gJWT53W9JfqXxf97nXQjMQkqA==
+
mute-stream@0.0.8:
version "0.0.8"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
From f802eab27df5a5ee7b6a34f088c40c7b292043d6 Mon Sep 17 00:00:00 2001
From: Alina Beck
Date: Wed, 11 Sep 2019 12:44:15 +0100
Subject: [PATCH 02/21] copy email text to separate file
---
.../src/middleware/email/templates/signup.js | 52 +++----------------
.../src/middleware/email/templates/signup.txt | 42 +++++++++++++++
2 files changed, 50 insertions(+), 44 deletions(-)
create mode 100644 backend/src/middleware/email/templates/signup.txt
diff --git a/backend/src/middleware/email/templates/signup.js b/backend/src/middleware/email/templates/signup.js
index 54cc51be2..25f3681d7 100644
--- a/backend/src/middleware/email/templates/signup.js
+++ b/backend/src/middleware/email/templates/signup.js
@@ -1,4 +1,9 @@
import CONFIG from '../../../config'
+import fs from 'fs'
+import path from 'path'
+import mustache from 'mustache'
+
+const signupText = fs.readFileSync(path.join(__dirname, './signup.txt'), 'utf-8')
export const signupTemplate = options => {
const {
@@ -11,52 +16,11 @@ export const signupTemplate = options => {
actionUrl.searchParams.set('nonce', nonce)
actionUrl.searchParams.set('email', email)
+ console.log(actionUrl)
+
return {
to: email,
subject,
- text: `
-Willkommen bei Human Connection! Klick auf diesen Link, um den
-Registrierungsprozess abzuschließen und um ein Benutzerkonto zu erstellen!
-
-${actionUrl}
-
-Alternativ kannst du diesen Code auch kopieren und im Browserfenster einfügen:
-
-${nonce}
-
-Bitte ignoriere diese Mail, falls du dich nicht bei Human Connection angemeldet
-hast. Bei Fragen kontaktiere gerne unseren Support:
-
-${supportUrl}
-
-Danke,
-Das Human Connection Team
-
-
-English Version
-===============
-
-Welcome to Human Connection! Use this link to complete the registration process
-and create a user account:
-
-${actionUrl}
-
-You can also copy+paste this verification nonce in your browser window:
-
-${nonce}
-
-If you did not signed up for Human Connection, please ignore this email or
-contact support if you have questions:
-
-${supportUrl}
-
-Thanks,
-The Human Connection Team
-
-Human Connection gemeinnützige GmbH
-Bahnhofstr. 11
-73235 Weilheim / Teck
-Deutschland
- `,
+ text: mustache.render(signupText, { actionUrl, nonce, supportUrl })
}
}
diff --git a/backend/src/middleware/email/templates/signup.txt b/backend/src/middleware/email/templates/signup.txt
new file mode 100644
index 000000000..c3e2ba8c6
--- /dev/null
+++ b/backend/src/middleware/email/templates/signup.txt
@@ -0,0 +1,42 @@
+Willkommen bei Human Connection! Klick auf diesen Link, um den
+Registrierungsprozess abzuschließen und um ein Benutzerkonto zu erstellen!
+
+{{{actionUrl}}}
+
+Alternativ kannst du diesen Code auch kopieren und im Browserfenster einfügen:
+
+{{{nonce}}}
+
+Bitte ignoriere diese Mail, falls du dich nicht bei Human Connection angemeldet
+hast. Bei Fragen kontaktiere gerne unseren Support:
+
+{{{supportUrl}}}
+
+Danke,
+Das Human Connection Team
+
+
+English Version
+===============
+
+Welcome to Human Connection! Use this link to complete the registration process
+and create a user account:
+
+{{{actionUrl}}}
+
+You can also copy+paste this verification nonce in your browser window:
+
+{{{nonce}}}
+
+If you did not signed up for Human Connection, please ignore this email or
+contact support if you have questions:
+
+{{{supportUrl}}}
+
+Thanks,
+The Human Connection Team
+
+Human Connection gemeinnützige GmbH
+Bahnhofstr. 11
+73235 Weilheim / Teck
+Deutschland
From 1cd354ff17dceab55808d23e9101d23bda7b7f66 Mon Sep 17 00:00:00 2001
From: Alina Beck
Date: Wed, 11 Sep 2019 12:51:27 +0100
Subject: [PATCH 03/21] paste html template from TedGoas/Cerberus
---
.../middleware/email/templates/signup.html | 434 ++++++++++++++++++
.../src/middleware/email/templates/signup.js | 4 +-
2 files changed, 437 insertions(+), 1 deletion(-)
create mode 100644 backend/src/middleware/email/templates/signup.html
diff --git a/backend/src/middleware/email/templates/signup.html b/backend/src/middleware/email/templates/signup.html
new file mode 100644
index 000000000..7316dc841
--- /dev/null
+++ b/backend/src/middleware/email/templates/signup.html
@@ -0,0 +1,434 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ (Optional) This text will appear in the inbox preview, but not the email body. It can be used to supplement the
+ email subject line or even summarize the email's contents. Extended text preheaders (~490 characters) seems like a
+ better UX for anyone using a screenreader or voice-command apps like Siri to dictate the contents of an email. If
+ this text is not included, email clients will automatically populate it using the text (including image alt text)
+ at the start of the email's body.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Praesent laoreet malesuada cursus.
+
Maecenas sed ante pellentesque, posuere leo id, eleifend dolor. Class aptent
+ taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent laoreet
+ malesuada cursus. Maecenas scelerisque congue eros eu posuere. Praesent in felis ut velit pretium
+ lobortis rhoncus ut erat.
+ Praesent in felis ut velit pretium lobortis rhoncus ut erat.
+
+
A list item.
+
Another list item here.
+
Everyone gets a list item, list items for
+ everyone!
+
+
Maecenas sed ante pellentesque, posuere leo id, eleifend dolor. Class aptent
+ taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent laoreet
+ malesuada cursus. Maecenas scelerisque congue eros eu posuere. Praesent in felis ut velit pretium
+ lobortis rhoncus ut erat.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Maecenas sed ante pellentesque, posuere leo id, eleifend dolor.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Maecenas sed ante pellentesque, posuere leo id, eleifend dolor.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Maecenas sed ante pellentesque, posuere leo id, eleifend dolor. Class aptent
+ taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent laoreet
+ malesuada cursus. Maecenas scelerisque congue eros eu posuere. Praesent in felis ut velit pretium
+ lobortis rhoncus ut erat.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ View as a Web Page
+
+
+ Company Name 123 Fake Street, SpringField, OR, 97477
+ US (123) 456-7890
+
+ unsubscribe
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Maecenas sed ante pellentesque, posuere leo id, eleifend dolor. Class aptent
+ taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent laoreet
+ malesuada cursus. Maecenas scelerisque congue eros eu posuere. Praesent in felis ut velit pretium
+ lobortis rhoncus ut erat.
- (Optional) This text will appear in the inbox preview, but not the email body. It can be used to supplement the
- email subject line or even summarize the email's contents. Extended text preheaders (~490 characters) seems like a
- better UX for anyone using a screenreader or voice-command apps like Siri to dictate the contents of an email. If
- this text is not included, email clients will automatically populate it using the text (including image alt text)
- at the start of the email's body.
-
-
-
-
-
-
-
-
-
-
-
@@ -234,8 +213,10 @@
-
@@ -246,14 +227,14 @@
-
+
- Praesent laoreet malesuada cursus.
-
Maecenas sed ante pellentesque, posuere leo id, eleifend dolor. Class aptent
- taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent laoreet
- malesuada cursus. Maecenas scelerisque congue eros eu posuere. Praesent in felis ut velit pretium
- lobortis rhoncus ut erat.
Thank you for joining our cause – it's awesome to have you on board. There's
+ just one tiny step missing before we can start shaping the world together: Please confirm your
+ e-mail address by clicking the button below!
- Praesent in felis ut velit pretium lobortis rhoncus ut erat.
-
-
A list item.
-
Another list item here.
-
Everyone gets a list item, list items for
- everyone!
-
-
Maecenas sed ante pellentesque, posuere leo id, eleifend dolor. Class aptent
- taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent laoreet
- malesuada cursus. Maecenas scelerisque congue eros eu posuere. Praesent in felis ut velit pretium
- lobortis rhoncus ut erat.
+
+
Or you can copy this code and paste it in your browser window:
@@ -294,52 +264,9 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Maecenas sed ante pellentesque, posuere leo id, eleifend dolor.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Maecenas sed ante pellentesque, posuere leo id, eleifend dolor.
-
-
-
-
-
-
-
-
-
-
-
+
@@ -350,11 +277,37 @@
-
-
Maecenas sed ante pellentesque, posuere leo id, eleifend dolor. Class aptent
- taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent laoreet
- malesuada cursus. Maecenas scelerisque congue eros eu posuere. Praesent in felis ut velit pretium
- lobortis rhoncus ut erat.
+
+
If you didn't sign up for Human Connection we recommend you to check it out!
+ It's an online platform for people to connect and change the world together.
+
PS: If you ignore this email we will not create an account for
+ you. ;)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Feel free to contact our support team with any questions you might have.
+
Thank you, and see you soon on Human Connection!
+
– The Human Connection Team
@@ -370,14 +323,11 @@
style="margin: auto;">
- View as a Web Page
-
+ style="padding: 20px; font-family: Lato, sans-serif; font-size: 12px; line-height: 15px; text-align: center; color: #888888;">
- Company Name 123 Fake Street, SpringField, OR, 97477
- US (123) 456-7890
+ Human Connection gGmbH Bahnhofstraße 11 73235 Weilheim /
+ Teck Germany
- unsubscribe
@@ -390,39 +340,6 @@
-
-
-
-
-
-
-
-
-
-
Maecenas sed ante pellentesque, posuere leo id, eleifend dolor. Class aptent
- taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent laoreet
- malesuada cursus. Maecenas scelerisque congue eros eu posuere. Praesent in felis ut velit pretium
- lobortis rhoncus ut erat.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
If you didn't sign up for Human Connection we recommend you to check it out!
+ style="padding: 20px; font-family: Lato, sans-serif; font-size: 16px; line-height: 22px; color: #555555;">
+
If you didn't sign up for Human Connection we recommend you to check it out!
It's an online platform for people to connect and change the world together.
PS: If you ignore this email we will not create an account for
you. ;)
+
+
–––––––––––––––––––––––––––––––––––––––––––––––
+
-
-
-
-
-
-
-
-
-
Feel free to contact our support team with any questions you might have.
If you didn't sign up for Human Connection we recommend you to check it out!
- It's an online platform for people to connect and change the world together.
+ It's a social network from people for people who want to connect and change the world together.
PS: If you ignore this email we will not create an account for
you. ;)
Danke, dass du dich angemeldet hast – wir freuen uns, dich dabei zu haben. Jetzt
+ fehlt nur noch eine Kleinigkeit, bevor wir gemeinsam die Welt verbessern können... Bitte bestätige
+ deine E-Mail Adresse:
Oder du kopierst diesen Code in dein Browserfenster: {{{ nonce }}}
+
+
+
+
+
–––––––––––––––––––––––––––––––––––––––––––––––
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Falls du dich nicht selbst bei Human Connection angemeldet hast, schau doch mal vorbei!
+ Wir sind ein gemeinnütziges Aktionsnetzwerk – von Menschen für Menschen.
+
PS: Wenn du keinen Account bei uns möchtest, kannst du diese
+ E-Mail einfach ignorieren. ;)
Du hast also dein Passwort vergessen? Kein Problem! Mit Klick auf diesen Button
+ kannst du innerhalb der nächsten 24 Stunden dein Passwort zurücksetzen:
Falls du kein neues Passwort angefordert hast, kannst du diese E-Mail einfach
+ ignorieren. Wenn du noch Fragen hast, melde dich gerne bei
+ unserem Support Team!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Sollte der Button für dich nicht funktionieren, kannst du auch folgenden Code in
+ dein Browserfenster einfügen: {{{ nonce }}}
From e45948f4f0785a455c1ff71f112eb337c26a6b13 Mon Sep 17 00:00:00 2001
From: Alina Beck
Date: Thu, 19 Sep 2019 00:23:51 +0100
Subject: [PATCH 17/21] use password reset template
---
.../email/templates/passwordReset.js | 48 +++++--------------
1 file changed, 13 insertions(+), 35 deletions(-)
diff --git a/backend/src/middleware/email/templates/passwordReset.js b/backend/src/middleware/email/templates/passwordReset.js
index c8617004b..03f697200 100644
--- a/backend/src/middleware/email/templates/passwordReset.js
+++ b/backend/src/middleware/email/templates/passwordReset.js
@@ -1,13 +1,17 @@
+import fs from 'fs'
+import path from 'path'
+import mustache from 'mustache'
import CONFIG from '../../../config'
-export const resetPasswordMail = options => {
- const {
- name,
- email,
- nonce,
- subject = 'Use this link to reset your password. The link is only valid for 24 hours.',
- supportUrl = 'https://human-connection.org/en/contact/',
- } = options
+const passwordResetHtml = fs.readFileSync(path.join(__dirname, './resetPassword.html'), 'utf-8')
+
+export const resetPasswordMail = ({
+ name,
+ email,
+ nonce,
+ subject = 'Neues Passwort / Reset Password',
+ supportUrl = 'https://human-connection.org/en/contact/',
+}) => {
const actionUrl = new URL('/password-reset/change-password', CONFIG.CLIENT_URI)
actionUrl.searchParams.set('nonce', nonce)
actionUrl.searchParams.set('email', email)
@@ -16,33 +20,7 @@ export const resetPasswordMail = options => {
from: '"Human Connection" ',
to: email,
subject,
- text: `
-Hi ${name}!
-
-You recently requested to reset your password for your Human Connection account.
-Use the link below to reset it. This password reset is only valid for the next
-24 hours.
-
-${actionUrl}
-
-If you did not request a password reset, please ignore this email or contact
-support if you have questions:
-
-${supportUrl}
-
-Thanks,
-The Human Connection Team
-
-If you're having trouble with the link above, you can manually copy and
-paste the following code into your browser window:
-
-${nonce}
-
-Human Connection gemeinnützige GmbH
-Bahnhofstr. 11
-73235 Weilheim / Teck
-Deutschland
- `,
+ html: mustache.render(passwordResetHtml, { actionUrl, name, nonce, supportUrl }),
}
}
From b193e180c5d9d70c8d9e9aa5f927493026cb8458 Mon Sep 17 00:00:00 2001
From: Alina Beck
Date: Thu, 19 Sep 2019 00:42:42 +0100
Subject: [PATCH 18/21] add wrong account html template
---
.../email/templates/passwordReset.js | 26 +-
.../email/templates/resetPassword.html | 4 +-
.../email/templates/wrongAccount.html | 448 ++++++++++++++++++
3 files changed, 452 insertions(+), 26 deletions(-)
create mode 100644 backend/src/middleware/email/templates/wrongAccount.html
diff --git a/backend/src/middleware/email/templates/passwordReset.js b/backend/src/middleware/email/templates/passwordReset.js
index 03f697200..0b57fc9d5 100644
--- a/backend/src/middleware/email/templates/passwordReset.js
+++ b/backend/src/middleware/email/templates/passwordReset.js
@@ -4,6 +4,7 @@ import mustache from 'mustache'
import CONFIG from '../../../config'
const passwordResetHtml = fs.readFileSync(path.join(__dirname, './resetPassword.html'), 'utf-8')
+const wrongAccountHtml = fs.readFileSync(path.join(__dirname, './wrongAccount.html'), 'utf-8')
export const resetPasswordMail = ({
name,
@@ -35,29 +36,6 @@ export const wrongAccountMail = options => {
from: '"Human Connection" ',
to: email,
subject,
- text: `
-We received a request to reset the password to access Human Connection with your
-email address, but we were unable to find an account associated with this
-address.
-
-If you use Human Connection and were expecting this email, consider trying to
-request a password reset using the email address associated with your account.
-Try a different email:
-
-${actionUrl}
-
-If you do not use Human Connection or did not request a password reset, please
-ignore this email. Feel free to contact support if you have further questions:
-
-${supportUrl}
-
-Thanks,
-The Human Connection Team
-
-Human Connection gemeinnützige GmbH
-Bahnhofstr. 11
-73235 Weilheim / Teck
-Deutschland
- `,
+ html: mustache.render(wrongAccountHtml, { actionUrl, supportUrl }),
}
}
diff --git a/backend/src/middleware/email/templates/resetPassword.html b/backend/src/middleware/email/templates/resetPassword.html
index 162078c73..1b12702b4 100644
--- a/backend/src/middleware/email/templates/resetPassword.html
+++ b/backend/src/middleware/email/templates/resetPassword.html
@@ -8,7 +8,7 @@
- Reset Password / Neues Passwort
+ Reset Password | Neues Passwort
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Hallo!
+
Du hast bei uns ein neues Password angefordert – leider haben wir aber keinen
+ Account mit deiner E-Mailadresse gefunden. Kann es sein, dass du mit einer anderen Adresse bei uns
+ angemeldet bist?
You requested a password reset but unfortunately we couldn't find an account
+ associated with your email address. Did you maybe use another one when you signed up?
+
+
+
From a7d525deab849799cae9d4c11d76c6d149b61b0a Mon Sep 17 00:00:00 2001
From: Alina Beck
Date: Thu, 19 Sep 2019 00:55:06 +0100
Subject: [PATCH 19/21] refactor password reset
---
.../src/middleware/email/emailMiddleware.js | 7 ++-
.../email/templates/passwordReset.js | 43 +++++++++----------
2 files changed, 23 insertions(+), 27 deletions(-)
diff --git a/backend/src/middleware/email/emailMiddleware.js b/backend/src/middleware/email/emailMiddleware.js
index 52bf25954..af3d69c4a 100644
--- a/backend/src/middleware/email/emailMiddleware.js
+++ b/backend/src/middleware/email/emailMiddleware.js
@@ -1,13 +1,13 @@
import CONFIG from '../../config'
import nodemailer from 'nodemailer'
import { htmlToText } from 'nodemailer-html-to-text'
-import { resetPasswordMail, wrongAccountMail } from './templates/passwordReset'
+import { resetPasswordTemplate } from './templates/passwordReset'
import { signupTemplate } from './templates/signup'
const hasEmailConfig = CONFIG.SMTP_HOST && CONFIG.SMTP_PORT
const hasAuthData = CONFIG.SMTP_USERNAME && CONFIG.SMTP_PASSWORD
-let sendMail = () => {}
+let sendMail = () => { }
if (!hasEmailConfig) {
if (process.env.NODE_ENV !== 'test') {
// eslint-disable-next-line no-console
@@ -49,8 +49,7 @@ const sendSignupMail = async (resolve, root, args, context, resolveInfo) => {
const sendPasswordResetMail = async (resolve, root, args, context, resolveInfo) => {
const { email } = args
const { email: emailFound, nonce, name } = await resolve(root, args, context, resolveInfo)
- const mailTemplate = emailFound ? resetPasswordMail : wrongAccountMail
- await sendMail(mailTemplate({ email, nonce, name }))
+ await sendMail(resetPasswordTemplate({ emailFound, email, nonce, name }))
return true
}
diff --git a/backend/src/middleware/email/templates/passwordReset.js b/backend/src/middleware/email/templates/passwordReset.js
index 0b57fc9d5..d9da7a180 100644
--- a/backend/src/middleware/email/templates/passwordReset.js
+++ b/backend/src/middleware/email/templates/passwordReset.js
@@ -6,36 +6,33 @@ import CONFIG from '../../../config'
const passwordResetHtml = fs.readFileSync(path.join(__dirname, './resetPassword.html'), 'utf-8')
const wrongAccountHtml = fs.readFileSync(path.join(__dirname, './wrongAccount.html'), 'utf-8')
-export const resetPasswordMail = ({
+const supportUrl = 'https://human-connection.org/en/contact/'
+const from = '"Human Connection" '
+
+export const resetPasswordTemplate = ({
name,
email,
+ emailFound,
nonce,
- subject = 'Neues Passwort / Reset Password',
- supportUrl = 'https://human-connection.org/en/contact/',
}) => {
- const actionUrl = new URL('/password-reset/change-password', CONFIG.CLIENT_URI)
- actionUrl.searchParams.set('nonce', nonce)
- actionUrl.searchParams.set('email', email)
+ let subject, htmlTemplate, actionUrl
+
+ if (emailFound) {
+ subject = 'Neues Passwort | Reset Password'
+ htmlTemplate = passwordResetHtml
+ actionUrl = new URL('/password-reset/change-password', CONFIG.CLIENT_URI)
+ actionUrl.searchParams.set('nonce', nonce)
+ actionUrl.searchParams.set('email', email)
+ } else {
+ subject = 'Falsche Mailadresse? | Wrong Email?'
+ htmlTemplate = wrongAccountHtml
+ actionUrl = new URL('/password-reset/request', CONFIG.CLIENT_URI)
+ }
return {
- from: '"Human Connection" ',
+ from,
to: email,
subject,
- html: mustache.render(passwordResetHtml, { actionUrl, name, nonce, supportUrl }),
- }
-}
-
-export const wrongAccountMail = options => {
- const {
- email,
- subject = `We received a request to reset your password with this email address (${email})`,
- supportUrl = 'https://human-connection.org/en/contact/',
- } = options
- const actionUrl = new URL('/password-reset/request', CONFIG.CLIENT_URI)
- return {
- from: '"Human Connection" ',
- to: email,
- subject,
- html: mustache.render(wrongAccountHtml, { actionUrl, supportUrl }),
+ html: mustache.render(htmlTemplate, { actionUrl, name, nonce, supportUrl }),
}
}
From e843edeb131a8017f3ef078608b133cdba4b84b1 Mon Sep 17 00:00:00 2001
From: Alina Beck
Date: Thu, 19 Sep 2019 01:15:52 +0100
Subject: [PATCH 20/21] unite email templates in templateBuilder
---
.../src/middleware/email/emailMiddleware.js | 14 +--
.../email/templates/passwordReset.js | 38 ---------
.../src/middleware/email/templates/signup.js | 24 ------
.../email/templates/templateBuilder.js | 48 +++++++++++
.../resolvers/passwordReset/emailTemplates.js | 85 -------------------
5 files changed, 57 insertions(+), 152 deletions(-)
delete mode 100644 backend/src/middleware/email/templates/passwordReset.js
delete mode 100644 backend/src/middleware/email/templates/signup.js
create mode 100644 backend/src/middleware/email/templates/templateBuilder.js
delete mode 100644 backend/src/schema/resolvers/passwordReset/emailTemplates.js
diff --git a/backend/src/middleware/email/emailMiddleware.js b/backend/src/middleware/email/emailMiddleware.js
index af3d69c4a..e5b0678b8 100644
--- a/backend/src/middleware/email/emailMiddleware.js
+++ b/backend/src/middleware/email/emailMiddleware.js
@@ -1,13 +1,16 @@
import CONFIG from '../../config'
import nodemailer from 'nodemailer'
import { htmlToText } from 'nodemailer-html-to-text'
-import { resetPasswordTemplate } from './templates/passwordReset'
-import { signupTemplate } from './templates/signup'
+import {
+ signupTemplate,
+ resetPasswordTemplate,
+ wrongAccountTemplate,
+} from './templates/templateBuilder'
const hasEmailConfig = CONFIG.SMTP_HOST && CONFIG.SMTP_PORT
const hasAuthData = CONFIG.SMTP_USERNAME && CONFIG.SMTP_PASSWORD
-let sendMail = () => { }
+let sendMail = () => {}
if (!hasEmailConfig) {
if (process.env.NODE_ENV !== 'test') {
// eslint-disable-next-line no-console
@@ -48,8 +51,9 @@ const sendSignupMail = async (resolve, root, args, context, resolveInfo) => {
const sendPasswordResetMail = async (resolve, root, args, context, resolveInfo) => {
const { email } = args
- const { email: emailFound, nonce, name } = await resolve(root, args, context, resolveInfo)
- await sendMail(resetPasswordTemplate({ emailFound, email, nonce, name }))
+ const { email: userFound, nonce, name } = await resolve(root, args, context, resolveInfo)
+ const template = userFound ? resetPasswordTemplate : wrongAccountTemplate
+ await sendMail(template({ email, nonce, name }))
return true
}
diff --git a/backend/src/middleware/email/templates/passwordReset.js b/backend/src/middleware/email/templates/passwordReset.js
deleted file mode 100644
index d9da7a180..000000000
--- a/backend/src/middleware/email/templates/passwordReset.js
+++ /dev/null
@@ -1,38 +0,0 @@
-import fs from 'fs'
-import path from 'path'
-import mustache from 'mustache'
-import CONFIG from '../../../config'
-
-const passwordResetHtml = fs.readFileSync(path.join(__dirname, './resetPassword.html'), 'utf-8')
-const wrongAccountHtml = fs.readFileSync(path.join(__dirname, './wrongAccount.html'), 'utf-8')
-
-const supportUrl = 'https://human-connection.org/en/contact/'
-const from = '"Human Connection" '
-
-export const resetPasswordTemplate = ({
- name,
- email,
- emailFound,
- nonce,
-}) => {
- let subject, htmlTemplate, actionUrl
-
- if (emailFound) {
- subject = 'Neues Passwort | Reset Password'
- htmlTemplate = passwordResetHtml
- actionUrl = new URL('/password-reset/change-password', CONFIG.CLIENT_URI)
- actionUrl.searchParams.set('nonce', nonce)
- actionUrl.searchParams.set('email', email)
- } else {
- subject = 'Falsche Mailadresse? | Wrong Email?'
- htmlTemplate = wrongAccountHtml
- actionUrl = new URL('/password-reset/request', CONFIG.CLIENT_URI)
- }
-
- return {
- from,
- to: email,
- subject,
- html: mustache.render(htmlTemplate, { actionUrl, name, nonce, supportUrl }),
- }
-}
diff --git a/backend/src/middleware/email/templates/signup.js b/backend/src/middleware/email/templates/signup.js
deleted file mode 100644
index d67c8f7ae..000000000
--- a/backend/src/middleware/email/templates/signup.js
+++ /dev/null
@@ -1,24 +0,0 @@
-import fs from 'fs'
-import path from 'path'
-import mustache from 'mustache'
-import CONFIG from '../../../config'
-
-const signupHtml = fs.readFileSync(path.join(__dirname, './signup.html'), 'utf-8')
-
-export const signupTemplate = ({
- email,
- nonce,
- subject = 'Willkommen, Bienvenue, Welcome to Human Connection!',
- supportUrl = 'https://human-connection.org/en/contact',
-}) => {
- const actionUrl = new URL('/registration/create-user-account', CONFIG.CLIENT_URI)
- actionUrl.searchParams.set('nonce', nonce)
- actionUrl.searchParams.set('email', email)
-
- return {
- from: '"Human Connection" ',
- to: email,
- subject,
- html: mustache.render(signupHtml, { actionUrl, nonce, supportUrl }),
- }
-}
diff --git a/backend/src/middleware/email/templates/templateBuilder.js b/backend/src/middleware/email/templates/templateBuilder.js
new file mode 100644
index 000000000..8bf7dc438
--- /dev/null
+++ b/backend/src/middleware/email/templates/templateBuilder.js
@@ -0,0 +1,48 @@
+import fs from 'fs'
+import path from 'path'
+import mustache from 'mustache'
+import CONFIG from '../../../config'
+
+const from = '"Human Connection" '
+const supportUrl = 'https://human-connection.org/en/contact'
+
+const signupHtml = fs.readFileSync(path.join(__dirname, './signup.html'), 'utf-8')
+const passwordResetHtml = fs.readFileSync(path.join(__dirname, './resetPassword.html'), 'utf-8')
+const wrongAccountHtml = fs.readFileSync(path.join(__dirname, './wrongAccount.html'), 'utf-8')
+
+export const signupTemplate = ({ email, nonce }) => {
+ const actionUrl = new URL('/registration/create-user-account', CONFIG.CLIENT_URI)
+ actionUrl.searchParams.set('nonce', nonce)
+ actionUrl.searchParams.set('email', email)
+
+ return {
+ from,
+ to: email,
+ subject: 'Willkommen, Bienvenue, Welcome to Human Connection!',
+ html: mustache.render(signupHtml, { actionUrl, supportUrl }),
+ }
+}
+
+export const resetPasswordTemplate = ({ email, nonce, name }) => {
+ const actionUrl = new URL('/password-reset/change-password', CONFIG.CLIENT_URI)
+ actionUrl.searchParams.set('nonce', nonce)
+ actionUrl.searchParams.set('email', email)
+
+ return {
+ from,
+ to: email,
+ subject: 'Neues Passwort | Reset Password',
+ html: mustache.render(passwordResetHtml, { actionUrl, name, nonce, supportUrl }),
+ }
+}
+
+export const wrongAccountTemplate = ({ email }) => {
+ const actionUrl = new URL('/password-reset/request', CONFIG.CLIENT_URI)
+
+ return {
+ from,
+ to: email,
+ subject: 'Falsche Mailadresse? | Wrong Email?',
+ html: mustache.render(wrongAccountHtml, { actionUrl, supportUrl }),
+ }
+}
diff --git a/backend/src/schema/resolvers/passwordReset/emailTemplates.js b/backend/src/schema/resolvers/passwordReset/emailTemplates.js
deleted file mode 100644
index 8508adccc..000000000
--- a/backend/src/schema/resolvers/passwordReset/emailTemplates.js
+++ /dev/null
@@ -1,85 +0,0 @@
-import CONFIG from '../../../config'
-
-export const from = '"Human Connection" '
-
-export const resetPasswordMail = options => {
- const {
- name,
- email,
- code,
- subject = 'Use this link to reset your password. The link is only valid for 24 hours.',
- supportUrl = 'https://human-connection.org/en/contact/',
- } = options
- const actionUrl = new URL('/password-reset/change-password', CONFIG.CLIENT_URI)
- actionUrl.searchParams.set('code', code)
- actionUrl.searchParams.set('email', email)
-
- return {
- to: email,
- subject,
- text: `
-Hi ${name}!
-
-You recently requested to reset your password for your Human Connection account.
-Use the link below to reset it. This password reset is only valid for the next
-24 hours.
-
-${actionUrl}
-
-If you did not request a password reset, please ignore this email or contact
-support if you have questions:
-
-${supportUrl}
-
-Thanks,
-The Human Connection Team
-
-If you're having trouble with the link above, you can manually copy and
-paste the following code into your browser window:
-
-${code}
-
-Human Connection gemeinnützige GmbH
-Bahnhofstr. 11
-73235 Weilheim / Teck
-Deutschland
- `,
- }
-}
-
-export const wrongAccountMail = options => {
- const {
- email,
- subject = `We received a request to reset your password with this email address (${email})`,
- supportUrl = 'https://human-connection.org/en/contact/',
- } = options
- const actionUrl = new URL('/password-reset/request', CONFIG.CLIENT_URI)
- return {
- to: email,
- subject,
- text: `
-We received a request to reset the password to access Human Connection with your
-email address, but we were unable to find an account associated with this
-address.
-
-If you use Human Connection and were expecting this email, consider trying to
-request a password reset using the email address associated with your account.
-Try a different email:
-
-${actionUrl}
-
-If you do not use Human Connection or did not request a password reset, please
-ignore this email. Feel free to contact support if you have further questions:
-
-${supportUrl}
-
-Thanks,
-The Human Connection Team
-
-Human Connection gemeinnützige GmbH
-Bahnhofstr. 11
-73235 Weilheim / Teck
-Deutschland
- `,
- }
-}
From b25d552193269a4c58f689523394fb519b3bee91 Mon Sep 17 00:00:00 2001
From: Alina Beck
Date: Thu, 19 Sep 2019 09:52:47 +0100
Subject: [PATCH 21/21] follow @Tirokk and @datenbrei suggestions
---
.../email/templates/resetPassword.html | 14 ++++----
.../middleware/email/templates/signup.html | 33 ++++++++-----------
.../email/templates/templateBuilder.js | 2 +-
.../email/templates/wrongAccount.html | 18 +++++-----
4 files changed, 30 insertions(+), 37 deletions(-)
diff --git a/backend/src/middleware/email/templates/resetPassword.html b/backend/src/middleware/email/templates/resetPassword.html
index 1b12702b4..e0dde53e5 100644
--- a/backend/src/middleware/email/templates/resetPassword.html
+++ b/backend/src/middleware/email/templates/resetPassword.html
@@ -8,7 +8,7 @@
- Reset Password | Neues Passwort
+ Neues Passwort | Reset Password
- Here is your signup link.
+ Dein Anmeldelink. | Here is your signup link.
@@ -261,9 +261,9 @@
Willkommen bei Human Connection!
-
Danke, dass du dich angemeldet hast – wir freuen uns, dich dabei zu haben. Jetzt
- fehlt nur noch eine Kleinigkeit, bevor wir gemeinsam die Welt verbessern können... Bitte bestätige
- deine E-Mail Adresse:
+
Danke, dass Du dich angemeldet hast – wir freuen uns, Dich dabei zu haben. Jetzt
+ fehlt nur noch eine Kleinigkeit, bevor wir gemeinsam die Welt verbessern können ... Bitte bestätige
+ Deine E-Mail Adresse:
Falls du dich nicht selbst bei Falls Du Dich nicht selbst bei Human Connection angemeldet hast, schau doch mal vorbei!
Wir sind ein gemeinnütziges Aktionsnetzwerk – von Menschen für Menschen.
-
PS: Wenn du keinen Account bei uns möchtest, kannst du diese
+
PS: Wenn Du keinen Account bei uns möchtest, kannst Du diese
E-Mail einfach ignorieren. ;)
Thank you for joining our cause – it's awesome to have you on board. There's
- just one tiny step missing before we can start shaping the world together... Please confirm your
+ just one tiny step missing before we can start shaping the world together ... Please confirm your
e-mail address by clicking the button below:
Or you can copy this code and paste it in your browser window: {{{ nonce }}}
-
-
–––––––––––––––––––––––––––––––––––––––––––––––
@@ -422,7 +414,8 @@
If you didn't sign up for Human Connection we recommend you to check it out!
It's a social network from people for people who want to connect and change the world together.
-
PS: If you ignore this email we will not create an account for
+
PS: If you ignore this e-mail we will not create an account
+ for
you. ;)