use std::sync::Arc; use config::AppConfig; use export::{AppDatabase, AppRedis, AppState}; use mailbaby::Email; use crate::errors::AuthError; pub mod access_keys; pub mod agreements; pub mod deletion; pub mod devices; pub mod email; pub mod login; pub mod logout; pub mod notifications; pub mod password; pub mod pow; pub mod preferences; pub mod profile; pub mod register; pub mod reports; pub mod sessions; pub mod ssh_keys; pub mod suspensions; pub mod two_factor; pub mod users; #[derive(Clone)] pub struct AuthService { pub state: AppState, } impl AuthService { pub fn new(state: AppState) -> Self { Self { state } } pub fn config(&self) -> &AppConfig { &self.state.config } pub fn db(&self) -> &Arc { &self.state.database } pub fn redis(&self) -> &AppRedis { &self.state.redis } pub async fn send_email( &self, to: &str, subject: &str, text: &str, html: &str, ) -> Result<(), AuthError> { let builder = Email::builder(subject).to([to]).text_body(text); let builder = if html.is_empty() { builder } else { builder.html_body(html) }; let email = builder .build() .map_err(|error| AuthError::Internal(format!("mail build failed: {error}")))?; self.state .email .send(&email) .await .map(|_| ()) .map_err(AuthError::from) } }