mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
feat(admin): move pending registrations to their own page (#1388)
This commit is contained in:
1 parent
97b2ac91ca
commit
abcb5cb814
31 files changed
+839
-328
No files matched your search
@@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use crate::{
|
||||
api::types::{AdminUser, PremiumBranding},
|
||||
api::types::{AdminUser, AdminUserMeResponse, PremiumBranding},
|
||||
middleware::flash,
|
||||
session::{self, Session},
|
||||
state::AppState,
|
||||
@@ -16,6 +16,7 @@ use axum::{
|
||||
pub struct AuthContext {
|
||||
pub session: Session,
|
||||
pub admin_user: Option<AdminUser>,
|
||||
pub pending_registration_count: Option<u32>,
|
||||
pub branding: Option<PremiumBranding>,
|
||||
}
|
||||
|
||||
@@ -29,17 +30,19 @@ pub async fn require_auth(
|
||||
let Some(session) = session else {
|
||||
return Redirect::to(&format!("{}/auth/start", config.base_path)).into_response();
|
||||
};
|
||||
let admin_user = match fetch_admin_user(state.http_client(), config, &session).await {
|
||||
AdminFetchResult::Unauthorized => {
|
||||
let login_url = format!("{}/login", config.base_path);
|
||||
return clear_session_and_redirect(&login_url, config);
|
||||
}
|
||||
AdminFetchResult::Ok(admin_user) => Some(*admin_user),
|
||||
AdminFetchResult::None => None,
|
||||
};
|
||||
let (admin_user, pending_registration_count) =
|
||||
match fetch_admin_user(state.http_client(), config, &session).await {
|
||||
AdminFetchResult::Unauthorized => {
|
||||
let login_url = format!("{}/login", config.base_path);
|
||||
return clear_session_and_redirect(&login_url, config);
|
||||
}
|
||||
AdminFetchResult::Ok(me) => (Some(me.user), me.pending_registration_count),
|
||||
AdminFetchResult::None => (None, None),
|
||||
};
|
||||
request.extensions_mut().insert(AuthContext {
|
||||
session,
|
||||
admin_user,
|
||||
pending_registration_count,
|
||||
branding: state.self_hosted_branding().await,
|
||||
});
|
||||
|
||||
@@ -83,7 +86,7 @@ fn extract_session(request: &Request, secret_key: &str) -> Option<Session> {
|
||||
}
|
||||
|
||||
enum AdminFetchResult {
|
||||
Ok(Box<AdminUser>),
|
||||
Ok(Box<AdminUserMeResponse>),
|
||||
Unauthorized,
|
||||
None,
|
||||
}
|
||||
@@ -109,11 +112,8 @@ async fn fetch_admin_user(
|
||||
if !response.status().is_success() {
|
||||
return AdminFetchResult::None;
|
||||
}
|
||||
match response
|
||||
.json::<crate::api::types::AdminUserMeResponse>()
|
||||
.await
|
||||
{
|
||||
Ok(resp) => AdminFetchResult::Ok(Box::new(resp.user)),
|
||||
match response.json::<AdminUserMeResponse>().await {
|
||||
Ok(me) => AdminFetchResult::Ok(Box::new(me)),
|
||||
Err(_) => AdminFetchResult::None,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user