Saving code
This commit is contained in:
+2
-2
@@ -3,6 +3,6 @@ pub mod register;
|
|||||||
|
|
||||||
pub mod endpoints {
|
pub mod endpoints {
|
||||||
pub const ROOT: &str = "/";
|
pub const ROOT: &str = "/";
|
||||||
pub const REGISTER: &str = "/api/v2/register";
|
pub const REGISTER: &str = "/api/v1/register";
|
||||||
pub const DBTEST: &str = "/api/v2/test/db";
|
pub const DBTEST: &str = "/api/v1/test/db";
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-13
@@ -8,18 +8,15 @@ pub mod request {
|
|||||||
|
|
||||||
#[derive(Default, Deserialize, Serialize, utoipa::ToSchema)]
|
#[derive(Default, Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
pub struct Request {
|
pub struct Request {
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub username: String,
|
pub username: String,
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
|
||||||
pub password: String,
|
pub password: String,
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
pub phone_number: String,
|
||||||
pub email: String,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
pub email: Option<String>,
|
||||||
pub phone: String,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
pub firstname: Option<String>,
|
||||||
pub firstname: String,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
pub lastname: Option<String>,
|
||||||
pub lastname: String,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,13 +68,20 @@ pub async fn register_user(
|
|||||||
username: payload.username.clone(),
|
username: payload.username.clone(),
|
||||||
password: payload.password.clone(),
|
password: payload.password.clone(),
|
||||||
// email: payload.email.clone(),
|
// email: payload.email.clone(),
|
||||||
phone_number: payload.phone.clone(),
|
phone_number: payload.phone_number.clone(),
|
||||||
firstname: payload.firstname.clone(),
|
|
||||||
lastname: payload.lastname.clone(),
|
|
||||||
// email_verified: true,
|
// email_verified: true,
|
||||||
..Default::default()
|
..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 {
|
match repo::user::exists(&pool, &user.username).await {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
if res {
|
if res {
|
||||||
|
|||||||
+21
-4
@@ -15,7 +15,7 @@ pub mod user {
|
|||||||
) -> Result<textsender_models::user::User, sqlx::Error> {
|
) -> Result<textsender_models::user::User, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
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)
|
.bind(username)
|
||||||
@@ -85,8 +85,25 @@ pub mod user {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => Ok(r.is_some()),
|
Ok(r) => {
|
||||||
Err(e) => Err(e),
|
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> {
|
) -> Result<(uuid::Uuid, std::option::Option<time::OffsetDateTime>), sqlx::Error> {
|
||||||
let row = sqlx::query(
|
let row = sqlx::query(
|
||||||
r#"
|
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)
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
RETURNING id, created;
|
RETURNING id, created;
|
||||||
"#,
|
"#,
|
||||||
|
|||||||
Reference in New Issue
Block a user