This commit is contained in:
Martin Brodbeck 2023-09-26 12:48:53 +02:00
parent 41ece3063c
commit 2e8d3d2701

View file

@ -36,7 +36,7 @@ async fn root() -> &'static str {
"KOreader sync server"
}
async fn create_user(Json(payload): Json<User>) -> StatusCode {
async fn create_user(Json(payload): Json<User>) -> (StatusCode, String) {
let client = redis::Client::open("redis://127.0.0.1/").unwrap();
let mut con = client.get_connection().unwrap();
@ -50,10 +50,13 @@ async fn create_user(Json(payload): Json<User>) -> StatusCode {
if does_exist == false {
let _: () = con.set(&user_key, password).unwrap();
} else {
return StatusCode::PAYMENT_REQUIRED;
return (
StatusCode::PAYMENT_REQUIRED,
"Username is already registered.".to_owned(),
);
}
StatusCode::CREATED
(StatusCode::CREATED, format!("username = {username}"))
}
async fn auth_user(headers: HeaderMap) -> StatusCode {