Replace Rusqlite by Sqlx and Actix by Axum (A lot of changes)

This commit is contained in:
Greg Burri 2024-11-03 10:13:31 +01:00
parent 57d7e7a3ce
commit 980c5884a4
28 changed files with 2860 additions and 2262 deletions

View file

@ -1,6 +1,8 @@
use derive_more::Display;
use lettre::{transport::smtp::authentication::Credentials, Message, SmtpTransport, Transport};
use std::time::Duration;
use lettre::{
transport::smtp::{authentication::Credentials, AsyncSmtpTransport},
AsyncTransport, Message, Tokio1Executor,
};
use crate::consts;
@ -29,10 +31,11 @@ impl From<lettre::error::Error> for Error {
}
}
pub fn send_validation(
pub async fn send_validation(
site_url: &str,
email: &str,
token: &str,
smtp_relay_address: &str,
smtp_login: &str,
smtp_password: &str,
) -> Result<(), Error> {
@ -40,20 +43,20 @@ pub fn send_validation(
.message_id(None)
.from("recipes@gburri.org".parse()?)
.to(email.parse()?)
.subject("Recipes.gburri.org account validation")
.subject("recipes.gburri.org account validation")
.body(format!(
"Follow this link to confirm your inscription: {}/validation?token={}",
"Follow this link to confirm your inscription: {}/validation?validation_token={}",
site_url, token
))?;
let credentials = Credentials::new(smtp_login.to_string(), smtp_password.to_string());
let mailer = SmtpTransport::relay("mail.gandi.net")?
let mailer = AsyncSmtpTransport::<Tokio1Executor>::relay(smtp_relay_address)?
.credentials(credentials)
.timeout(Some(consts::SEND_EMAIL_TIMEOUT))
.build();
if let Err(error) = mailer.send(&email) {
if let Err(error) = mailer.send(email).await {
eprintln!("Error when sending E-mail:\n{:?}", &error);
}