use chrono::{DateTime, Utc};
use serde::Serialize;
#[derive(Debug, Clone, Serialize)]
pub struct BackendUser {
pub id: i64,
pub username: String,
pub email: String,
pub first_name: String,
pub last_name: Option<String>,
#[serde(skip)]
pub password_hash: String,
pub is_superuser: bool,
pub is_active: bool,
pub timezone: Option<String>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
impl BackendUser {
pub fn full_name(&self) -> String {
match &self.last_name {
Some(last) if !last.is_empty() => format!("{} {}", self.first_name, last),
_ => self.first_name.clone(),
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct BackendUserSummary {
pub id: i64,
pub username: String,
pub email: String,
pub first_name: String,
pub last_name: Option<String>,
pub is_superuser: bool,
pub is_active: bool,
pub created_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AccessEvent {
LoginSuccess,
LoginFailure,
LockedOut,
Logout,
}
impl AccessEvent {
pub fn as_str(self) -> &'static str {
match self {
AccessEvent::LoginSuccess => "login_success",
AccessEvent::LoginFailure => "login_failure",
AccessEvent::LockedOut => "locked_out",
AccessEvent::Logout => "logout",
}
}
}