diff --git a/README.md b/README.md index 2b6d940..e289d5b 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,9 @@ A list of things that could be implemented/added to the application, some of the - [ ] Move the database queries to their own functions - [ ] Cache those results - [ ] Centralize Markdown parsing ? - - [ ] Use fairings for the different elements ? + - [x] Use fairings for the different elements - [ ] Use guards for User calls ? + - [ ] Use SQLite Row ID for User IDs rather than regular IDs, for randomness ? # Dependencies diff --git a/src/auth.rs b/src/auth.rs index eb56446..34c0bec 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -8,6 +8,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; use argon2::{Argon2, PasswordHash, PasswordVerifier}; use blake2::{Blake2b512, Digest}; use blake2::digest::FixedOutput; +use rocket::fairing::AdHoc; use crate::database_records::{AuthTokens, PlayerLoginInfo, Vote}; use crate::{database, week}; use database::Db; @@ -210,3 +211,9 @@ pub async fn logout(week: u8, mut db: Connection, cookies: &CookieJar<'_>) - Redirect::to(uri!(week::week(week))) } + +pub fn stage() -> AdHoc { + AdHoc::on_ignite("Auth stage", |rocket| async { + rocket.mount("/", routes![login, logout]) + }) +} diff --git a/src/main.rs b/src/main.rs index ac5bc3f..a7d56c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,13 +36,11 @@ async fn index(mut db: Connection) -> Redirect { fn rocket() -> _ { rocket::build() .mount("/", FileServer::from(relative!("static_files"))) - .mount("/", routes![index, - vote::fetch_vote_data, vote::vote, - truth::create_truth, truth::edit_truth, - week::week, week::update_week, week::set_last_week, week::create_week, - auth::login, auth::logout]) + .attach(auth::stage()) + .attach(week::stage()) + .attach(truth::stage()) + .attach(vote::stage()) + .mount("/", routes![index]) .attach(database::stage()) .attach(Template::fairing()) } - -// TODO: Random Row ID \ No newline at end of file diff --git a/src/truth.rs b/src/truth.rs index 861449c..b9df46a 100644 --- a/src/truth.rs +++ b/src/truth.rs @@ -5,6 +5,7 @@ use rocket::response::Redirect; use rocket_db_pools::{sqlx, Connection}; use pulldown_cmark::{Parser, Options}; +use rocket::fairing::AdHoc; use sqlx::Row; use crate::{auth, database, week}; @@ -110,3 +111,9 @@ pub async fn create_truth(week: u8, form: Form, Redirect::to(uri!(week::week(week))) } + +pub fn stage() -> AdHoc { + AdHoc::on_ignite("Truth stage", |rocket| async { + rocket.mount("/", routes![create_truth, edit_truth]) + }) +} diff --git a/src/vote.rs b/src/vote.rs index 7bd400f..ff1e555 100644 --- a/src/vote.rs +++ b/src/vote.rs @@ -164,9 +164,8 @@ pub async fn fetch_vote_data(week: u8, mut db: Connection, cookies Some(Json(VoteData{truth_count: truth_count, votes: vote_data})) } -// FIXME: pub fn stage() -> AdHoc { - AdHoc::on_ignite("SQLx Stage", |rocket| async { + AdHoc::on_ignite("Vote stage", |rocket| async { rocket.mount("/", routes![vote, fetch_vote_data]) }) } diff --git a/src/week.rs b/src/week.rs index 1eb52db..8744ce2 100644 --- a/src/week.rs +++ b/src/week.rs @@ -210,3 +210,9 @@ pub async fn create_week(week: u8, mut db: Connection, cookies: &CookieJar<' } } } + +pub fn stage() -> AdHoc { + AdHoc::on_ignite("Week stage", |rocket| async { + rocket.mount("/", routes![week, create_week, update_week, set_last_week]) + }) +}