Saving code
This commit is contained in:
+2
-2
@@ -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
@@ -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,13 +68,20 @@ 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 = match payload.firstname {
|
||||
Some(firstname) => firstname,
|
||||
None => String::new()
|
||||
};
|
||||
user.lastname = match payload.lastname {
|
||||
Some(lastname) => lastname,
|
||||
None => String::new()
|
||||
};
|
||||
|
||||
match repo::user::exists(&pool, &user.username).await {
|
||||
Ok(res) => {
|
||||
if res {
|
||||
|
||||
+21
-4
@@ -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,25 @@ 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 +113,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;
|
||||
"#,
|
||||
|
||||
Reference in New Issue
Block a user