This commit is contained in:
2026-06-09 23:05:35 +02:00
parent ee2fc42fff
commit eb2652f7e9
27 changed files with 665 additions and 538 deletions
+15 -1
View File
@@ -34,10 +34,24 @@ pub async fn join(
));
};
let user_am = join_request_to_user_am(payload, state.init_token)?;
let user_am = {
let init_token_lock = state
.init_token
.read()
.map_err(|e| HTTPError::InternalServerError(e.to_string()))?;
join_request_to_user_am(payload, *init_token_lock)?
};
let user = state.repositories.user.create(user_am).await?;
if user.is_superuser {
let mut init_token_lock = state
.init_token
.write()
.map_err(|e| HTTPError::InternalServerError(e.to_string()))?;
*init_token_lock = None;
}
state
.repositories
.server
+4 -5
View File
@@ -9,13 +9,12 @@ 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,
};
let mut is_super_admin = false;
if let (Some(provided), Some(init)) = (payload.superuser_token.as_ref(), superuser_token) {
is_super_admin = provided == &init.to_string();
}
Ok(user::ActiveModel {
id: Default::default(),
username: Set(payload.username),
password: Set(hash_password(&payload.password)?),
is_superuser: Set(is_super_admin),