Working on emails, updated swagger, added geometry column to airports
This commit is contained in:
@@ -6,8 +6,9 @@ use lettre::message::{Mailbox, MultiPart, SinglePart};
|
||||
use lettre::transport::smtp::authentication::Credentials;
|
||||
use lettre::{Address, Message, SmtpTransport, Transport};
|
||||
use serde::Serialize;
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::sync::OnceLock;
|
||||
use std::{env, fs};
|
||||
|
||||
static MAILER: OnceLock<SmtpTransport> = OnceLock::new();
|
||||
static FROM_ADDRESS: OnceLock<Mailbox> = OnceLock::new();
|
||||
@@ -34,46 +35,10 @@ fn from_address() -> &'static Mailbox {
|
||||
})
|
||||
}
|
||||
|
||||
fn registry() -> &'static Handlebars<'static> {
|
||||
pub fn registry() -> &'static Handlebars<'static> {
|
||||
REGISTRY.get_or_init(|| Handlebars::new())
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct PasswordResetCtx {
|
||||
logo_url: String,
|
||||
link: String,
|
||||
domain: String,
|
||||
year: i32,
|
||||
}
|
||||
|
||||
pub fn send_password_reset(to: &str, token: &str) -> ApiResult<()> {
|
||||
let base_url = env::var("EXTERNAL_URL")?.trim_end_matches('/').to_string();
|
||||
let link = format!("{base_url}/profile/reset?token={token}");
|
||||
let subject = "Reset your password";
|
||||
|
||||
let plain = format!(
|
||||
"Hello,\n\n\
|
||||
We received a password reset request. Click the link below:\n\n\
|
||||
{link}\n\n\
|
||||
This link expires in 24 hours. If you didn't request this, please ignore.\n\n\
|
||||
Cheers,\n\
|
||||
\tAviation Data",
|
||||
link = link
|
||||
);
|
||||
|
||||
let ctx = PasswordResetCtx {
|
||||
logo_url: format!("{}/logo.svg", base_url),
|
||||
link: link.clone(),
|
||||
domain: base_url,
|
||||
year: Utc::now().year(),
|
||||
};
|
||||
|
||||
let template_html = include_str!("../.././templates/password_reset.html");
|
||||
let html = registry().render_template(template_html, &ctx).unwrap();
|
||||
|
||||
send_email(to, subject, plain, html)
|
||||
}
|
||||
|
||||
pub fn send_email(to: &str, subject: &str, header: String, html: String) -> ApiResult<()> {
|
||||
let to_address = to.parse::<Address>()?;
|
||||
let to_mailbox = Mailbox::new(None, to_address);
|
||||
|
||||
Reference in New Issue
Block a user