Extract user information from session

This commit is contained in:
2025-03-18 22:44:52 +01:00
parent ecd44dc16d
commit d5bb1acbcb
7 changed files with 108 additions and 6 deletions

View File

@ -1,5 +1,6 @@
use crate::app_config::AppConfig;
use crate::controllers::{HttpFailure, HttpResult};
use crate::extractors::auth_extractor::{AuthExtractor, AuthenticatedMethod};
use crate::extractors::money_session::MoneySession;
use crate::services::users_service;
use actix_remote_ip::RemoteIP;
@ -104,3 +105,23 @@ pub async fn finish_oidc(
Ok(HttpResponse::Ok().finish())
}
/// Get current user information
pub async fn auth_info(auth: AuthExtractor) -> HttpResult {
Ok(HttpResponse::Ok().json(auth.user))
}
/// Sign out user
pub async fn sign_out(auth: AuthExtractor, session: MoneySession) -> HttpResult {
match auth.method {
AuthenticatedMethod::Cookie => {
session.unset_current_user()?;
}
AuthenticatedMethod::Dev => {
// Nothing to be done, user is always authenticated
}
}
Ok(HttpResponse::NoContent().finish())
}