From f63d93f3740e029e336048742be886641aca0971 Mon Sep 17 00:00:00 2001 From: FORESTIER Fabien <fabien.forestier@soprasteria.com> Date: Thu, 31 Jan 2019 18:32:17 +0100 Subject: [PATCH] Add redis + put redis key/value on account creation and send email --- docker-compose.yml | 14 ++ package-lock.json | 28 +++- package.json | 5 +- src/configuration/config.ts | 5 + .../account-creation-template.html | 28 ++++ .../account-creation-template.mjml | 65 ++++++++ src/email-templates/account-creation/index.ts | 37 +++++ .../data-access-deletion-admin-template.html | 2 +- .../data-access-deletion-admin-template.mjml | 2 +- .../data-access-deletion-user-template.html | 2 +- .../data-access-deletion-user-template.mjml | 2 +- .../data-access-deletion/index.ts | 4 +- .../data-access-renew-admin-template.html | 2 +- .../data-access-renew-admin-template.mjml | 2 +- .../data-access-renew-user-template.html | 2 +- .../data-access-renew-user-template.mjml | 2 +- .../data-access-renew/index.ts | 4 +- .../data-access-request-admin-template.html | 2 +- .../data-access-request-admin-template.mjml | 2 +- .../data-access-request-user-template.html | 2 +- .../data-access-request-user-template.mjml | 2 +- .../data-access-request/index.ts | 4 +- src/legacy/errorHandlingHelper.ts | 14 ++ src/legacy/legacy.service.ts | 142 +++++++++++++++--- 24 files changed, 328 insertions(+), 46 deletions(-) create mode 100644 src/email-templates/account-creation/account-creation-template.html create mode 100644 src/email-templates/account-creation/account-creation-template.mjml create mode 100644 src/email-templates/account-creation/index.ts create mode 100644 src/legacy/errorHandlingHelper.ts diff --git a/docker-compose.yml b/docker-compose.yml index 3c37cc1..6829373 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,20 @@ services: - ADMIN_USERNAME=${DEV_ADMIN_USERNAME} - SERVICE_EMAIL_URL=${DEV_SERVICE_EMAIL_URL} - PLATEFORM_DATA_ADMIN_EMAIL=${DEV_PLATEFORM_DATA_ADMIN_EMAIL} + restart: unless-stopped + depends_on: + - redis + + redis: + container_name: middleware-legacy-aut-redis-${NODE_ENV} + image: redis:5.0.0-alpine + command: ["redis-server", "--appendonly", "yes"] + hostname: redis + volumes: + - redis-data:/data restart: unless-stopped +volumes: + redis-data: + diff --git a/package-lock.json b/package-lock.json index f022982..086e991 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1332,8 +1332,7 @@ "bluebird": { "version": "3.5.3", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.3.tgz", - "integrity": "sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw==", - "dev": true + "integrity": "sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw==" }, "bn.js": { "version": "4.11.8", @@ -2481,6 +2480,11 @@ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-6.1.0.tgz", "integrity": "sha512-/veDn2ztgRlB7gKmE3i9f6CmDIyXAy6d5nBq+whO9SLX+Zs1sXEgFLPi+aSuWqUuusMfbi84fT8j34fs1HaYUw==" }, + "double-ended-queue": { + "version": "2.1.0-0", + "resolved": "https://registry.npmjs.org/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz", + "integrity": "sha1-ED01J/0xUo9AGIEwyEHv3XgmTlw=" + }, "duplexer3": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz", @@ -7165,6 +7169,26 @@ "util.promisify": "^1.0.0" } }, + "redis": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/redis/-/redis-2.8.0.tgz", + "integrity": "sha512-M1OkonEQwtRmZv4tEWF2VgpG0JWJ8Fv1PhlgT5+B+uNq2cA3Rt1Yt/ryoR+vQNOQcIEgdCdfH0jr3bDpihAw1A==", + "requires": { + "double-ended-queue": "^2.1.0-0", + "redis-commands": "^1.2.0", + "redis-parser": "^2.6.0" + } + }, + "redis-commands": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.4.0.tgz", + "integrity": "sha512-cu8EF+MtkwI4DLIT0x9P8qNTLFhQD4jLfxLR0cCNkeGzs87FN6879JOJwNQR/1zD7aSYNbU0hgsV9zGY71Itvw==" + }, + "redis-parser": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-2.6.0.tgz", + "integrity": "sha1-Uu0J2srBCPGmMcB+m2mUHnoZUEs=" + }, "reflect-metadata": { "version": "0.1.12", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.12.tgz", diff --git a/package.json b/package.json index 6bf5423..02a387c 100644 --- a/package.json +++ b/package.json @@ -23,17 +23,20 @@ "@nestjs/common": "^5.1.0", "@nestjs/core": "^5.1.0", "@nestjs/swagger": "^2.5.1", + "bluebird": "^3.5.3", "class-transformer": "^0.2.0", "class-validator": "^0.9.1", "dotenv": "^6.1.0", "jsonwebtoken": "^8.4.0", "moment": "^2.23.0", "node-rsa": "^1.0.3", + "redis": "^2.8.0", "reflect-metadata": "^0.1.12", "request": "^2.88.0", "request-promise-native": "^1.0.5", "rxjs": "^6.2.2", - "typescript": "^3.0.1" + "typescript": "^3.0.1", + "uuid": "^3.3.2" }, "devDependencies": { "@nestjs/testing": "^5.1.0", diff --git a/src/configuration/config.ts b/src/configuration/config.ts index bb6fc2d..05d70ed 100644 --- a/src/configuration/config.ts +++ b/src/configuration/config.ts @@ -7,4 +7,9 @@ export const Config = { plateformeDataAdminEmail: '', publicKey: '', privateKey: '', + accountCreationTokenTTL: 86400, // Time to live of the token used to validate the cration of an account in second (24h) + redis: { + port: 6379, + host: 'redis', + }, }; \ No newline at end of file diff --git a/src/email-templates/account-creation/account-creation-template.html b/src/email-templates/account-creation/account-creation-template.html new file mode 100644 index 0000000..83f047e --- /dev/null +++ b/src/email-templates/account-creation/account-creation-template.html @@ -0,0 +1,28 @@ +<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Validation de votre compte</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } + .ReadMsgBody { width:100%; } + .ExternalClass { width:100%; } + .ExternalClass * { line-height:100%; } + body { margin:0;padding:0;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%; } + table, td { border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt; } + img { border:0;height:auto;line-height:100%; outline:none;text-decoration:none;-ms-interpolation-mode:bicubic; } + p { display:block;margin:13px 0; }</style><!--[if !mso]><!--><style type="text/css">@media only screen and (max-width:480px) { + @-ms-viewport { width:320px; } + @viewport { width:320px; } + }</style><!--<![endif]--><!--[if mso]> + <xml> + <o:OfficeDocumentSettings> + <o:AllowPNG/> + <o:PixelsPerInch>96</o:PixelsPerInch> + </o:OfficeDocumentSettings> + </xml> + <![endif]--><!--[if lte mso 11]> + <style type="text/css"> + .outlook-group-fix { width:100% !important; } + </style> + <![endif]--><!--[if !mso]><!--><link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css"><style type="text/css">@import url(https://fonts.googleapis.com/css?family=Lato);</style><!--<![endif]--><style type="text/css">@media only screen and (min-width:480px) { + .mj-column-per-100 { width:100% !important; max-width: 100%; } + }</style><style type="text/css">@media only screen and (max-width:480px) { + table.full-width-mobile { width: 100% !important; } + td.full-width-mobile { width: auto !important; } + }</style></head><body><div><!--[if mso | IE]><table align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]--><div style="Margin:0px auto;max-width:600px;"><table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;"><tbody><tr><td style="border:1px solid #ccc;direction:ltr;font-size:0px;padding:0px 0px;text-align:center;vertical-align:top;"><!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" width="600px" ><table align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:598px;" width="598" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]--><div style="background:white;background-color:white;Margin:0px auto;max-width:598px;"><table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="background:white;background-color:white;width:100%;"><tbody><tr><td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;vertical-align:top;"><!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:598px;" ><![endif]--><div class="mj-column-per-100 outlook-group-fix" style="font-size:13px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%"><tr><td align="center" style="font-size:0px;padding:10px 25px;word-break:break-word;"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:collapse;border-spacing:0px;"><tbody><tr><td style="width:250px;"><img height="auto" src="https://highway-to-data.alpha.grandlyon.com/email-template-assets/datagrandlyoncom.png" style="border:0;display:block;outline:none;text-decoration:none;height:auto;width:100%;" width="250"></td></tr></tbody></table></td></tr><tr><td style="font-size:0px;padding:10px 25px;word-break:break-word;"><p style="border-top:solid 4px #ed1c24;font-size:1;margin:0px auto;width:100%;"></p><!--[if mso | IE]><table align="center" border="0" cellpadding="0" cellspacing="0" style="border-top:solid 4px #ed1c24;font-size:1;margin:0px auto;width:548px;" role="presentation" width="548px" ><tr><td style="height:0;line-height:0;"> +</td></tr></table><![endif]--></td></tr><tr><td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;"><div style="font-family:Lato;font-size:16px;line-height:25px;text-align:left;color:#000000;"><h2 align="center">Validation de votre compte</h2></div></td></tr><tr><td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;"><div style="font-family:Lato;font-size:16px;line-height:25px;text-align:left;color:#000000;"><p style="margin:0px;">Bonjour,</p><p>Vous avez récemment effectué une demarche de cration de compte sur la plateforme data.grandlyon.com.</p><p>Afin de valider votre email et de finaliser la création de votre compte, veuillez cliquer sur le lien suivant.</p><p><a href="${info.accountValidationUrl}">${info.accountValidationUrl}</a></p><p>Ce lien expirera ${info.tokenValidity}h après la saisie du formulaire de création de compte.</p><p>Merci d'utiliser notre site !</p><p>L'équipe de data.grandlyon.com</p></div></td></tr></table></div><!--[if mso | IE]></td></tr></table><![endif]--></td></tr></tbody></table></div><!--[if mso | IE]></td></tr></table></td></tr><tr><td class="" width="600px" ><table align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:598px;" width="598" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]--><div style="background:#ed1c24;background-color:#ed1c24;Margin:0px auto;max-width:598px;"><table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="background:#ed1c24;background-color:#ed1c24;width:100%;"><tbody><tr><td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;vertical-align:top;"><!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:598px;" ><![endif]--><div class="mj-column-per-100 outlook-group-fix" style="font-size:13px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%"><tr><td align="center" style="font-size:0px;padding:10px 25px;word-break:break-word;"><!--[if mso | IE]><table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" ><tr><td><![endif]--><table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="float:none;display:inline-table;"><tr><td style="padding:4px;"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-radius:3px;width:25px;"><tr><td style="font-size:0;height:25px;vertical-align:middle;width:25px;"><a href="https://download.data.grandlyon.com/catalogue/srv/fre/rss.search?sortBy=publicationDate&georss=simplepoint&data" target="_blank"><img height="25" src="https://highway-to-data.alpha.grandlyon.com/email-template-assets/rss.png" style="border-radius:3px;" width="25"></a></td></tr></table></td></tr></table><!--[if mso | IE]></td><td><![endif]--><table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="float:none;display:inline-table;"><tr><td style="padding:4px;"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-radius:3px;width:25px;"><tr><td style="font-size:0;height:25px;vertical-align:middle;width:25px;"><a href="http://www.facebook.com/legrandlyon" target="_blank"><img height="25" src="https://highway-to-data.alpha.grandlyon.com/email-template-assets/facebook.png" style="border-radius:3px;" width="25"></a></td></tr></table></td></tr></table><!--[if mso | IE]></td><td><![endif]--><table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="float:none;display:inline-table;"><tr><td style="padding:4px;"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-radius:3px;width:25px;"><tr><td style="font-size:0;height:25px;vertical-align:middle;width:25px;"><a href="https://twitter.com/grandlyon" target="_blank"><img height="25" src="https://highway-to-data.alpha.grandlyon.com/email-template-assets/twitter.png" style="border-radius:3px;" width="25"></a></td></tr></table></td></tr></table><!--[if mso | IE]></td></tr></table><![endif]--></td></tr></table></div><!--[if mso | IE]></td></tr></table><![endif]--></td></tr></tbody></table></div><!--[if mso | IE]></td></tr></table></td></tr></table><![endif]--></td></tr></tbody></table></div><!--[if mso | IE]></td></tr></table><![endif]--></div></body></html> \ No newline at end of file diff --git a/src/email-templates/account-creation/account-creation-template.mjml b/src/email-templates/account-creation/account-creation-template.mjml new file mode 100644 index 0000000..0040fbb --- /dev/null +++ b/src/email-templates/account-creation/account-creation-template.mjml @@ -0,0 +1,65 @@ +<mjml> + <mj-head> + <mj-title>Validation de votre compte</mj-title> + <mj-font name="Lato" href="https://fonts.googleapis.com/css?family=Lato" /> + <mj-attributes> + <mj-text font-family="Lato" line-height="25px" font-size="16px" /> + </mj-attributes> + </mj-head> + <mj-body> + <mj-wrapper border="1px solid #ccc" padding="0px 0px"> + <mj-section background-color="white"> + <mj-column> + + <mj-image width="250px" src="https://highway-to-data.alpha.grandlyon.com/email-template-assets/datagrandlyoncom.png"></mj-image> + + <mj-divider border-color="#ed1c24"></mj-divider> + + <mj-text> + <h2 align="center"> + Validation de votre compte + </h2> + </mj-text> + <mj-text> + <p style="margin:0px;">Bonjour,</p> + + <p>Vous avez récemment effectué une demarche de cration de compte sur la plateforme data.grandlyon.com.</p> + + <p>Afin de valider votre email et de finaliser la création de votre compte, veuillez cliquer sur le lien suivant.</p> + + <p> + <a href="${info.accountValidationUrl}"> + ${info.accountValidationUrl} + </a> + </p> + + <p>Ce lien expirera ${info.tokenValidity}h après la saisie du formulaire de création de compte.</p> + + <p> + Merci d'utiliser notre site ! + </p> + + <p> + L'équipe de data.grandlyon.com + </p> + </mj-text> + </mj-column> + </mj-section> + + <mj-section background-color="#ed1c24"> + <mj-column> + <mj-social font-size="15px" icon-size="25px" mode="horizontal"> + <mj-social-element href="https://download.data.grandlyon.com/catalogue/srv/fre/rss.search?sortBy=publicationDate&georss=simplepoint&data" src="https://highway-to-data.alpha.grandlyon.com/email-template-assets/rss.png"> + </mj-social-element> + <mj-social-element href="http://www.facebook.com/legrandlyon" src="https://highway-to-data.alpha.grandlyon.com/email-template-assets/facebook.png"> + </mj-social-element> + <mj-social-element href="https://twitter.com/grandlyon" src="https://highway-to-data.alpha.grandlyon.com/email-template-assets/twitter.png"> + </mj-social-element> + </mj-social> + </mj-column> + </mj-section> + + + </mj-wrapper> + </mj-body> +</mjml> \ No newline at end of file diff --git a/src/email-templates/account-creation/index.ts b/src/email-templates/account-creation/index.ts new file mode 100644 index 0000000..9507f47 --- /dev/null +++ b/src/email-templates/account-creation/index.ts @@ -0,0 +1,37 @@ +export const buildAccountValidationEmail = (info: AccountValidationEmailInfo) => { + const html = `<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Validation de votre compte</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } + .ReadMsgBody { width:100%; } + .ExternalClass { width:100%; } + .ExternalClass * { line-height:100%; } + body { margin:0;padding:0;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%; } + table, td { border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt; } + img { border:0;height:auto;line-height:100%; outline:none;text-decoration:none;-ms-interpolation-mode:bicubic; } + p { display:block;margin:13px 0; }</style><!--[if !mso]><!--><style type="text/css">@media only screen and (max-width:480px) { + @-ms-viewport { width:320px; } + @viewport { width:320px; } + }</style><!--<![endif]--><!--[if mso]> +<xml> +<o:OfficeDocumentSettings> + <o:AllowPNG/> + <o:PixelsPerInch>96</o:PixelsPerInch> +</o:OfficeDocumentSettings> +</xml> +<![endif]--><!--[if lte mso 11]> +<style type="text/css"> + .outlook-group-fix { width:100% !important; } +</style> +<![endif]--><!--[if !mso]><!--><link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css"><style type="text/css">@import url(https://fonts.googleapis.com/css?family=Lato);</style><!--<![endif]--><style type="text/css">@media only screen and (min-width:480px) { +.mj-column-per-100 { width:100% !important; max-width: 100%; } +}</style><style type="text/css">@media only screen and (max-width:480px) { +table.full-width-mobile { width: 100% !important; } +td.full-width-mobile { width: auto !important; } +}</style></head><body><div><!--[if mso | IE]><table align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]--><div style="Margin:0px auto;max-width:600px;"><table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;"><tbody><tr><td style="border:1px solid #ccc;direction:ltr;font-size:0px;padding:0px 0px;text-align:center;vertical-align:top;"><!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" width="600px" ><table align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:598px;" width="598" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]--><div style="background:white;background-color:white;Margin:0px auto;max-width:598px;"><table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="background:white;background-color:white;width:100%;"><tbody><tr><td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;vertical-align:top;"><!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:598px;" ><![endif]--><div class="mj-column-per-100 outlook-group-fix" style="font-size:13px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%"><tr><td align="center" style="font-size:0px;padding:10px 25px;word-break:break-word;"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:collapse;border-spacing:0px;"><tbody><tr><td style="width:250px;"><img height="auto" src="https://highway-to-data.alpha.grandlyon.com/email-template-assets/datagrandlyoncom.png" style="border:0;display:block;outline:none;text-decoration:none;height:auto;width:100%;" width="250"></td></tr></tbody></table></td></tr><tr><td style="font-size:0px;padding:10px 25px;word-break:break-word;"><p style="border-top:solid 4px #ed1c24;font-size:1;margin:0px auto;width:100%;"></p><!--[if mso | IE]><table align="center" border="0" cellpadding="0" cellspacing="0" style="border-top:solid 4px #ed1c24;font-size:1;margin:0px auto;width:548px;" role="presentation" width="548px" ><tr><td style="height:0;line-height:0;"> +</td></tr></table><![endif]--></td></tr><tr><td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;"><div style="font-family:Lato;font-size:16px;line-height:25px;text-align:left;color:#000000;"><h2 align="center">Validation de votre compte</h2></div></td></tr><tr><td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;"><div style="font-family:Lato;font-size:16px;line-height:25px;text-align:left;color:#000000;"><p style="margin:0px;">Bonjour,</p><p>Vous avez récemment effectué une demarche de cration de compte sur la plateforme data.grandlyon.com.</p><p>Afin de valider votre email et de finaliser la création de votre compte, veuillez cliquer sur le lien suivant.</p><p><a href="${info.accountValidationUrl}">${info.accountValidationUrl}</a></p><p>Ce lien expirera ${info.tokenValidity}h après la saisie du formulaire de création de compte.</p><p>Merci d'utiliser notre site !</p><p>L'équipe de data.grandlyon.com</p></div></td></tr></table></div><!--[if mso | IE]></td></tr></table><![endif]--></td></tr></tbody></table></div><!--[if mso | IE]></td></tr></table></td></tr><tr><td class="" width="600px" ><table align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:598px;" width="598" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]--><div style="background:#ed1c24;background-color:#ed1c24;Margin:0px auto;max-width:598px;"><table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="background:#ed1c24;background-color:#ed1c24;width:100%;"><tbody><tr><td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;vertical-align:top;"><!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:598px;" ><![endif]--><div class="mj-column-per-100 outlook-group-fix" style="font-size:13px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%"><tr><td align="center" style="font-size:0px;padding:10px 25px;word-break:break-word;"><!--[if mso | IE]><table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" ><tr><td><![endif]--><table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="float:none;display:inline-table;"><tr><td style="padding:4px;"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-radius:3px;width:25px;"><tr><td style="font-size:0;height:25px;vertical-align:middle;width:25px;"><a href="https://download.data.grandlyon.com/catalogue/srv/fre/rss.search?sortBy=publicationDate&georss=simplepoint&data" target="_blank"><img height="25" src="https://highway-to-data.alpha.grandlyon.com/email-template-assets/rss.png" style="border-radius:3px;" width="25"></a></td></tr></table></td></tr></table><!--[if mso | IE]></td><td><![endif]--><table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="float:none;display:inline-table;"><tr><td style="padding:4px;"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-radius:3px;width:25px;"><tr><td style="font-size:0;height:25px;vertical-align:middle;width:25px;"><a href="http://www.facebook.com/legrandlyon" target="_blank"><img height="25" src="https://highway-to-data.alpha.grandlyon.com/email-template-assets/facebook.png" style="border-radius:3px;" width="25"></a></td></tr></table></td></tr></table><!--[if mso | IE]></td><td><![endif]--><table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="float:none;display:inline-table;"><tr><td style="padding:4px;"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-radius:3px;width:25px;"><tr><td style="font-size:0;height:25px;vertical-align:middle;width:25px;"><a href="https://twitter.com/grandlyon" target="_blank"><img height="25" src="https://highway-to-data.alpha.grandlyon.com/email-template-assets/twitter.png" style="border-radius:3px;" width="25"></a></td></tr></table></td></tr></table><!--[if mso | IE]></td></tr></table><![endif]--></td></tr></table></div><!--[if mso | IE]></td></tr></table><![endif]--></td></tr></tbody></table></div><!--[if mso | IE]></td></tr></table></td></tr></table><![endif]--></td></tr></tbody></table></div><!--[if mso | IE]></td></tr></table><![endif]--></div></body></html>`; + + return html; +}; + +class AccountValidationEmailInfo { + accountValidationUrl: string; + tokenValidity: number; +} \ No newline at end of file diff --git a/src/email-templates/data-access-deletion/data-access-deletion-admin-template.html b/src/email-templates/data-access-deletion/data-access-deletion-admin-template.html index c3aca2c..f0dd89c 100644 --- a/src/email-templates/data-access-deletion/data-access-deletion-admin-template.html +++ b/src/email-templates/data-access-deletion/data-access-deletion-admin-template.html @@ -1,4 +1,4 @@ -<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Réinitialisation du mot de passe</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } +<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Demande de suppression d’accès aux données</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } .ReadMsgBody { width:100%; } .ExternalClass { width:100%; } .ExternalClass * { line-height:100%; } diff --git a/src/email-templates/data-access-deletion/data-access-deletion-admin-template.mjml b/src/email-templates/data-access-deletion/data-access-deletion-admin-template.mjml index 76e443e..7a85c8a 100644 --- a/src/email-templates/data-access-deletion/data-access-deletion-admin-template.mjml +++ b/src/email-templates/data-access-deletion/data-access-deletion-admin-template.mjml @@ -1,6 +1,6 @@ <mjml> <mj-head> - <mj-title>Réinitialisation du mot de passe</mj-title> + <mj-title>Demande de suppression d’accès aux données</mj-title> <mj-font name="Lato" href="https://fonts.googleapis.com/css?family=Lato" /> <mj-attributes> <mj-text font-family="Lato" line-height="25px" font-size="16px" /> diff --git a/src/email-templates/data-access-deletion/data-access-deletion-user-template.html b/src/email-templates/data-access-deletion/data-access-deletion-user-template.html index 688c01c..74ff928 100644 --- a/src/email-templates/data-access-deletion/data-access-deletion-user-template.html +++ b/src/email-templates/data-access-deletion/data-access-deletion-user-template.html @@ -1,4 +1,4 @@ -<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Réinitialisation du mot de passe</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } +<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Demande de suppression d’accès aux données</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } .ReadMsgBody { width:100%; } .ExternalClass { width:100%; } .ExternalClass * { line-height:100%; } diff --git a/src/email-templates/data-access-deletion/data-access-deletion-user-template.mjml b/src/email-templates/data-access-deletion/data-access-deletion-user-template.mjml index b014c27..10aff6c 100644 --- a/src/email-templates/data-access-deletion/data-access-deletion-user-template.mjml +++ b/src/email-templates/data-access-deletion/data-access-deletion-user-template.mjml @@ -1,6 +1,6 @@ <mjml> <mj-head> - <mj-title>Réinitialisation du mot de passe</mj-title> + <mj-title>Demande de suppression d’accès aux données</mj-title> <mj-font name="Lato" href="https://fonts.googleapis.com/css?family=Lato" /> <mj-attributes> <mj-text font-family="Lato" line-height="25px" font-size="16px" /> diff --git a/src/email-templates/data-access-deletion/index.ts b/src/email-templates/data-access-deletion/index.ts index b3c6828..99017b7 100644 --- a/src/email-templates/data-access-deletion/index.ts +++ b/src/email-templates/data-access-deletion/index.ts @@ -1,5 +1,5 @@ export const buildDataAccessDeletionAdminEmail = (params: DataAccessEmailDeletionInfo) => { - const html = `<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Réinitialisation du mot de passe</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } + const html = `<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Demande de suppression d’accès aux données</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } .ReadMsgBody { width:100%; } .ExternalClass { width:100%; } .ExternalClass * { line-height:100%; } @@ -32,7 +32,7 @@ td.full-width-mobile { width: auto !important; } }; export const buildDataAccessDeletionUserEmail = (datasets: string) => { - const html = `<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Réinitialisation du mot de passe</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } + const html = `<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Demande de suppression d’accès aux données</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } .ReadMsgBody { width:100%; } .ExternalClass { width:100%; } .ExternalClass * { line-height:100%; } diff --git a/src/email-templates/data-access-renew/data-access-renew-admin-template.html b/src/email-templates/data-access-renew/data-access-renew-admin-template.html index dec30bb..b66e15f 100644 --- a/src/email-templates/data-access-renew/data-access-renew-admin-template.html +++ b/src/email-templates/data-access-renew/data-access-renew-admin-template.html @@ -1,4 +1,4 @@ -<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Réinitialisation du mot de passe</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } +<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Demande de renouvellement d’accès aux données</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } .ReadMsgBody { width:100%; } .ExternalClass { width:100%; } .ExternalClass * { line-height:100%; } diff --git a/src/email-templates/data-access-renew/data-access-renew-admin-template.mjml b/src/email-templates/data-access-renew/data-access-renew-admin-template.mjml index 39ccb8c..08927c9 100644 --- a/src/email-templates/data-access-renew/data-access-renew-admin-template.mjml +++ b/src/email-templates/data-access-renew/data-access-renew-admin-template.mjml @@ -1,6 +1,6 @@ <mjml> <mj-head> - <mj-title>Réinitialisation du mot de passe</mj-title> + <mj-title>Demande de renouvellement d’accès aux données</mj-title> <mj-font name="Lato" href="https://fonts.googleapis.com/css?family=Lato" /> <mj-attributes> <mj-text font-family="Lato" line-height="25px" font-size="16px" /> diff --git a/src/email-templates/data-access-renew/data-access-renew-user-template.html b/src/email-templates/data-access-renew/data-access-renew-user-template.html index 26e0b00..da3fb24 100644 --- a/src/email-templates/data-access-renew/data-access-renew-user-template.html +++ b/src/email-templates/data-access-renew/data-access-renew-user-template.html @@ -1,4 +1,4 @@ -<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Réinitialisation du mot de passe</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } +<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Demande de renouvellement d’accès aux données</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } .ReadMsgBody { width:100%; } .ExternalClass { width:100%; } .ExternalClass * { line-height:100%; } diff --git a/src/email-templates/data-access-renew/data-access-renew-user-template.mjml b/src/email-templates/data-access-renew/data-access-renew-user-template.mjml index 387a0ad..3215641 100644 --- a/src/email-templates/data-access-renew/data-access-renew-user-template.mjml +++ b/src/email-templates/data-access-renew/data-access-renew-user-template.mjml @@ -1,6 +1,6 @@ <mjml> <mj-head> - <mj-title>Réinitialisation du mot de passe</mj-title> + <mj-title>Demande de renouvellement d’accès aux données</mj-title> <mj-font name="Lato" href="https://fonts.googleapis.com/css?family=Lato" /> <mj-attributes> <mj-text font-family="Lato" line-height="25px" font-size="16px" /> diff --git a/src/email-templates/data-access-renew/index.ts b/src/email-templates/data-access-renew/index.ts index ef2d2d9..b34409b 100644 --- a/src/email-templates/data-access-renew/index.ts +++ b/src/email-templates/data-access-renew/index.ts @@ -1,5 +1,5 @@ export const buildRenewDataAccessRequestAdminEmail = (params: DataAccessEmailDeletionInfo) => { - const html = `<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Réinitialisation du mot de passe</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } + const html = `<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Demande de renouvellement d’accès aux données</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } .ReadMsgBody { width:100%; } .ExternalClass { width:100%; } .ExternalClass * { line-height:100%; } @@ -32,7 +32,7 @@ td.full-width-mobile { width: auto !important; } }; export const buildRenewDataAccessRequestUserEmail = (datasets: string) => { - const html = `<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Réinitialisation du mot de passe</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } + const html = `<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Demande de renouvellement d’accès aux données</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } .ReadMsgBody { width:100%; } .ExternalClass { width:100%; } .ExternalClass * { line-height:100%; } diff --git a/src/email-templates/data-access-request/data-access-request-admin-template.html b/src/email-templates/data-access-request/data-access-request-admin-template.html index e7543e7..e3217ac 100644 --- a/src/email-templates/data-access-request/data-access-request-admin-template.html +++ b/src/email-templates/data-access-request/data-access-request-admin-template.html @@ -1,4 +1,4 @@ -<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Réinitialisation du mot de passe</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } +<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Demande d’accès aux données</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } .ReadMsgBody { width:100%; } .ExternalClass { width:100%; } .ExternalClass * { line-height:100%; } diff --git a/src/email-templates/data-access-request/data-access-request-admin-template.mjml b/src/email-templates/data-access-request/data-access-request-admin-template.mjml index 2d0e9ee..91014e9 100644 --- a/src/email-templates/data-access-request/data-access-request-admin-template.mjml +++ b/src/email-templates/data-access-request/data-access-request-admin-template.mjml @@ -1,6 +1,6 @@ <mjml> <mj-head> - <mj-title>Réinitialisation du mot de passe</mj-title> + <mj-title>Demande d’accès aux données</mj-title> <mj-font name="Lato" href="https://fonts.googleapis.com/css?family=Lato" /> <mj-attributes> <mj-text font-family="Lato" line-height="25px" font-size="16px" /> diff --git a/src/email-templates/data-access-request/data-access-request-user-template.html b/src/email-templates/data-access-request/data-access-request-user-template.html index dd04e78..8ff98c7 100644 --- a/src/email-templates/data-access-request/data-access-request-user-template.html +++ b/src/email-templates/data-access-request/data-access-request-user-template.html @@ -1,4 +1,4 @@ -<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Réinitialisation du mot de passe</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } +<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Demande d’accès aux données</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } .ReadMsgBody { width:100%; } .ExternalClass { width:100%; } .ExternalClass * { line-height:100%; } diff --git a/src/email-templates/data-access-request/data-access-request-user-template.mjml b/src/email-templates/data-access-request/data-access-request-user-template.mjml index 549b43a..43b16ab 100644 --- a/src/email-templates/data-access-request/data-access-request-user-template.mjml +++ b/src/email-templates/data-access-request/data-access-request-user-template.mjml @@ -1,6 +1,6 @@ <mjml> <mj-head> - <mj-title>Réinitialisation du mot de passe</mj-title> + <mj-title>Demande d’accès aux données</mj-title> <mj-font name="Lato" href="https://fonts.googleapis.com/css?family=Lato" /> <mj-attributes> <mj-text font-family="Lato" line-height="25px" font-size="16px" /> diff --git a/src/email-templates/data-access-request/index.ts b/src/email-templates/data-access-request/index.ts index 094ca5a..4559d21 100644 --- a/src/email-templates/data-access-request/index.ts +++ b/src/email-templates/data-access-request/index.ts @@ -1,5 +1,5 @@ export const buildDataAccessRequestAdminEmail = (params: DataAccessEmailDeletionInfo) => { - const html = `<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Réinitialisation du mot de passe</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } + const html = `<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Demande d’accès aux données</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } .ReadMsgBody { width:100%; } .ExternalClass { width:100%; } .ExternalClass * { line-height:100%; } @@ -32,7 +32,7 @@ td.full-width-mobile { width: auto !important; } }; export const buildDataAccessRequestUserEmail = (datasets: string) => { - const html = `<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Réinitialisation du mot de passe</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } + const html = `<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title>Demande d’accès aux données</title><!--[if !mso]><!-- --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style type="text/css">#outlook a { padding:0; } .ReadMsgBody { width:100%; } .ExternalClass { width:100%; } .ExternalClass * { line-height:100%; } diff --git a/src/legacy/errorHandlingHelper.ts b/src/legacy/errorHandlingHelper.ts new file mode 100644 index 0000000..7729554 --- /dev/null +++ b/src/legacy/errorHandlingHelper.ts @@ -0,0 +1,14 @@ +import { HttpException } from '@nestjs/common'; + +export function handleError(err, defaultErr) { + if (err instanceof HttpException) { + throw err; + } else { + if (err && err.error) { + const error = JSON.parse(err.error); + throw new HttpException(error.message, err.statusCode); + } else { + throw defaultErr; + } + } +} \ No newline at end of file diff --git a/src/legacy/legacy.service.ts b/src/legacy/legacy.service.ts index 5672367..897f20b 100644 --- a/src/legacy/legacy.service.ts +++ b/src/legacy/legacy.service.ts @@ -13,6 +13,12 @@ import { decrypt } from './encryptionHelpers'; import { buildDataAccessDeletionAdminEmail, buildDataAccessDeletionUserEmail } from 'email-templates/data-access-deletion'; import { buildDataAccessRequestAdminEmail, buildDataAccessRequestUserEmail } from 'email-templates/data-access-request'; import { buildRenewDataAccessRequestAdminEmail, buildRenewDataAccessRequestUserEmail } from 'email-templates/data-access-renew'; +import { handleError } from './errorHandlingHelper'; +import * as bluebird from 'bluebird'; +import * as redis from 'redis'; +bluebird.promisifyAll(redis); +import * as uuid4 from 'uuid/v4'; +import { buildAccountValidationEmail } from 'email-templates/account-creation'; @Injectable() export class LegacyService { @@ -139,34 +145,48 @@ export class LegacyService { async createUser(form: UserCreationForm): Promise<void> { Logger.log(`[-] createUser method`); try { - form.password = decrypt(form.password, this.conf.privateKey); + // form.password = decrypt(form.password, this.conf.privateKey); const legacyForm = new LegacyUserCreationForm(form); - let res = await request.post(`${this.conf.authUrl}/add_user/`).form(legacyForm); - res = JSON.parse(res); - if (res.server_response && res.server_response === 'Success') { - Logger.log(res); - return; - } else { - Logger.error(` [x] Error: ${res.message}`); - if (res.message === 'Error during account creation') { - throw new InternalServerErrorException(res.message); - } - if (res.message === 'Account already exists') { - throw new BadRequestException('existingAccount'); - } - if (res.message === 'Uncomplete form') { - throw new BadRequestException('uncompleteForm'); - } else { - throw new BadRequestException(res.message); - } - } + + // Generate a unique random token + const accountCreationToken = uuid4(); + Logger.log('Reset password token:', accountCreationToken); + + // Set a redis key/value, this allow to open a 24h session with the token as key that will let us identify the email associated to the token + await this.setRedisKeyValue(accountCreationToken, JSON.stringify(legacyForm) , this.conf.accountCreationTokenTTL); + + const html = buildAccountValidationEmail({ accountValidationUrl: 'test', tokenValidity: (this.conf.accountCreationTokenTTL / 3600) }); + + await request.post(`${this.conf.serviceEmailUrl}/email/send`).form({ + html, + to: [form.email], + subject: 'Validation de votre compte data.grandlyon.com', + }); + + return; + + // let res = await request.post(`${this.conf.authUrl}/add_user/`).form(legacyForm); + // res = JSON.parse(res); + // if (res.server_response && res.server_response === 'Success') { + // Logger.log(res); + // return; + // } else { + // Logger.error(` [x] Error: ${res.message}`); + // if (res.message === 'Error during account creation') { + // throw new InternalServerErrorException(res.message); + // } + // if (res.message === 'Account already exists') { + // throw new BadRequestException('existingAccount'); + // } + // if (res.message === 'Uncomplete form') { + // throw new BadRequestException('uncompleteForm'); + // } else { + // throw new BadRequestException(res.message); + // } + // } } catch (err) { Logger.error(err); - if (err instanceof HttpException) { - throw new HttpException(err.message, err.getStatus()); - } else { - throw new InternalServerErrorException('Something went wrong.'); - } + handleError(err, new InternalServerErrorException('Something went wrong.')); } } @@ -607,4 +627,76 @@ export class LegacyService { throw new InternalServerErrorException('Couldn\'t get the public key.'); } } + + /**** Redis methods ****/ + + private async setRedisKeyValue(key: string, value: string, ttl: number): Promise<any> { + Logger.log(`[-] setRedisKeyValue with params: ${key} ${value} ${ttl}`); + + const client = this.connectToRedis(); + + try { + // Set key value with expiration time in seconds + const res = await client.setAsync(key, value, 'EX', ttl); + Logger.log(` [*] Setting key/pair result => ${res}`); + client.quit(); + return res; + } catch (error) { + Logger.error(` [x] Setting key/pair error:`); + Logger.error(error); + client.quit(); + handleError(error, new InternalServerErrorException('Couldn\'t set key/value in redis.')); + } + } + + private async deleteRedisKey(key: string): Promise<any> { + Logger.log(`[-] deleteRedisKey with params: ${key}`); + + const client = this.connectToRedis(); + + try { + // Set key value with expiration time in seconds + const res = await client.delAsync(key); + Logger.log(` [*] Removing key/pair result => ${res}`); + client.quit(); + return res; + } catch (error) { + Logger.error(` [x] Removing key/pair error:`); + Logger.error(error); + client.quit(); + handleError(error, new InternalServerErrorException('Couldn\'t remove key/value in redis.')); + } + } + + private async getRedisValueByKey(key: string): Promise<string> { + Logger.log(`[-] getRedisValueByKey with key: ${key}`); + + const client = this.connectToRedis(); + + try { + const res = await client.getAsync(key); + Logger.log(` [*] Value found => ${res}`); + client.quit(); + return res; + } catch (error) { + Logger.error(` [x] Error getting value from redis:`); + Logger.error(error); + client.quit(); + handleError(error, new InternalServerErrorException('Couldn\'t get value from redis.')); + } + } + + private connectToRedis() { + Logger.log(`[-] Connecting to redis`); + + const client = redis.createClient({ host: this.conf.redis.host, port: this.conf.redis.port }); + + client.on('error', (err) => { + Logger.error(' [x] Redis client error:'); + Logger.error(err); + client.quit(); + }); + + return client; + } } \ No newline at end of file -- GitLab