This commit is contained in:
2026-05-17 13:33:10 +02:00
parent b2cefb7d66
commit fed75d4820
54 changed files with 3845 additions and 51 deletions
+1 -1
View File
@@ -10,5 +10,5 @@ pub struct JoinRequest {
pub password: String,
#[validate(must_match(other = "password", message = "Passwords do not match"))]
pub password_valid: String,
pub super_admin_token: Option<String>,
pub superuser_token: Option<String>,
}
+13 -1
View File
@@ -7,6 +7,16 @@ use axum::extract::State;
use axum::http::StatusCode;
use axum::response::IntoResponse;
#[utoipa::path(
post,
path = "/join",
request_body = JoinRequest,
responses(
(status = 201, description = "User created successfully"),
(status = 400, description = "Validation error"),
),
tag = "Core"
)]
pub async fn join(
State(state): State<AppState>,
ValidatedJson(payload): ValidatedJson<JoinRequest>,
@@ -24,8 +34,10 @@ pub async fn join(
));
};
let user_am = join_request_to_user_am(payload)?;
let user_am = join_request_to_user_am(payload, state.init_token)?;
let user = state.repositories.user.create(user_am).await?;
state
.repositories
.server
+11 -1
View File
@@ -3,12 +3,22 @@ use crate::models::user;
use crate::routes::core::dto::JoinRequest;
use anyhow::Result as AnyResult;
use sea_orm::Set;
use uuid::Uuid;
pub fn join_request_to_user_am(
payload: JoinRequest,
superuser_token: Option<Uuid>,
) -> AnyResult<user::ActiveModel> {
let is_super_admin = match (payload.superuser_token.as_ref(), superuser_token) {
(Some(provided), Some(init)) => provided == &init.to_string(),
_ => false,
};
pub fn join_request_to_user_am(payload: JoinRequest) -> AnyResult<user::ActiveModel> {
Ok(user::ActiveModel {
id: Default::default(),
username: Set(payload.username),
password: Set(hash_password(&payload.password)?),
is_superuser: Set(is_super_admin),
..Default::default()
})
}
+2 -2
View File
@@ -1,7 +1,7 @@
use super::handlers;
use crate::http::OxRouter;
use axum::{routing::get, Router};
use axum::{routing::post, Router};
pub fn router() -> OxRouter {
Router::new().route("/join", get(handlers::join))
Router::new().route("/join", post(handlers::join))
}