account management thingy

This commit is contained in:
Reid 2023-09-22 18:27:42 -07:00
parent b128f6549b
commit 8fde05a96d
Signed by: reidlab
GPG key ID: 6C9EAA3364F962C8
18 changed files with 251 additions and 18 deletions

View file

@ -58,7 +58,9 @@ fn rocket() -> _ {
template_endpoints::login::post_login,
template_endpoints::login::get_login,
template_endpoints::logout::logout,
template_endpoints::account_management::account_management,
template_endpoints::logout::logout
])
// assets
.mount("/", routes![

View file

@ -1,3 +1,4 @@
pub mod account_management;
pub mod index;
pub mod login;
pub mod logout;

View file

@ -0,0 +1,37 @@
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<Template, Redirect> {
let connection = &mut db::establish_connection_pg();
let (logged_in, username_val, _account_id_val, user_id_val) = crate::helpers::templates::auth!(cookies);
if logged_in {
use crate::schema::users::dsl::*;
use crate::models::User;
let result = users
.filter(id.eq(user_id_val.expect("user_id not found")))
.get_result::<User, >(connection)
.expect("couldnt find user with user id from account");
return Ok(Template::render("account_management", context! {
username: username_val.expect("username not found"),
stars: result.stars,
diamonds: result.diamonds,
coins: result.coins,
user_coins: result.user_coins,
demons: result.demons
}));
} else {
return Err(Redirect::to("/login"));
}
}

View file

@ -7,7 +7,7 @@ pub fn index() -> Template {
let silly_strings: Vec<&str> = vec![
"the trianges consume",
"geomtry das",
"now with no RCE!",
"now with no ACE!",
"the best gdps",
"better than topala",
"better than robtop",
@ -17,7 +17,21 @@ pub fn index() -> Template {
"kagepro",
"wowaka is peak music",
"you have been warned: dyno jun",
"listen to jin"
"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::<i32>().write(42) }",
"-1",
"[REDACTED]",
"chrome jop jop?",
"pikmin 4",
"italian apk downloader"
];
let mut rng = rand::thread_rng();

View file

@ -20,7 +20,7 @@ pub struct FormLogin {
}
#[post("/login", data = "<input>")]
pub fn post_login(jar: &CookieJar<'_>, input: Form<FormLogin>) -> Template {
pub fn post_login(cookies: &CookieJar<'_>, input: Form<FormLogin>) -> Template {
let connection = &mut db::establish_connection_pg();
use crate::schema::accounts::dsl::*;
@ -34,15 +34,15 @@ pub fn post_login(jar: &CookieJar<'_>, input: Form<FormLogin>) -> 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) => {
jar.add_private(Cookie::build(
cookies.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"

View file

@ -3,9 +3,7 @@ use rocket::response::Redirect;
#[post("/accounts/logout")]
pub fn logout(jar: &CookieJar<'_>) -> Redirect {
jar.remove_private(Cookie::named("username"));
jar.remove_private(Cookie::named("account_id"));
jar.remove_private(Cookie::named("user_id"));
jar.remove_private(Cookie::named("blackmail_data"));
Redirect::to("/")
}