/
codemaster
/
a-pass-oauth
Обзор
Документация
Войти
/
codemaster
/
a-pass-oauth
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/session.rs
70 строк
2 KB
mich-master
2512
25 дек 2025, 13:51
25 дек 2025, 13:51
3273252
Код
Авторство
О чём код?
use chrono::{Utc, DateTime}; // use serde::{Deserialize, Serialize}; use uuid::Uuid; // #[derive(Debug)] // #[derive(Clone)] // pub enum SessionFlow { // Authenticaton, // Consent, // Run, // } #[derive(Debug)] #[derive(Clone)] #[allow(dead_code)] pub struct UserSession { pub session_id: String, pub user_id: String, pub username: String, pub created_at: DateTime<Utc>, pub expires_at: DateTime<Utc>, pub client_id: Option<String>, pub scope: Option<String>, pub is_authenticated: bool, pub is_consented: bool, // pub flow: SessionFlow, pub ip_address: Option<String>, pub user_agent: Option<String>, } impl UserSession { pub fn new( user_id: String, username: String, client_id: Option<String>, scope: Option<String>, ip_address: Option<String>, user_agent: Option<String>, session_duration_minutes: i64, ) -> Self { let now = Utc::now(); Self { session_id: Uuid::new_v4().to_string(), user_id, username, created_at: now, expires_at: now + chrono::Duration::minutes(session_duration_minutes), client_id, scope, is_authenticated: true, is_consented: false, // flow: SessionFlow::Authenticaton, ip_address, user_agent, } } pub fn is_valid(&self) -> bool { self.is_authenticated && Utc::now() < self.expires_at // Utc::now() < self.expires_at } pub fn refresh(&mut self, duration_minutes: i64) { self.expires_at = Utc::now() + chrono::Duration::minutes(duration_minutes); } pub fn set_consented(&mut self) { self.is_consented = true; } }