refactor: using word depot in rear instead of admin

This commit is contained in:
2024-07-20 09:34:51 +02:00
parent a26e17a064
commit 966291dbd9
38 changed files with 1112 additions and 72 deletions

View File

@@ -1,14 +1,13 @@
use async_trait::async_trait;
use log::debug;
use rear::admin::domain::*;
use rear::admin::state::AdminRegistry;
use rear::depot::prelude::*;
use sea_orm::{ActiveModelTrait, DatabaseConnection, EntityTrait, ModelTrait, Set};
use serde_json::Value;
use crate::models::UserRepository;
#[async_trait]
impl AdminRepository for UserRepository {
impl DepotRepository for UserRepository {
type Key = i64;
fn key_from_string(&self, s: String) -> Option<Self::Key> {
@@ -202,11 +201,11 @@ impl AdminRepository for UserRepository {
}
}
pub fn register(registry: &mut AdminRegistry, db: DatabaseConnection) -> UserRepository {
let app_key = registry.register_app("Auth");
pub fn register(registry: &mut DepotRegistry, db: DatabaseConnection) -> UserRepository {
let section_key = registry.register_section("Auth");
let repo = UserRepository::new(db);
let model_config = AdminModelConfig {
app_key: app_key,
let model_config = DepotModelConfig {
section_key: section_key,
name: "User".to_owned(),
};
let model_result = registry.register_model(model_config, repo.clone());

View File

@@ -23,7 +23,7 @@ pub struct NextUrl {
next: Option<String>,
}
pub fn routes<S: rear::admin::state::AdminState + Clone + Send + Sync + 'static>() -> Router<S>
pub fn routes<S: rear::depot::state::DepotState + Clone + Send + Sync + 'static>() -> Router<S>
where {
Router::new()
.route("/login", post(self::post::login))
@@ -44,7 +44,7 @@ mod post {
Ok(None) => {
messages.error("Invalid credentials");
let mut login_url = "/admin/login".to_string();
let mut login_url = "/depot/login".to_string();
if let Some(next) = creds.next {
login_url = format!("{}?next={}", login_url, next);
};
@@ -70,7 +70,7 @@ mod post {
pub async fn logout(mut auth_session: AuthSession) -> impl IntoResponse {
match auth_session.logout().await {
Ok(_) => Redirect::to("/admin/login").into_response(),
Ok(_) => Redirect::to("/depot/login").into_response(),
Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
}
}
@@ -80,7 +80,7 @@ mod get {
use super::*;
use axum::extract::State;
pub async fn login<S: rear::admin::state::AdminState + Clone + Send + Sync + 'static>(
pub async fn login<S: rear::depot::state::DepotState + Clone + Send + Sync + 'static>(
messages: Messages,
admin: State<S>,
Query(NextUrl { next }): Query<NextUrl>,
@@ -90,7 +90,7 @@ mod get {
messages: messages.into_iter().collect(),
next,
};
templates.render_html("admin/login.html", context)
templates.render_html("depot/login.html", context)
}
}