From 39dfa6816ee715960ba5bd8cb73f9e4ed68fce08 Mon Sep 17 00:00:00 2001 From: Evie Viau Date: Thu, 20 Mar 2025 16:59:31 -0700 Subject: [PATCH] feature: Implement AUTH_URL for authservice emails Fixes #T116 --- authservice/src/main.rs | 3 +++ authservice/src/process/basic_accounts.rs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/authservice/src/main.rs b/authservice/src/main.rs index b57b85d..f04eaef 100644 --- a/authservice/src/main.rs +++ b/authservice/src/main.rs @@ -15,6 +15,7 @@ mod process; pub mod db; mod email; +use std::env; use std::string::ToString; use std::sync::Arc; use std::sync::atomic::{AtomicI64, AtomicU64, Ordering}; @@ -36,6 +37,8 @@ pub static SMTP_URL: Lazy = Lazy::new(|| std::env::var("SMTP_URL").expec pub static SMTP_USERNAME: Lazy = Lazy::new(|| std::env::var("SMTP_USERNAME").expect("NO SMTP_USERNAME DEFINED")); pub static SMTP_PASSWORD: Lazy = Lazy::new(|| std::env::var("SMTP_PASSWORD").expect("NO SMTP_PASSWORD DEFINED")); +pub static AUTH_URL: Lazy = Lazy::new(|| std::env::var("AUTH_URL").unwrap_or("https://auth.asklyphe.com".to_string())); + pub static PROCESSES_HANDLED: AtomicU64 = AtomicU64::new(0); pub static LAST_MESSAGE: AtomicI64 = AtomicI64::new(0); diff --git a/authservice/src/process/basic_accounts.rs b/authservice/src/process/basic_accounts.rs index bbefa51..fe6097b 100644 --- a/authservice/src/process/basic_accounts.rs +++ b/authservice/src/process/basic_accounts.rs @@ -21,7 +21,7 @@ use crate::db::{invite_code, session, user}; use crate::db::invite_code::ConsumeInviteCodeError; use crate::db::session::{CreateSessionError, DeleteSessionError, FetchSessionError}; use crate::db::user::{CreateUserError, DeleteUserError, EmailChangeError, FetchUserError, RegisterVerificationCodeError, VerifyEmailPassComboError, VerifyVerificationCodeError}; -use crate::email; +use crate::{email, AUTH_URL}; fn generate_email_verification_code() -> String { rand::thread_rng() @@ -121,7 +121,7 @@ pub async fn register_request(db: &DatabaseConnection, request: RegisterRequest) } debug!("verification code for {} is \"{}\"", request.username, verification_code); - email::send_verification_code_email(&request.email, &request.username, format!("https://auth.asklyphe.com/verify?username={}&token={}", request.username, verification_code).as_str()); + email::send_verification_code_email(&request.email, &request.username, format!("{}/verify?username={}&token={}", AUTH_URL.as_str(), request.username, verification_code).as_str()); RegisterResponse::Success }