rust
Elnu 1 year ago
parent 94bd2da27b
commit a282d06bc5

@ -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(

@ -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() {

@ -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;

@ -1,4 +1,4 @@
use serde::{Serialize, Serializer, ser::SerializeStruct};
use serde::{ser::SerializeStruct, Serialize, Serializer};
use super::User;

@ -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("/<challenge>")]
pub async fn get_challenge(challenge: u32, cookies: &CookieJar<'_>) -> Template {

@ -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 {

@ -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};

@ -8,13 +8,21 @@ use crate::models::User;
#[get("/testing")]
pub async fn testing(cookies: &CookieJar<'_>, http: &State<Http>) -> 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)
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
)
}

@ -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<String>);

Loading…
Cancel
Save