openserve 2.0.3

A modern, high-performance, AI-enhanced file server built in Rust
Documentation
//! Authentication and authorization data models.

use serde::{Deserialize, Serialize};
use chrono::{DateTime, Utc};

/// Login request payload
#[derive(Debug, Clone, Deserialize)]
pub struct LoginRequest {
    /// Username for authentication
    pub username: String,
    /// User password
    pub password: String,
}

/// Registration request payload
#[derive(Debug, Clone, Deserialize)]
pub struct RegisterRequest {
    /// Desired username
    pub username: String,
    /// User email address
    pub email: String,
    /// User password
    pub password: String,
}

/// User information for API responses
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct User {
    /// Unique identifier for the user
    pub id: String,
    /// Username for the user
    pub username: String,
    /// Email address of the user
    pub email: String,
    /// Role assigned to the user
    pub role: UserRole,
    /// Timestamp when the user was created
    pub created_at: DateTime<Utc>,
    /// Last login timestamp
    pub last_login: Option<DateTime<Utc>>,
}

/// Available user roles in the system
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum UserRole {
    /// Administrator with full system access
    Admin,
    /// Regular user with standard access
    User,
    /// Read-only user with limited access
    ReadOnly,
}

/// JWT authentication token
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthToken {
    /// JWT access token
    pub token: String,
    /// Token expiration timestamp
    pub expires_at: DateTime<Utc>,
}

/// Claims embedded in JWT tokens
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Claims {
    /// Subject (user ID)
    pub sub: String,
    /// Token expiration timestamp
    pub exp: usize,
    /// Token issued at timestamp
    pub iat: usize,
    /// User role
    pub role: UserRole,
}