d489716c9b
This commit introduces the foundation for web-based authentication and user interface. It includes: - **Session Management**: Securely handling user sessions using cryptographically generated tokens, cookies with appropriate security flags, and server-side storage. - **Login/Logout Functionality**: Endpoints for users to log in with their credentials and log out, clearing their session. - **User Interface**: Basic templates for the login page, a list of cases, and a detailed view of a single case, allowing users to navigate and view their data. - **Authorization**: An `AuthenticatedWebUser` extractor to ensure only logged-in users can access protected web routes. - **Configuration**: Added a `cookie_secure` option to the configuration to control the `Secure` flag on session cookies, useful for local development. - **Dependencies**: Added necessary dependencies for password hashing, time handling, and TOML file manipulation. - **Helper Binary**: Included a `hash-password` binary to simplify generating bcrypt hashes for user passwords.
18 lines
350 B
Rust
18 lines
350 B
Rust
use std::collections::HashMap;
|
|
use std::sync::Arc;
|
|
use std::time::Instant;
|
|
|
|
use tokio::sync::RwLock;
|
|
|
|
pub struct WebSession {
|
|
pub slug: String,
|
|
pub role: String,
|
|
pub expires_at: Instant,
|
|
}
|
|
|
|
pub type SessionStore = Arc<RwLock<HashMap<String, WebSession>>>;
|
|
|
|
pub fn new_store() -> SessionStore {
|
|
Arc::new(RwLock::new(HashMap::new()))
|
|
}
|