Fix docker (#3)
Rust Build / Test Suite (push) Successful in 1m20s
Rust Build / Check (push) Successful in 1m31s
Rust Build / Rustfmt (push) Successful in 33s
Rust Build / Clippy (push) Successful in 1m27s
Rust Build / build (push) Successful in 1m38s
Rust Build / Check (pull_request) Successful in 1m16s
Rust Build / Test Suite (pull_request) Successful in 1m34s
Rust Build / Rustfmt (pull_request) Successful in 36s
Rust Build / Clippy (pull_request) Successful in 1m53s
Rust Build / build (pull_request) Successful in 1m47s

Reviewed-on: phoenix/textsender-auth#3
This commit was merged in pull request #3.
This commit is contained in:
2026-06-07 18:45:08 -04:00
parent 5edeba0799
commit 27f4443818
12 changed files with 116 additions and 72 deletions
+2 -2
View File
@@ -3,6 +3,6 @@ pub mod register;
pub mod endpoints {
pub const ROOT: &str = "/";
pub const REGISTER: &str = "/api/v2/register";
pub const DBTEST: &str = "/api/v2/test/db";
pub const REGISTER: &str = "/api/v1/register";
pub const DBTEST: &str = "/api/v1/test/db";
}
+17 -13
View File
@@ -8,18 +8,15 @@ pub mod request {
#[derive(Default, Deserialize, Serialize, utoipa::ToSchema)]
pub struct Request {
#[serde(skip_serializing_if = "String::is_empty")]
pub username: String,
#[serde(skip_serializing_if = "String::is_empty")]
pub password: String,
#[serde(skip_serializing_if = "String::is_empty")]
pub email: String,
#[serde(skip_serializing_if = "String::is_empty")]
pub phone: String,
#[serde(skip_serializing_if = "String::is_empty")]
pub firstname: String,
#[serde(skip_serializing_if = "String::is_empty")]
pub lastname: String,
pub phone_number: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub firstname: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub lastname: Option<String>,
}
}
@@ -71,16 +68,19 @@ pub async fn register_user(
username: payload.username.clone(),
password: payload.password.clone(),
// email: payload.email.clone(),
phone_number: payload.phone.clone(),
firstname: payload.firstname.clone(),
lastname: payload.lastname.clone(),
phone_number: payload.phone_number.clone(),
// email_verified: true,
..Default::default()
};
user.firstname = payload.firstname.unwrap_or_default();
user.lastname = payload.lastname.unwrap_or_default();
println!("Checking if user exists");
match repo::user::exists(&pool, &user.username).await {
Ok(res) => {
if res {
println!("Already exists");
(
StatusCode::BAD_REQUEST,
Json(response::Response {
@@ -89,16 +89,20 @@ pub async fn register_user(
}),
)
} else {
println!("Good to create");
println!("Generate salt string");
let salt_string = hashing::generate_salt().unwrap();
let mut salt = textsender_models::user::Salt::default();
let generated_salt = salt_string;
salt.salt = generated_salt.to_string();
println!("Creating salt");
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;
println!("Creating user");
match repo::user::insert(&pool, &user).await {
Ok((id, date_created)) => {
user.id = id;
+19 -6
View File
@@ -15,7 +15,7 @@ pub mod user {
) -> Result<textsender_models::user::User, sqlx::Error> {
let result = sqlx::query(
r#"
SELECT * FROM "user" WHERE username = $1
SELECT id, username, password, phone_number, salt_id, firstname, lastname, created, last_login FROM "user" WHERE username = $1
"#,
)
.bind(username)
@@ -85,8 +85,21 @@ pub mod user {
.await;
match result {
Ok(r) => Ok(r.is_some()),
Err(e) => Err(e),
Ok(r) => match r {
Some(row) => {
if row.is_empty() {
Ok(false)
} else {
Ok(true)
}
}
None => Ok(false),
},
Err(e) => {
eprintln!("What??");
eprintln!("Error: {e:?}");
Err(e)
}
}
}
@@ -96,7 +109,7 @@ pub mod user {
) -> Result<(uuid::Uuid, std::option::Option<time::OffsetDateTime>), sqlx::Error> {
let row = sqlx::query(
r#"
INSERT INTO "user" (username, password, phone, firstname, lastname, salt_id)
INSERT INTO "user" (username, password, phone_number, firstname, lastname, salt_id)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id, created;
"#,
@@ -117,7 +130,7 @@ pub mod user {
let result = InsertedData {
id: row.try_get("id").map_err(|_e| sqlx::Error::RowNotFound)?,
date_created: row
.try_get("date_created")
.try_get("created")
.map_err(|_e| sqlx::Error::RowNotFound)?,
};
@@ -143,7 +156,7 @@ pub mod salt {
) -> Result<textsender_models::user::Salt, sqlx::Error> {
let result = sqlx::query(
r#"
SELECT * FROM "salt" WHERE id = $1
SELECT id, salt FROM "salt" WHERE id = $1
"#,
)
.bind(id)