Changing response
soaricarus_auth Build / Clippy (pull_request) Failing after 1m7s
soaricarus_auth Build / Rustfmt (pull_request) Successful in 1m10s
soaricarus_auth Build / Check (pull_request) Successful in 1m14s
soaricarus_auth Build / Test Suite (pull_request) Successful in 1m16s
soaricarus_auth Build / build (pull_request) Successful in 1m20s

This commit is contained in:
phoenix committed 2026-11-19 12:33:45 -05:00
1 parent 5f80b608ed
commit 610e4183f2
1 file changed
+30 -24
+30 -24
View File
@@ -29,7 +29,7 @@ pub mod response {
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
pub struct Response {
pub message: String,
pub data: Vec<simodels::user::User>,
pub data: Vec<simodels::register_result::RegisterResult>,
}
}
@@ -59,7 +59,7 @@ pub async fn register_user(
return (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
Json(response::Response {
message: String::from("Registration check failed"),
message: "Registration check failed".to_string(),
data: Vec::new(),
}),
);
@@ -67,19 +67,7 @@ pub async fn register_user(
};
if registration_enabled {
let mut user = simodels::user::User {
username: payload.username.clone(),
password: payload.password.clone(),
email: payload.email.clone(),
phone: payload.phone.clone(),
firstname: payload.firstname.clone(),
lastname: payload.lastname.clone(),
status: String::from("Active"),
email_verified: true,
..Default::default()
};
match repo::user::exists(&pool, &user.username).await {
match repo::user::exists(&pool, &payload.username).await {
Ok(res) => {
if res {
(
@@ -95,20 +83,38 @@ pub async fn register_user(
let generated_salt = salt_string;
salt.salt = generated_salt.to_string().clone();
salt.id = repo::salt::insert(&pool, &salt).await.unwrap();
user.salt_id = salt.id;
let hashed_password =
hashing::hash_password(&user.password, &generated_salt).unwrap();
user.password = hashed_password;
hashing::hash_password(&payload.password, &generated_salt).unwrap();
let user = simodels::user::User {
username: payload.username,
password: hashed_password,
email: payload.email,
phone: payload.phone,
firstname: payload.firstname,
lastname: payload.lastname,
status: "Active".to_string(),
salt_id: salt.id,
email_verified: true,
..Default::default()
};
match repo::user::insert(&pool, &user).await {
Ok((id, date_created)) => {
user.id = id;
user.date_created = date_created;
let user_id = id;
let date_created = date_created;
let register_user = simodels::register_result::RegisterResult {
id: user_id,
username: user.username,
email: user.email,
firstname: user.firstname,
lastname: user.lastname,
date_created,
};
(
StatusCode::CREATED,
Json(response::Response {
message: String::from("User created"),
data: vec![user],
message: "User created".to_string(),
data: vec![register_user],
}),
)
}
@@ -116,7 +122,7 @@ pub async fn register_user(
StatusCode::BAD_REQUEST,
Json(response::Response {
message: err.to_string(),
data: vec![user],
data: vec![],
}),
),
}
@@ -126,7 +132,7 @@ pub async fn register_user(
StatusCode::BAD_REQUEST,
Json(response::Response {
message: err.to_string(),
data: vec![user],
data: vec![],
}),
),
}