use crate::AppState;
use crate::events::Event;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct Registered {
pub user_id: i64,
pub email: String,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct LoggedIn {
pub user_id: i64,
pub ip: Option<String>,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct LoginFailed {
pub email: String,
pub ip: Option<String>,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct LockedOut {
pub email: String,
pub ip: Option<String>,
pub seconds: u64,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct LoggedOut {
pub user_id: i64,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct PasswordReset {
pub user_id: i64,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct PasswordChanged {
pub user_id: i64,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct EmailVerified {
pub user_id: i64,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct ProfileUpdated {
pub user_id: i64,
pub email_changed: bool,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct OtherDevicesLoggedOut {
pub user_id: i64,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct AccountDeleted {
pub user_id: i64,
pub email: String,
}
impl Event for Registered {}
impl Event for LoggedIn {}
impl Event for LoginFailed {}
impl Event for LockedOut {}
impl Event for LoggedOut {}
impl Event for PasswordReset {}
impl Event for PasswordChanged {}
impl Event for EmailVerified {}
impl Event for ProfileUpdated {}
impl Event for OtherDevicesLoggedOut {}
impl Event for AccountDeleted {}
pub(crate) async fn announce<E: Event>(state: &AppState, event: E) {
if let Err(err) = state.emit(event).await {
tracing::error!(event = std::any::type_name::<E>(), error = ?err, "auth listener failed");
}
}