Skip to content

Commit

Permalink
web: fix user password/audio theme setters
Browse files Browse the repository at this point in the history
  • Loading branch information
sre committed Nov 17, 2023
1 parent 938842d commit 80d2971
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/bin/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ async fn user_info(cookies: &CookieJar<'_>, id: i32) -> Result<Template, WebShop
}

#[post("/users/set-sound-theme/<userid>", format = "application/json", data = "<theme>")]
async fn user_sound_theme_set(cookies: &CookieJar<'_>, userid: i32, theme: String) -> Result<Json<bool>, Forbidden<String>> {
async fn user_sound_theme_set(cookies: &CookieJar<'_>, userid: i32, theme: Json<String>) -> Result<Json<bool>, Forbidden<String>> {
let session = match get_session(cookies).await {
Err(error) => { return Err(Forbidden(error.to_string())); },
Ok(session) => session,
Expand All @@ -1384,6 +1384,8 @@ async fn user_sound_theme_set(cookies: &CookieJar<'_>, userid: i32, theme: Strin
return Err(Forbidden("Missing Permission".to_string()));
}

let theme = theme.into_inner();

match set_user_theme(userid, &theme).await {
Err(error) => { return Err(Forbidden(error.to_string())); },
Ok(_) => {},
Expand All @@ -1393,7 +1395,7 @@ async fn user_sound_theme_set(cookies: &CookieJar<'_>, userid: i32, theme: Strin
}

#[post("/users/set-password/<userid>", format = "application/json", data = "<password>")]
async fn user_password_set(cookies: &CookieJar<'_>, userid: i32, password: String) -> Result<Json<bool>, Forbidden<String>> {
async fn user_password_set(cookies: &CookieJar<'_>, userid: i32, password: Json<String>) -> Result<Json<bool>, Forbidden<String>> {
let session = match get_session(cookies).await {
Err(error) => { return Err(Forbidden(error.to_string())); },
Ok(session) => session,
Expand All @@ -1403,10 +1405,14 @@ async fn user_password_set(cookies: &CookieJar<'_>, userid: i32, password: Strin
return Err(Forbidden("Missing Permission".to_string()));
}

let password = password.into_inner();

if password.is_empty() {
return Ok(Json(false));
}

print!("user: '{}', password: '{}'\n", userid, password);

match set_user_password(userid, &password).await {
Err(error) => { return Err(Forbidden(error.to_string())); },
Ok(_) => {},
Expand Down

0 comments on commit 80d2971

Please sign in to comment.