mirror of
https://github.com/perstarkse/minne.git
synced 2026-03-27 11:51:37 +01:00
feat: admin status, first user is admin, site settings
This commit is contained in:
52
src/server/routes/html/admin_panel.rs
Normal file
52
src/server/routes/html/admin_panel.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use axum::{
|
||||
extract::State,
|
||||
http::{StatusCode, Uri},
|
||||
response::{IntoResponse, Redirect},
|
||||
};
|
||||
use axum_htmx::HxRedirect;
|
||||
use axum_session_auth::AuthSession;
|
||||
use axum_session_surreal::SessionSurrealPool;
|
||||
use surrealdb::{engine::any::Any, Surreal};
|
||||
|
||||
use crate::{
|
||||
error::{AppError, HtmlError},
|
||||
page_data,
|
||||
server::{routes::html::render_template, AppState},
|
||||
storage::types::{analytics::Analytics, system_settings::SystemSettings, user::User},
|
||||
};
|
||||
|
||||
page_data!(AdminPanelData, "auth/admin_panel.html", {
|
||||
user: User,
|
||||
settings: SystemSettings,
|
||||
analytics: Analytics
|
||||
});
|
||||
|
||||
pub async fn show_admin_panel(
|
||||
State(state): State<AppState>,
|
||||
auth: AuthSession<User, String, SessionSurrealPool<Any>, Surreal<Any>>,
|
||||
) -> Result<impl IntoResponse, HtmlError> {
|
||||
// Early return if the user is not authenticated
|
||||
let user = match auth.current_user {
|
||||
Some(user) => user,
|
||||
None => return Ok(Redirect::to("/").into_response()),
|
||||
};
|
||||
|
||||
let settings = SystemSettings::get_current(&state.surreal_db_client)
|
||||
.await
|
||||
.map_err(|e| HtmlError::new(e, state.templates.clone()))?;
|
||||
let analytics = Analytics::get_current(&state.surreal_db_client)
|
||||
.await
|
||||
.map_err(|e| HtmlError::new(e, state.templates.clone()))?;
|
||||
|
||||
let output = render_template(
|
||||
AdminPanelData::template_name(),
|
||||
AdminPanelData {
|
||||
user,
|
||||
settings,
|
||||
analytics,
|
||||
},
|
||||
state.templates.clone(),
|
||||
)?;
|
||||
|
||||
Ok(output.into_response())
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use minijinja_autoreload::AutoReloader;
|
||||
use crate::error::{HtmlError, IntoHtmlError};
|
||||
|
||||
pub mod account;
|
||||
pub mod admin_panel;
|
||||
pub mod documentation;
|
||||
pub mod gdpr;
|
||||
pub mod index;
|
||||
|
||||
@@ -7,6 +7,7 @@ use axum::{
|
||||
use axum_htmx::{HxBoosted, HxRedirect};
|
||||
use axum_session_auth::AuthSession;
|
||||
use axum_session_surreal::SessionSurrealPool;
|
||||
use chrono::RoundingError;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use surrealdb::{engine::any::Any, Surreal};
|
||||
use tracing::info;
|
||||
@@ -59,8 +60,8 @@ pub async fn process_signup_and_show_verification(
|
||||
let user = match User::create_new(form.email, form.password, &state.surreal_db_client).await {
|
||||
Ok(user) => user,
|
||||
Err(e) => {
|
||||
info!("{:?}", e);
|
||||
return Ok(Html("<p>User already exists</p>").into_response());
|
||||
tracing::error!("{:?}", e);
|
||||
return Ok(Html(format!("<p>{}</p>", e)).into_response());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user