-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add reset password email template
- Loading branch information
Showing
4 changed files
with
67 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,46 @@ pub fn send_verify_user( | |
|
||
Ok(data) | ||
} | ||
|
||
pub fn send_forgot_password( | ||
email_api_key: String, | ||
to: String, | ||
reset_password_link: String, | ||
) -> Result(ApiData, AppError) { | ||
// Create an email to send | ||
|
||
let body = | ||
[templates.forgot_password_confirmation(reset_password_link)] | ||
|> curry2(layout)("Forgot Password Confirmation") | ||
|> element.to_string | ||
|
||
let email = | ||
zeptomail.Email( | ||
from: Addressee("Planktonsoft", "[email protected]"), | ||
to: [Addressee(to, to)], | ||
reply_to: [], | ||
cc: [], | ||
bcc: [], | ||
body: zeptomail.HtmlBody(body), | ||
subject: "Crappy Board: Forgot Password Confirmation", | ||
) | ||
|
||
// Prepare an API request that sends the email | ||
let request = zeptomail.email_request(email, email_api_key) | ||
|
||
// Send the API request using `gleam_httpc` | ||
let assert Ok(response) = httpc.send(request) | ||
|
||
// Parse the API response to verify success | ||
use data <- result.then( | ||
zeptomail.decode_email_response(response) | ||
|> result.map_error(fn(error) { | ||
io.debug(error) | ||
case error { | ||
_ -> error.ApiError(error) | ||
} | ||
}), | ||
) | ||
|
||
Ok(data) | ||
} |
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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import app/templates/forgot_password_confirmation | ||
import app/templates/signup_confirmation | ||
|
||
pub fn signup_confirmation(confirmation_link: String) { | ||
signup_confirmation.root(confirmation_link) | ||
} | ||
|
||
pub fn forgot_password_confirmation(reset_password_link: String) { | ||
forgot_password_confirmation.root(reset_password_link) | ||
} |
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,17 @@ | ||
import lustre/attribute.{attribute} | ||
import lustre/element.{type Element} | ||
import lustre/element/html | ||
|
||
pub fn root(reset_password_link: String) -> Element(t) { | ||
html.div([attribute.class("email-container")], [ | ||
html.h1([], [element.text("Forgot Password Confirmation")]), | ||
html.p([], [element.text("Please click the button below.")]), | ||
html.a([attribute.href(reset_password_link)], [ | ||
element.text("Forgot Password"), | ||
]), | ||
html.p([], [ | ||
element.text("If you didn’t forgot password, ignore this email."), | ||
]), | ||
html.footer([], [element.text("© 2024 Planktonsoft. All rights reserved.")]), | ||
]) | ||
} |