Extract user information from session
This commit is contained in:
@ -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())
|
||||
}
|
||||
|
Reference in New Issue
Block a user