use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[deprecated(
since = "0.1.0-rc.15",
note = "Use AuthIdentity + BaseUser/FullUser + PermissionsMixin instead"
)]
pub trait User: Send + Sync {
fn id(&self) -> String;
fn username(&self) -> &str;
fn get_username(&self) -> &str {
self.username()
}
fn is_authenticated(&self) -> bool;
fn is_active(&self) -> bool;
fn is_admin(&self) -> bool;
fn is_staff(&self) -> bool;
fn is_superuser(&self) -> bool;
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SimpleUser {
pub id: Uuid,
pub username: String,
pub email: String,
pub is_active: bool,
pub is_admin: bool,
pub is_staff: bool,
pub is_superuser: bool,
}
#[allow(deprecated)] impl User for SimpleUser {
fn id(&self) -> String {
self.id.to_string()
}
fn username(&self) -> &str {
&self.username
}
fn is_authenticated(&self) -> bool {
true
}
fn is_active(&self) -> bool {
self.is_active
}
fn is_admin(&self) -> bool {
self.is_admin
}
fn is_staff(&self) -> bool {
self.is_staff
}
fn is_superuser(&self) -> bool {
self.is_superuser
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AnonymousUser;
#[allow(deprecated)] impl User for AnonymousUser {
fn id(&self) -> String {
String::new()
}
fn username(&self) -> &str {
""
}
fn is_authenticated(&self) -> bool {
false
}
fn is_active(&self) -> bool {
false
}
fn is_admin(&self) -> bool {
false
}
fn is_staff(&self) -> bool {
false
}
fn is_superuser(&self) -> bool {
false
}
}