diff --git a/public/assets/icons/gd/coin.png b/public/assets/icons/gd/coin.png deleted file mode 100644 index c6ab23f..0000000 Binary files a/public/assets/icons/gd/coin.png and /dev/null differ diff --git a/public/assets/icons/gd/demon.png b/public/assets/icons/gd/demon.png deleted file mode 100644 index b6e46bc..0000000 Binary files a/public/assets/icons/gd/demon.png and /dev/null differ diff --git a/public/assets/icons/gd/diamond.png b/public/assets/icons/gd/diamond.png deleted file mode 100644 index 10b8a59..0000000 Binary files a/public/assets/icons/gd/diamond.png and /dev/null differ diff --git a/public/assets/icons/gd/silvercoin.png b/public/assets/icons/gd/silvercoin.png deleted file mode 100644 index 8c905ce..0000000 Binary files a/public/assets/icons/gd/silvercoin.png and /dev/null differ diff --git a/public/assets/icons/gd/star.png b/public/assets/icons/gd/star.png deleted file mode 100644 index 59bc2b1..0000000 Binary files a/public/assets/icons/gd/star.png and /dev/null differ diff --git a/public/favicon.png b/public/favicon.png index ea828db..9b562aa 100644 Binary files a/public/favicon.png and b/public/favicon.png differ diff --git a/public/style.css b/public/style.css index 2b07298..bee5c97 100644 --- a/public/style.css +++ b/public/style.css @@ -54,10 +54,6 @@ a { color: #a6e3a1; } -.dim { - color: #a6adc8; -} - .fancy-button { outline: 0; border: none; @@ -71,106 +67,4 @@ a { cursor: pointer; transition: 0.1s background-color; -} - -.fancy-button:hover { - background-color: #bad4fc; -} - -.inline-post { - display: inline; -} - -.inline-post-button { - display: inline; - background: none; - outline: none; - border: none; - color: inherit; - font-size: inherit; - font-weight: inherit; - text-decoration: underline; - cursor: pointer; - padding: 0; -} - -.greeting ::selection { - background-color: #11111b; - color: #cdd6f4; -} - -.greeting { - background-color: #89b4fa; - color: #11111b; - border-radius: 1.5em; - padding: 1em; - - display: flex; - flex-direction: row; - gap: 1rem; -} - -.greeting-l { - flex: 0 0 auto; - max-width: 100%; - width: auto; - height: 100%; - max-height: 3rem; - object-fit: contain; - display: block; -} - -.greeting-r { - flex: 1 1 0px; - min-width: 0; - - display: flex; - flex-direction: column; - justify-content: space-between; -} - -.greeting-top { - display: flex; - flex-direction: row; - align-items: center; - justify-content: space-between; -} - -.greeting-top-left { - font-size: 1.4rem; -} - -.greeting-stats { - display: flex; - flex-direction: row; - align-items: stretch; - gap: 0.5ex; -} - -.greeting-stats img { - width: auto; - height: 1em; -} - -.greeting a { - color: #11111b; -} - - -.header { - height: 96px; - max-width: 600px; - display: flex; - flex-direction: row; - align-items: center; - width: 100%; -} - -.header>.greeting { - flex: 1 1 0px; -} - -.favicon { - margin: auto; - display: block; } \ No newline at end of file diff --git a/readme.md b/readme.md index d7e5db5..26357f7 100644 --- a/readme.md +++ b/readme.md @@ -39,7 +39,4 @@ i've run out of ideas. - better song support - authentication caching (ip? redis?) - use log instead of println -- make a proper rank system (reuploading, uploading music, rating, etc.) -- user icons in the account management + settings (gdicon.oat.zone? selfhost?) -- account settings page -- better web design \ No newline at end of file +- make a proper rank system (reuploading, uploading music, rating, etc.) \ No newline at end of file diff --git a/src/helpers/templates.rs b/src/helpers/templates.rs index 1c8b0f1..20eac2e 100644 --- a/src/helpers/templates.rs +++ b/src/helpers/templates.rs @@ -1,18 +1,19 @@ -use rocket::http::CookieJar; +macro_rules! auth { + ($cookies: expr) => { + match $cookies.get_private("blackmail_data") { + Some(cookie_val) => { + let parts = cookie_val.value().split(":").collect::>(); -pub fn authenticate(cookies: &CookieJar<'_>) -> Result<(String, i32, i32), &'static str> { - match cookies.get_private("blackmail_data") { - Some(cookie) => { - let parts = cookie.value().split(":").collect::>(); - - let username = parts[0].to_string(); - let account_id = parts[1].parse::().expect("account id is not an integer! this should NOT happen!"); - let user_id = parts[2].parse::().expect("user id is not an integer! this should NOT happen!"); - - return Ok((username, account_id, user_id)) - } - None => { - return Err("authentication failed") + let username = parts[0].to_string(); + let account_id = parts[1].parse::().expect("account id is not an integer! this should NOT happen!"); + let user_id = parts[2].parse::().expect("user id is not an integer! this should NOT happen!"); + + (true, Some(username), Some(account_id), Some(user_id)) + } + None => { + (false, None, None, None) + } } } -} \ No newline at end of file +} +pub(crate) use auth; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index dcf71dc..a0455ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,9 +58,7 @@ fn rocket() -> _ { template_endpoints::login::post_login, template_endpoints::login::get_login, - template_endpoints::account_management::account_management, - - template_endpoints::logout::logout + template_endpoints::logout::logout, ]) // assets .mount("/", routes![ diff --git a/src/template_endpoints.rs b/src/template_endpoints.rs index 9c42b0e..89eada7 100644 --- a/src/template_endpoints.rs +++ b/src/template_endpoints.rs @@ -1,4 +1,3 @@ -pub mod account_management; pub mod index; pub mod login; pub mod logout; diff --git a/src/template_endpoints/account_management.rs b/src/template_endpoints/account_management.rs deleted file mode 100644 index 31a1ffe..0000000 --- a/src/template_endpoints/account_management.rs +++ /dev/null @@ -1,40 +0,0 @@ -use rocket::response::Redirect; - -use rocket_dyn_templates::{Template, context}; - -use rocket::http::CookieJar; - -use diesel::prelude::*; - -use crate::db; - -#[get("/accounts")] -pub fn account_management(cookies: &CookieJar<'_>) -> Result { - let connection = &mut db::establish_connection_pg(); - - let logged_in = crate::helpers::templates::authenticate(cookies); - - match logged_in { - Ok((username_val, account_id_val, user_id_val)) => { - use crate::schema::users::dsl::*; - use crate::models::User; - - let result = users - .filter(id.eq(user_id_val)) - .get_result::(connection) - .expect("couldnt find user with user id from account"); - - return Ok(Template::render("account_management", context! { - username: username_val, - stars: result.stars, - diamonds: result.diamonds, - coins: result.coins, - user_coins: result.user_coins, - demons: result.demons - })); - }, - Err(_) => { - return Err(Redirect::to("/login")); - } - } -} \ No newline at end of file diff --git a/src/template_endpoints/index.rs b/src/template_endpoints/index.rs index 47006e4..16fbe81 100644 --- a/src/template_endpoints/index.rs +++ b/src/template_endpoints/index.rs @@ -7,7 +7,7 @@ pub fn index() -> Template { let silly_strings: Vec<&str> = vec![ "the trianges consume", "geomtry das", - "now with no ACE!", + "now with no RCE!", "the best gdps", "better than topala", "better than robtop", @@ -17,21 +17,7 @@ pub fn index() -> Template { "kagepro", "wowaka is peak music", "you have been warned: dyno jun", - "listen to jin", - "GIVEUP!GIVEUP!GIVEUP!GIVEUP!GIVEUP!GIVEUP!LOVE!LOVE!GIVEUP!GIVEUP!GIVEUP!GIVEUP!GIVEUP!GIVEUP!", - "cross site scripting is a myth", - "VITAL STATE: Deceased - abducted by Pikmin", - "geometry dash for the 3ds", - "trans rights", - "how many maggots eat burger?", - "who would win: the rust borrow checker or rotting flesh", - "your system has run out of application memory", - "unsafe { std::ptr::null_mut::().write(42) }", - "-1", - "[REDACTED]", - "chrome jop jop?", - "pikmin 4", - "italian apk downloader" + "listen to jin" ]; let mut rng = rand::thread_rng(); diff --git a/src/template_endpoints/login.rs b/src/template_endpoints/login.rs index 227319c..96855e8 100644 --- a/src/template_endpoints/login.rs +++ b/src/template_endpoints/login.rs @@ -20,7 +20,7 @@ pub struct FormLogin { } #[post("/login", data = "")] -pub fn post_login(cookies: &CookieJar<'_>, input: Form) -> Template { +pub fn post_login(jar: &CookieJar<'_>, input: Form) -> Template { let connection = &mut db::establish_connection_pg(); use crate::schema::accounts::dsl::*; @@ -34,15 +34,15 @@ pub fn post_login(cookies: &CookieJar<'_>, input: Form) -> Template { Ok(account_id_username_val) => { match helpers::accounts::auth(account_id_username_val.0, Some(input.password.clone()), None, None) { Ok(account_id_user_id_val) => { - cookies.add_private(Cookie::build( + jar.add_private(Cookie::build( "blackmail_data", format!("{}:{}:{}", account_id_username_val.1, account_id_user_id_val.0, account_id_user_id_val.1)) - .path("/") - // should probably make this true when we get into production - .secure(false) - .http_only(true) - .max_age(Duration::days(365)) - .finish()); + .path("/") + // should probably make this true when we get into production + .secure(false) + .http_only(true) + .max_age(Duration::days(365)) + .finish()); return Template::render("login", context! { success: "Successfully logged in" @@ -65,14 +65,11 @@ pub fn post_login(cookies: &CookieJar<'_>, input: Form) -> Template { #[get("/login")] pub fn get_login(cookies: &CookieJar<'_>) -> Result { - let logged_in = crate::helpers::templates::authenticate(cookies); + let (logged_in, _username, _account_id, _user_id) = crate::helpers::templates::auth!(cookies); - match logged_in { - Ok(_) => { - return Ok(Redirect::to("/")) - }, - Err(_) => { - Err(Template::render("login", context! { })) - } + if logged_in { + Ok(Redirect::to("/")) + } else { + Err(Template::render("login", context! { })) } } \ No newline at end of file diff --git a/src/template_endpoints/logout.rs b/src/template_endpoints/logout.rs index 99566e6..83b0a28 100644 --- a/src/template_endpoints/logout.rs +++ b/src/template_endpoints/logout.rs @@ -3,7 +3,9 @@ use rocket::response::Redirect; #[post("/accounts/logout")] pub fn logout(jar: &CookieJar<'_>) -> Redirect { - jar.remove_private(Cookie::named("blackmail_data")); + jar.remove_private(Cookie::named("username")); + jar.remove_private(Cookie::named("account_id")); + jar.remove_private(Cookie::named("user_id")); Redirect::to("/") } \ No newline at end of file diff --git a/templates/account_management.html.hbs b/templates/account_management.html.hbs deleted file mode 100644 index 35aa150..0000000 --- a/templates/account_management.html.hbs +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - Home - - - -

- - Account Management -

-
-
- -
-
-
- hai, {{ username }}! -
-
- {{ stars }} {{ diamonds }} {{ coins }} {{ user_coins }} {{ demons }} -
-
-
- Settings · -
- -
-
-
-
-
-
- lorem ipsum sur dolor amet or something. i'll put stuff here later LOL -

- anyway how has ur day been -

- the demon should be your user icon haha, ill get 2 that latr :3 (gonna be next update i think) -
- - - \ No newline at end of file diff --git a/templates/index.html.hbs b/templates/index.html.hbs index 0eaf129..612426d 100644 --- a/templates/index.html.hbs +++ b/templates/index.html.hbs @@ -11,7 +11,7 @@

- + gdps-server

@@ -24,11 +24,10 @@
  • The Git repository
  • Level reuploading
  • -
  • Account stuff
  • -
    +
    {{ silly_string }}
    diff --git a/templates/login.html.hbs b/templates/login.html.hbs index 94c9fe5..127901b 100644 --- a/templates/login.html.hbs +++ b/templates/login.html.hbs @@ -34,7 +34,7 @@
    - +