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 token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
let http = Http::new(&token); let http = Http::new(&token);
let config = rocket::Config::figment() let config = rocket::Config::figment().merge(("port", 1313)).merge((
.merge(("port", 1313)) "secret_key",
.merge(("secret_key", env::var("SECRET").expect("Must have SECRET defined in .env for private cookie persistence"))); env::var("SECRET")
.expect("Must have SECRET defined in .env for private cookie persistence"),
));
rocket::custom(config) rocket::custom(config)
.manage(http) .manage(http)
.mount( .mount(

@ -31,7 +31,8 @@ impl Challenge {
let arena = Arena::new(); let arena = Arena::new();
let root = parse_document( let root = parse_document(
&arena, &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, &options,
); );
if let Some(node) = root.children().next() { if let Some(node) = root.children().next() {

@ -6,7 +6,7 @@ mod tests;
use chrono::Utc; use chrono::Utc;
use derive_more::From; use derive_more::From;
use reqwest::StatusCode; use reqwest::StatusCode;
use rocket::http::{CookieJar, Cookie}; use rocket::http::{Cookie, CookieJar};
use serial::*; use serial::*;
use serde::Deserialize; use serde::Deserialize;

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

@ -1,7 +1,7 @@
use rocket::http::CookieJar; 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>")] #[get("/<challenge>")]
pub async fn get_challenge(challenge: u32, cookies: &CookieJar<'_>) -> Template { 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 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")] #[get("/logout")]
pub fn logout(cookies: &CookieJar<'_>, referer: Referer) -> Redirect { pub fn logout(cookies: &CookieJar<'_>, referer: Referer) -> Redirect {

@ -1,5 +1,9 @@
use chrono::{Utc, Duration}; use chrono::{Duration, Utc};
use rocket::{form::Form, http::{CookieJar, Cookie}, response::Redirect}; use rocket::{
form::Form,
http::{Cookie, CookieJar},
response::Redirect,
};
use crate::{cookies::token::TOKEN_EXPIRE_COOKIE, models::User}; use crate::{cookies::token::TOKEN_EXPIRE_COOKIE, models::User};

@ -8,13 +8,21 @@ use crate::models::User;
#[get("/testing")] #[get("/testing")]
pub async fn testing(cookies: &CookieJar<'_>, http: &State<Http>) -> String { pub async fn testing(cookies: &CookieJar<'_>, http: &State<Http>) -> String {
// Get logged in user's join date in 字ちゃん server // Get logged in user's join date in 字ちゃん server
format!("{:?}", http.get_guild(814700630958276649).await format!(
"{:?}",
http.get_guild(814700630958276649)
.await
.expect("Failed to get testing guild") .expect("Failed to get testing guild")
.member(http.deref(), User::get(cookies).await .member(
http.deref(),
User::get(cookies)
.await
.expect("Failed to get logged in user data") .expect("Failed to get logged in user data")
.expect("No logged in user") .expect("No logged in user")
.id .id
).await )
.await
.expect("Failed to fetch user in server") .expect("Failed to fetch user in server")
.joined_at) .joined_at
)
} }

@ -1,6 +1,9 @@
use std::convert::Infallible; use std::convert::Infallible;
use rocket::{request::{FromRequest, self}, Request}; use rocket::{
request::{self, FromRequest},
Request,
};
pub struct Referer(pub Option<String>); pub struct Referer(pub Option<String>);

Loading…
Cancel
Save