Skip to content

Commit

Permalink
fix: user info pretreatment
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaBosak233 committed Jan 26, 2025
1 parent 5e66bc4 commit 32d8072
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
4 changes: 3 additions & 1 deletion crates/db/src/transfer/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async fn preload(mut users: Vec<User>) -> Result<Vec<User>, DbErr> {
}

pub async fn find(
id: Option<i64>, name: Option<String>, username: Option<String>, group: Option<String>,
id: Option<i64>, name: Option<String>, username: Option<String>, group: Option<Group>,
email: Option<String>, page: Option<u64>, size: Option<u64>,
) -> Result<(Vec<User>, u64), DbErr> {
let mut sql = entity::user::Entity::find();
Expand Down Expand Up @@ -110,6 +110,8 @@ pub async fn find(
sql = sql.filter(entity::user::Column::Email.eq(email));
}

sql = sql.filter(entity::user::Column::IsDeleted.eq(false));

let total = sql.clone().count(get_db()).await?;

if let (Some(page), Some(size)) = (page, size) {
Expand Down
24 changes: 10 additions & 14 deletions crates/web/src/router/api/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,25 @@ use axum::{
response::{IntoResponse, Redirect},
};
use sea_orm::ActiveModelTrait;
use serde::{Deserialize, Serialize};

use serde_json::json;
use crate::traits::{WebError, WebResponse};

pub fn router() -> Router {
Router::new()
.route("/meta", axum::routing::get(get_meta))
.route("/", axum::routing::get(get))
.route("/icon", axum::routing::get(get_icon))
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Meta {
pub title: String,
pub description: String,
}

pub async fn get_meta() -> Result<WebResponse<Meta>, WebError> {
pub type ClientConfig = serde_json::Value;
pub async fn get() -> Result<WebResponse<ClientConfig>, WebError> {
Ok(WebResponse {
code: StatusCode::OK.as_u16(),
data: Some(Meta {
title: cds_config::get_config().meta.title,
description: cds_config::get_config().meta.description,
}),
data: Some(json!({
"meta": {
"title": cds_config::get_config().meta.title,
"description": cds_config::get_config().meta.description,
},
})),
..WebResponse::default()
})
}
Expand Down
10 changes: 9 additions & 1 deletion crates/web/src/router/api/user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct GetRequest {
pub id: Option<i64>,
pub name: Option<String>,
pub email: Option<String>,
pub group: Option<String>,
pub group: Option<cds_db::entity::user::Group>,
pub page: Option<u64>,
pub size: Option<u64>,
}
Expand Down Expand Up @@ -156,6 +156,14 @@ pub async fn update(
return Err(WebError::Forbidden(json!("")));
}

if let Some(email) = body.email {
body.email = Some(email.to_lowercase());
}

if let Some(username) = body.username {
body.username = Some(username.to_lowercase());
}

if let Some(password) = body.password {
let hashed_password = Argon2::default()
.hash_password(password.as_bytes(), &SaltString::generate(&mut OsRng))
Expand Down

0 comments on commit 32d8072

Please sign in to comment.