update account settings is real!

This commit is contained in:
Reid 2023-09-06 17:10:46 -07:00
parent 1dd0f382d0
commit 29bd670a57
Signed by: reidlab
GPG key ID: 6C9EAA3364F962C8
5 changed files with 69 additions and 4 deletions

View file

@ -39,4 +39,4 @@ _these features are implemented_
- in our level parsing, check for dual portals rather than just starting dual
- <small>green name users...</small>
- add more old endpoints
- add events, weekly, daily
- better support for older versions

View file

@ -1,2 +1,3 @@
pub mod login_account;
pub mod register_account;
pub mod register_account;
pub mod update_account_settings;

View file

@ -0,0 +1,63 @@
use rocket::form::Form;
use rocket::http::Status;
use rocket::response::status;
use diesel::prelude::*;
use crate::helpers;
use crate::db;
#[derive(FromForm)]
pub struct FormUpdateAccountSettings {
accountID: i32,
mS: i32,
frS: i32,
cS: i32,
yt: String,
twitter: String,
twitch: String,
password: Option<String>,
gjp: Option<String>,
gjp2: Option<String>,
}
#[post("/updateGJAccSettings20.php", data = "<input>")]
pub fn update_account_settings(input: Form<FormUpdateAccountSettings>) -> status::Custom<&'static str> {
let connection = &mut db::establish_connection_pg();
// account verification
let (_user_id_val, account_id_val): (i32, i32);
// password argument is used for the level, so
match helpers::accounts::auth(input.accountID.clone(), input.password.clone(), input.gjp.clone(), input.gjp2.clone()) {
Ok((user_id, account_id)) => {
_user_id_val = user_id;
account_id_val = account_id;
},
Err(_) => return status::Custom(Status::Ok, "-1")
};
use crate::models::Account;
{
use crate::schema::accounts::dsl::*;
diesel::update(accounts)
.filter(id.eq(account_id_val))
.set((
messages_enabled.eq(input.mS.clamp(0, 2)),
friend_requests_enabled.eq(input.frS.clamp(0, 1)),
comments_enabled.eq(input.cS.clamp(0, 2)),
youtube_url.eq(input.yt.chars().take(20).collect::<String>()),
twitch_url.eq(input.twitch.chars().take(25).collect::<String>()),
twitter_url.eq(input.twitter.chars().take(15).collect::<String>())
))
.get_result::<Account, >(connection)
.expect("failed to update account");
}
return status::Custom(Status::Ok, "1")
}

View file

@ -164,7 +164,7 @@ pub fn upload_level(input: Form<FormUploadLevel>) -> status::Custom<&'static str
Some(requested_stars_val) => requested_stars_val.clamp(0, 10),
None => 0
},
unlisted: input.unlisted.unwrap_or(0),
unlisted: input.unlisted.unwrap_or(0).clamp(0, 1),
version: input.levelVersion,
extra_data: extra_string.as_bytes().to_owned(),
level_info: input.levelInfo.clone().into_bytes(),
@ -175,7 +175,7 @@ pub fn upload_level(input: Form<FormUploadLevel>) -> status::Custom<&'static str
length_real: level_length_secs,
objects: objects_val as i32,
coins: coins_val as i32,
has_ldm: input.ldm.unwrap_or(0),
has_ldm: input.ldm.unwrap_or(0).clamp(0, 1),
two_player: two_player_val
};

View file

@ -35,6 +35,7 @@ fn rocket() -> _ {
.mount(CONFIG.general.append_path.as_str(), routes![
endpoints::accounts::login_account::login_account,
endpoints::accounts::register_account::register_account,
endpoints::accounts::update_account_settings::update_account_settings,
endpoints::users::get_users::get_users,