From 774d466dc012e2395ceee7f898b24789ccccec6c Mon Sep 17 00:00:00 2001 From: IMK Date: Tue, 8 Oct 2024 22:27:26 +0200 Subject: [PATCH] posts and stuff --- Cargo.lock | 1 + Cargo.toml | 3 +++ posts/newstuff/post.md | 11 +++++++++++ posts/newstuff/post_frontmatter.toml | 9 +++++++++ src/handlers/mod.rs | 3 ++- src/handlers/user_handler.rs | 7 +++---- src/lib.rs | 8 ++++---- 7 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 posts/newstuff/post.md create mode 100644 posts/newstuff/post_frontmatter.toml diff --git a/Cargo.lock b/Cargo.lock index 26441fe..92e1c32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -452,6 +452,7 @@ version = "0.1.0" dependencies = [ "actix-files", "actix-identity", + "actix-session", "actix-web", "base64 0.22.1", "dotenv", diff --git a/Cargo.toml b/Cargo.toml index cd1c0f5..d9be519 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] actix-files = "0.6.6" actix-identity = "0.8.0" +actix-session = {version = "0.10.1", features = ["cookie-session"]} actix-web = "4.9.0" base64 = "0.22.1" dotenv = "0.15.0" @@ -17,3 +18,5 @@ serde = {version = "1.0.210", features = ["derive"]} serde_json = "1.0.128" tera = "1.20.0" toml = "0.8.19" + +#[non_exhaustive] diff --git a/posts/newstuff/post.md b/posts/newstuff/post.md new file mode 100644 index 0000000..e58289d --- /dev/null +++ b/posts/newstuff/post.md @@ -0,0 +1,11 @@ +## hey... + +I had like school stuff so I couldn't really work on the website sowwy + +but I did some backend code for a login page so that's exciting and stuff + +thak you + +and also I made some music but I'll show that off in a later post when I figure out an efficient way toinclude something like webamp in posts + +thats alll bah bie :3 diff --git a/posts/newstuff/post_frontmatter.toml b/posts/newstuff/post_frontmatter.toml new file mode 100644 index 0000000..53ca3bb --- /dev/null +++ b/posts/newstuff/post_frontmatter.toml @@ -0,0 +1,9 @@ +title = 'BACK FROM THE DEAD YEAHH' +file_name = 'newstuff' +description = 'NO UPDATES FOR 3 DAYS??? UNSATISFACTORY' +tags = ["Rant"] +posted = '2024. oct. 08.' +estimated_reading_time = 1 +author = 'IMK' # feel free to swap with your own name +order = 1 +pinned = false diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index f8727aa..0e962c8 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -1,7 +1,8 @@ mod home_handler; mod post_handler; +mod user_handler; pub use home_handler::index; pub use post_handler::post; - +pub use user_handler::login; diff --git a/src/handlers/user_handler.rs b/src/handlers/user_handler.rs index c4bf859..595043e 100644 --- a/src/handlers/user_handler.rs +++ b/src/handlers/user_handler.rs @@ -1,10 +1,9 @@ use std::{fs, io::Error}; -use actix_web::{get, web, HttpResponse, Responder, HttpMessage}; +use actix_web::{get, web, HttpResponse, HttpMessage, Responder, HttpRequest, http::StatusCode}; use actix_identity::{Identity, IdentityMiddleware}; -use actix_session::{config::PresistentSession, storage::CookieSessionStore, SessionMiddleware}; -async fn login(req: HttpRequest) -> impl Responder{ - Identity::login(&req.extension(),"user1".to_owned()).unwrap(); +pub async fn login(req: HttpRequest) -> impl Responder{ + Identity::login(&req.extensions(),"user1".to_owned()).unwrap(); web::Redirect::to("/").using_status_code(StatusCode::FOUND) } diff --git a/src/lib.rs b/src/lib.rs index 592b585..9e1e32b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ use dotenv::dotenv; use actix_files::Files; use std::net::TcpListener; use actix_identity::{Identity, IdentityMiddleware}; -use actix_session::{config::PresistentSession, storage::CookieSessionStore, SessionMiddleware} +use actix_session::{config::PersistentSession, storage::CookieSessionStore, SessionMiddleware}; use actix_web::{dev::Server, web, http::StatusCode, HttpRequest, App, HttpResponse, HttpServer, middleware, cookie::{time::Duration, Key}}; use tera::Tera; use base64::prelude::*; @@ -38,15 +38,15 @@ pub fn start_blog(listener: TcpListener) -> Result{ .wrap(middleware::Logger::default()) .wrap(IdentityMiddleware::default()) .wrap( - SessionMiddleware::builder(CookieSessionStore::default(), secret_key.clone) + SessionMiddleware::builder(CookieSessionStore::default(), secret_key.clone()) .cookie_name("auth".to_owned()) .cookie_secure(false) - .session_lifecycle(PresistentSession::default().session_ttl(SES_TIME)) + .session_lifecycle(PersistentSession::default().session_ttl(SES_TIME)) .build() ) .service(Files::new("/static","static/").use_last_modified(true)) .route("/health", web::get().to(HttpResponse::Ok)) - .route("/login", web::post().to(login)) + .route("/login", web::post().to(handlers::login)) .service(handlers::index) .service(handlers::post) })