diff --git a/src/cookies.rs b/src/cookies.rs index f94c328..239ed95 100644 --- a/src/cookies.rs +++ b/src/cookies.rs @@ -7,4 +7,4 @@ pub mod user { pub const USER_NAME_COOKIE: &str = "user_name"; pub const USER_DISCRIMINATOR_COOKIE: &str = "user_discriminator"; pub const USER_AVATAR_COOKIE: &str = "user_avatar"; -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index b08cb35..8e41c2d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,9 +25,11 @@ async fn rocket() -> _ { let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment"); let http = Http::new(&token); - let config = rocket::Config::figment() - .merge(("port", 1313)) - .merge(("secret_key", env::var("SECRET").expect("Must have SECRET defined in .env for private cookie persistence"))); + let config = rocket::Config::figment().merge(("port", 1313)).merge(( + "secret_key", + env::var("SECRET") + .expect("Must have SECRET defined in .env for private cookie persistence"), + )); rocket::custom(config) .manage(http) .mount( diff --git a/src/models/challenge.rs b/src/models/challenge.rs index e2a46e5..99a9f39 100644 --- a/src/models/challenge.rs +++ b/src/models/challenge.rs @@ -31,7 +31,8 @@ impl Challenge { let arena = Arena::new(); let root = parse_document( &arena, - &fs::read_to_string(format!("content/challenges/{number}.md")).expect("Couldn't find challenge file"), + &fs::read_to_string(format!("content/challenges/{number}.md")) + .expect("Couldn't find challenge file"), &options, ); if let Some(node) = root.children().next() { @@ -48,7 +49,7 @@ impl Challenge { } } else { panic!("Empty document!") - } + } } } diff --git a/src/models/mod.rs b/src/models/mod.rs index c0f81eb..41f1ca0 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -2,4 +2,4 @@ mod user; pub use user::User; mod challenge; -pub use challenge::Challenge; \ No newline at end of file +pub use challenge::Challenge; diff --git a/src/models/user/mod.rs b/src/models/user/mod.rs index 778d614..4785a47 100644 --- a/src/models/user/mod.rs +++ b/src/models/user/mod.rs @@ -6,7 +6,7 @@ mod tests; use chrono::Utc; use derive_more::From; use reqwest::StatusCode; -use rocket::http::{CookieJar, Cookie}; +use rocket::http::{Cookie, CookieJar}; use serial::*; use serde::Deserialize; @@ -113,4 +113,4 @@ pub enum GetUserError { fn parse_cookie_value(cookies: &CookieJar<'_>, name: &str) -> Option { cookies.get_private(name)?.value().parse().ok() -} \ No newline at end of file +} diff --git a/src/models/user/serial.rs b/src/models/user/serial.rs index 582fd4d..466c6d9 100644 --- a/src/models/user/serial.rs +++ b/src/models/user/serial.rs @@ -1,4 +1,4 @@ -use serde::{Serialize, Serializer, ser::SerializeStruct}; +use serde::{ser::SerializeStruct, Serialize, Serializer}; use super::User; @@ -31,4 +31,4 @@ impl Serialize for User { state.serialize_field("username", &self.username())?; state.end() } -} \ No newline at end of file +} diff --git a/src/models/user/tests.rs b/src/models/user/tests.rs index ded0108..96f3db6 100644 --- a/src/models/user/tests.rs +++ b/src/models/user/tests.rs @@ -18,4 +18,4 @@ fn test_legacy_username() { fn test_new_username() { let user = test_user("test", 0); assert_eq!(user.username(), "test"); -} \ No newline at end of file +} diff --git a/src/prelude.rs b/src/prelude.rs index f3eebf3..df05737 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1 +1 @@ -pub use crate::utils::Kyujitai; \ No newline at end of file +pub use crate::utils::Kyujitai; diff --git a/src/routes/get_challenge.rs b/src/routes/get_challenge.rs index 8779a1f..4d10b69 100644 --- a/src/routes/get_challenge.rs +++ b/src/routes/get_challenge.rs @@ -1,7 +1,7 @@ use rocket::http::CookieJar; -use rocket_dyn_templates::{Template, context}; +use rocket_dyn_templates::{context, Template}; -use crate::models::{User, Challenge}; +use crate::models::{Challenge, User}; #[get("/")] pub async fn get_challenge(challenge: u32, cookies: &CookieJar<'_>) -> Template { @@ -19,4 +19,4 @@ pub async fn get_challenge(challenge: u32, cookies: &CookieJar<'_>) -> Template content: Challenge::get(challenge), }, ) -} \ No newline at end of file +} diff --git a/src/routes/login.rs b/src/routes/login.rs index ca76c73..910de68 100644 --- a/src/routes/login.rs +++ b/src/routes/login.rs @@ -10,4 +10,4 @@ pub fn login() -> Redirect { client_id = env::var("CLIENT_ID").unwrap(), redirect_uri = format!("{}success", env::var("DOMAIN").unwrap()), )) -} \ No newline at end of file +} diff --git a/src/routes/logout.rs b/src/routes/logout.rs index df5051f..1b46de4 100644 --- a/src/routes/logout.rs +++ b/src/routes/logout.rs @@ -2,7 +2,7 @@ use std::{collections::HashMap, env}; use rocket::{http::CookieJar, response::Redirect}; -use crate::{utils::Referer, cookies::token::TOKEN_COOKIE, models::User}; +use crate::{cookies::token::TOKEN_COOKIE, models::User, utils::Referer}; #[get("/logout")] pub fn logout(cookies: &CookieJar<'_>, referer: Referer) -> Redirect { @@ -33,4 +33,4 @@ pub fn logout(cookies: &CookieJar<'_>, referer: Referer) -> Redirect { User::purge(cookies); let redirect_url = referer.0.unwrap_or("/".to_owned()); Redirect::to(redirect_url) -} \ No newline at end of file +} diff --git a/src/routes/mod.rs b/src/routes/mod.rs index a8f5bf3..b2e2e50 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -20,4 +20,4 @@ pub use _success::success; #[path = "testing.rs"] mod _testing; -pub use _testing::testing; \ No newline at end of file +pub use _testing::testing; diff --git a/src/routes/post_login.rs b/src/routes/post_login.rs index 1ce1ac6..7be5462 100644 --- a/src/routes/post_login.rs +++ b/src/routes/post_login.rs @@ -1,5 +1,9 @@ -use chrono::{Utc, Duration}; -use rocket::{form::Form, http::{CookieJar, Cookie}, response::Redirect}; +use chrono::{Duration, Utc}; +use rocket::{ + form::Form, + http::{Cookie, CookieJar}, + response::Redirect, +}; use crate::{cookies::token::TOKEN_EXPIRE_COOKIE, models::User}; @@ -24,4 +28,4 @@ pub async fn post_login(login: Form>, cookies: &CookieJar<'_>) -> Redi )); } Redirect::to("/") -} \ No newline at end of file +} diff --git a/src/routes/success.rs b/src/routes/success.rs index 4f6e6fd..9c7e319 100644 --- a/src/routes/success.rs +++ b/src/routes/success.rs @@ -21,4 +21,4 @@ pub fn success() -> RawHtml<&'static str> { } ", ) -} \ No newline at end of file +} diff --git a/src/routes/testing.rs b/src/routes/testing.rs index 2deec8c..e62bbfc 100644 --- a/src/routes/testing.rs +++ b/src/routes/testing.rs @@ -8,13 +8,21 @@ use crate::models::User; #[get("/testing")] pub async fn testing(cookies: &CookieJar<'_>, http: &State) -> String { // Get logged in user's join date in 字ちゃん server - format!("{:?}", http.get_guild(814700630958276649).await - .expect("Failed to get testing guild") - .member(http.deref(), User::get(cookies).await - .expect("Failed to get logged in user data") - .expect("No logged in user") - .id - ).await - .expect("Failed to fetch user in server") - .joined_at) -} \ No newline at end of file + format!( + "{:?}", + http.get_guild(814700630958276649) + .await + .expect("Failed to get testing guild") + .member( + http.deref(), + User::get(cookies) + .await + .expect("Failed to get logged in user data") + .expect("No logged in user") + .id + ) + .await + .expect("Failed to fetch user in server") + .joined_at + ) +} diff --git a/src/utils/referer.rs b/src/utils/referer.rs index 8ce04a4..60c9cf1 100644 --- a/src/utils/referer.rs +++ b/src/utils/referer.rs @@ -1,6 +1,9 @@ use std::convert::Infallible; -use rocket::{request::{FromRequest, self}, Request}; +use rocket::{ + request::{self, FromRequest}, + Request, +}; pub struct Referer(pub Option); @@ -12,4 +15,4 @@ impl<'r> FromRequest<'r> for Referer { let referer = req.headers().get_one("Referer"); request::Outcome::Success(Referer(referer.map(|referer| referer.to_owned()))) } -} \ No newline at end of file +}