register user small fix
This commit is contained in:
BIN
db/1.sqlite-shm
BIN
db/1.sqlite-shm
Binary file not shown.
BIN
db/auth_copy_2.sqlite-shm
Normal file
BIN
db/auth_copy_2.sqlite-shm
Normal file
Binary file not shown.
BIN
db/auth_copy_2.sqlite-wal
Normal file
BIN
db/auth_copy_2.sqlite-wal
Normal file
Binary file not shown.
@@ -136,7 +136,8 @@ fn verify_password(password: &str, stored_hash: &str) -> bool {
|
|||||||
pub struct RegisterValues{
|
pub struct RegisterValues{
|
||||||
username: String,
|
username: String,
|
||||||
password: String,
|
password: String,
|
||||||
hotel_id: i32,
|
#[serde(default)]
|
||||||
|
hotel_ids: Vec<i32>, //-> :Vec!<32>, maybe optionnal ?
|
||||||
displayname: String,
|
displayname: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,10 +168,32 @@ pub async fn register_user (
|
|||||||
.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, "DB connection error"))?;
|
.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, "DB connection error"))?;
|
||||||
|
|
||||||
conn.execute(
|
conn.execute(
|
||||||
"INSERT INTO users (username, password, hotel_id, displayname) VALUES (?1, ?2, ?3, ?4)",
|
"INSERT INTO users (username, password, displayname) VALUES (?1, ?2, ?3)",
|
||||||
params![payload.username, hashed_password, payload.hotel_id, payload.displayname],
|
params![payload.username, hashed_password, payload.displayname],
|
||||||
)
|
)
|
||||||
.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, "DB insert error"))?;
|
.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, "DB insert error"))?;
|
||||||
|
|
||||||
|
let user_id = conn.last_insert_rowid();
|
||||||
|
for hotel_id in payload.hotel_ids {
|
||||||
|
|
||||||
|
// more logic for security here
|
||||||
|
//FIXME: needs to be the display name in the DB, scheme is currently wrong
|
||||||
|
|
||||||
|
let hotel_name = conn.execute(
|
||||||
|
"SELECT hotel_name
|
||||||
|
FROM hotels
|
||||||
|
WHERE id = ?1 ",
|
||||||
|
params![hotel_id],
|
||||||
|
).map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, "DB insert error"))?;
|
||||||
|
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO hotel_user_link (user_id, hotel_id, username, hotel_name) VALUES (?1, ?2, ?3, ?4)",
|
||||||
|
params![user_id, hotel_id, payload.username, hotel_name],
|
||||||
|
)
|
||||||
|
.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, "DB insert error"))?;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Ok((StatusCode::CREATED, "User registered successfully"))
|
Ok((StatusCode::CREATED, "User registered successfully"))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user