Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(hasura): replace email webhook with actions (#282)
* fix(hasura): replace email webhook with actions * fix: remove unsused file * Update targets/frontend/src/components/user/List.js Co-authored-by: Julien Bouquillon <julien.bouquillon@sg.social.gouv.fr> Co-authored-by: Julien Bouquillon <julien.bouquillon@sg.social.gouv.fr>
- Loading branch information
Showing
14 changed files
with
185 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import sendmail from "./sendmail"; | ||
|
||
const BASE_URL = | ||
process.env.CI_ENVIRONMENT_URL || `http://localhost:${process.env.PORT}`; | ||
|
||
export function sendActivateAccountEmail(email, secret_token) { | ||
const subject = "Activation de votre compte"; | ||
const activateUrl = `${BASE_URL}/change_password?token=${secret_token}&activate=1`; // todo: dynamic hostname | ||
const text = `Bonjour, | ||
Vous pouvez activer votre compte ${email} afin d'accéder à | ||
l'outil d'administration du cdtn en suivant ce lien : ${activateUrl} | ||
L'equipe veille CDTN | ||
`; | ||
|
||
var mailOptions = { | ||
from: process.env.ACCOUNT_MAIL_SENDER, | ||
subject, | ||
text, | ||
to: email, | ||
}; | ||
|
||
return sendmail(mailOptions); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import sendmail from "./sendmail"; | ||
|
||
const BASE_URL = | ||
process.env.CI_ENVIRONMENT_URL || `http://localhost:${process.env.PORT}`; | ||
|
||
export function sendLostPasswordEmail(email, secret_token) { | ||
const activateUrl = `${BASE_URL}/change_password?token=${secret_token}`; // todo: dynamic hostname | ||
const subject = "Réinitialisation de votre mot de passe"; | ||
const text = ` | ||
Bonjour, | ||
Une demande pour réinitialiser votre de mot de passe est en cours. | ||
Vous pouvez suivre ce lien : ${activateUrl} pour valider la demande. | ||
Si vous n'etes pas à l'origine de cette demande, pas de soucis, | ||
ne tenez pas compte de de message. | ||
L'equipe veille CDTN | ||
`; | ||
|
||
var mailOptions = { | ||
from: process.env.ACCOUNT_MAIL_SENDER, | ||
subject, | ||
text, | ||
to: email, | ||
}; | ||
|
||
return sendmail(mailOptions); | ||
} |
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
targets/frontend/src/pages/api/actions/email_account_activation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Boom from "@hapi/boom"; | ||
import { apiError } from "src/lib/apiError"; | ||
import { sendActivateAccountEmail } from "src/lib/emails/activateAccount"; | ||
|
||
export default async function ActivateAccount(req, res) { | ||
if ( | ||
!req.headers["actions-secret"] || | ||
req.headers["actions-secret"] !== process.env.ACTIONS_SECRET | ||
) { | ||
return apiError(res, Boom.unauthorized("Missing secret or env")); | ||
} | ||
|
||
const { email, secret_token } = req.body.input; | ||
try { | ||
await sendActivateAccountEmail(email, secret_token); | ||
res.json({ message: "email sent!", statusCode: 200 }); | ||
} catch (error) { | ||
console.error(`[email] send activation email to ${email} failed`); | ||
apiError(res, Boom.badGateway(`send activation email to ${email} failed`)); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
targets/frontend/src/pages/api/actions/email_password_request.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Boom from "@hapi/boom"; | ||
import { apiError } from "src/lib/apiError"; | ||
import { sendLostPasswordEmail } from "src/lib/emails/lostPassword"; | ||
|
||
export default async function AskNewPassword(req, res) { | ||
if ( | ||
!req.headers["actions-secret"] || | ||
req.headers["actions-secret"] !== process.env.ACTIONS_SECRET | ||
) { | ||
return apiError(res, Boom.unauthorized("Missing secret or env")); | ||
} | ||
|
||
const { email, secret_token } = req.body.input; | ||
try { | ||
await sendLostPasswordEmail(email, secret_token); | ||
res.json({ message: "email sent!", statusCode: 200 }); | ||
} catch (error) { | ||
console.error(`[email] send activation email to ${email} failed`); | ||
apiError(res, Boom.badGateway(`send activation email to ${email} failed`)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.