From 574efc2252129206d3767eacf5f5d145c7cff91b Mon Sep 17 00:00:00 2001 From: realaravinth Date: Wed, 30 Jun 2021 20:57:26 +0530 Subject: [PATCH] email verification --- .github/workflows/coverage.yml | 8 +++++++ .github/workflows/linux.yml | 8 +++++++ config/default.toml | 3 ++- src/data.rs | 22 +++++++++++++++----- src/email/verification.rs | 6 ++++-- src/main.rs | 2 +- src/settings.rs | 1 + templates/email/components/footer/index.html | 2 -- 8 files changed, 41 insertions(+), 11 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 83afdb24..dcbe70b8 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -36,6 +36,14 @@ jobs: image: mcaptcha/cache ports: - 6379:6379 + smtp: + image: maildev/maildev + ports: + - 10025:1025 + - 1080:1080 + options: >- + --incoming-user admin + --incoming-pass password steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 50f9869b..11bf74cd 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -37,6 +37,14 @@ jobs: image: mcaptcha/cache ports: - 6379:6379 + smtp: + image: maildev/maildev + ports: + - 10025:1025 + - 1080:1080 + options: >- + --incoming-user admin + --incoming-pass password steps: diff --git a/config/default.toml b/config/default.toml index 8c6acce8..d42e7cfc 100644 --- a/config/default.toml +++ b/config/default.toml @@ -52,6 +52,7 @@ pool = 4 [smtp] from = "admin@localhost" reply_to = "admin@localhost" -url = "localhost:10025" +url = "127.0.0.1" +port = 10025 username = "admin" password = "password" diff --git a/src/data.rs b/src/data.rs index 3647b708..80c51876 100644 --- a/src/data.rs +++ b/src/data.rs @@ -19,6 +19,7 @@ use std::sync::Arc; use actix::prelude::*; use argon2_creds::{Config, ConfigBuilder, PasswordPolicy}; +use lettre::transport::smtp::authentication::Mechanism; use lettre::{ transport::smtp::authentication::Credentials, AsyncSmtpTransport, Tokio1Executor, }; @@ -159,7 +160,7 @@ impl Data { .unwrap(); log::info!("Initializing credential manager"); - creds.init(); + //creds.init(); log::info!("Initialized credential manager"); let data = Data { @@ -177,10 +178,21 @@ impl Data { let creds = Credentials::new(smtp.username.to_string(), smtp.password.to_string()); // "smtp_username".to_string(), "smtp_password".to_string()); - let mailer: Mailer = AsyncSmtpTransport::::relay(&smtp.url) //"smtp.gmail.com") - .unwrap() - .credentials(creds) - .build(); + let mailer: Mailer = + AsyncSmtpTransport::::builder_dangerous(&smtp.url) + .port(smtp.port) + .credentials(creds) + .authentication(vec![ + Mechanism::Login, + Mechanism::Xoauth2, + Mechanism::Plain, + ]) + .build(); + + // let mailer: Mailer = AsyncSmtpTransport::::relay(&smtp.url) //"smtp.gmail.com") + // .unwrap() + // .credentials(creds) + // .build(); Some(mailer) } else { None diff --git a/src/email/verification.rs b/src/email/verification.rs index 7b3f7b06..1eb7d039 100644 --- a/src/email/verification.rs +++ b/src/email/verification.rs @@ -102,9 +102,11 @@ mod tests { #[actix_rt::test] async fn email_verification_works() { - const TO_ADDR: &str = "Hello "; + const TO_ADDR: &str = "Hello "; const VERIFICATION_LINK: &str = "https://localhost"; let data = Data::new().await; - verification(&data, TO_ADDR, VERIFICATION_LINK).await.unwrap(); + verification(&data, TO_ADDR, VERIFICATION_LINK) + .await + .unwrap(); } } diff --git a/src/main.rs b/src/main.rs index e0884248..f03a1776 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ use log::info; mod api; mod data; mod docs; -//mod email; +mod email; mod errors; mod middleware; #[macro_use] diff --git a/src/settings.rs b/src/settings.rs index 8daf8ac8..3ddeb35e 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -45,6 +45,7 @@ pub struct Smtp { pub url: String, pub username: String, pub password: String, + pub port: u16, } impl Server { diff --git a/templates/email/components/footer/index.html b/templates/email/components/footer/index.html index dfcee43f..46bf357f 100644 --- a/templates/email/components/footer/index.html +++ b/templates/email/components/footer/index.html @@ -5,8 +5,6 @@