diff --git a/Cargo.lock b/Cargo.lock index 726f8a1c11f204f6cde1a5418c7d7d92075e7eab..2d2adef0fad1c2607c221a3383c85a481b1b0a53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2308,8 +2308,8 @@ dependencies = [ [[package]] name = "rauth" -version = "0.2.2" -source = "git+https://gitlab.insrt.uk/insert/rauth?rev=73fd602f0aba3d3689307fb1f811f211422fb4d3#73fd602f0aba3d3689307fb1f811f211422fb4d3" +version = "0.2.4" +source = "git+https://gitlab.insrt.uk/insert/rauth?rev=8c96882057f85d950578a6324abf1f7268862edd#8c96882057f85d950578a6324abf1f7268862edd" dependencies = [ "chrono", "handlebars", @@ -2319,6 +2319,7 @@ dependencies = [ "mongodb", "nanoid", "regex", + "reqwest", "rocket", "rocket_contrib", "rust-argon2", @@ -2453,7 +2454,7 @@ dependencies = [ [[package]] name = "revolt" -version = "0.3.3-alpha.1" +version = "0.3.3-alpha.2" dependencies = [ "async-std", "async-tungstenite", diff --git a/Cargo.toml b/Cargo.toml index be0b430e6ebb0e64c350117e2608b46b499760a1..fb53456aa5d2c19d25a57674a0e5f930b31cee6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "revolt" -version = "0.3.3-alpha.1" +version = "0.3.3-alpha.2" authors = ["Paul Makles <paulmakles@gmail.com>"] edition = "2018" @@ -13,7 +13,7 @@ many-to-many = "0.1.2" ctrlc = { version = "3.0", features = ["termination"] } async-std = { version = "1.8.0", features = ["tokio02", "attributes"] } async-tungstenite = { version = "0.10.0", features = ["async-std-runtime"] } -rauth = { git = "https://gitlab.insrt.uk/insert/rauth", rev = "73fd602f0aba3d3689307fb1f811f211422fb4d3" } +rauth = { git = "https://gitlab.insrt.uk/insert/rauth", rev = "8c96882057f85d950578a6324abf1f7268862edd" } hive_pubsub = { version = "0.4.3", features = ["mongo"] } rocket_cors = { git = "https://github.com/insertish/rocket_cors", branch = "master" } diff --git a/src/main.rs b/src/main.rs index 019ca0a68f7e3dfaca44cd726630364db0e7fc95..e1cc438adb5ff4dfc3f002fe2ae248768c2a50ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,12 +21,16 @@ pub mod util; use chrono::Duration; use futures::join; use log::info; -use rauth::{auth::Auth, options::{Template, Templates}}; use rauth::options::{EmailVerification, Options, SMTP}; +use rauth::{ + auth::Auth, + options::{Template, Templates}, +}; use rocket_cors::AllowedOrigins; use rocket_prometheus::PrometheusMetrics; use util::variables::{ - PUBLIC_URL, SMTP_FROM, SMTP_HOST, SMTP_PASSWORD, SMTP_USERNAME, USE_EMAIL, USE_PROMETHEUS, APP_URL, INVITE_ONLY + APP_URL, HCAPTCHA_KEY, INVITE_ONLY, PUBLIC_URL, SMTP_FROM, SMTP_HOST, SMTP_PASSWORD, + SMTP_USERNAME, USE_EMAIL, USE_HCAPTCHA, USE_PROMETHEUS, }; #[async_std::main] @@ -61,49 +65,51 @@ async fn launch_web() { .to_cors() .expect("Failed to create CORS."); - let auth = Auth::new( - database::get_collection("accounts"), - if *INVITE_ONLY { - Options::new() - .invite_only_collection(database::get_collection("invites")) - } else { - Options::new() - } - .base_url(format!("{}/auth", *PUBLIC_URL)) - .email_verification(if *USE_EMAIL { - EmailVerification::Enabled { - success_redirect_uri: format!("{}/login", *APP_URL), - welcome_redirect_uri: format!("{}/welcome", *APP_URL), - password_reset_url: Some(format!("{}/login/reset", *APP_URL)), - - verification_expiry: Duration::days(1), - password_reset_expiry: Duration::hours(1), - - templates: Templates { - verify_email: Template { - title: "Verify your REVOLT account.", - text: "Verify your email here: {{url}}", - html: include_str!("../assets/templates/verify.html") - }, - reset_password: Template { - title: "Reset your REVOLT password.", - text: "Reset your password here: {{url}}", - html: include_str!("../assets/templates/reset.html") - }, - welcome: None + let mut options = Options::new() + .base_url(format!("{}/auth", *PUBLIC_URL)) + .email_verification(if *USE_EMAIL { + EmailVerification::Enabled { + success_redirect_uri: format!("{}/login", *APP_URL), + welcome_redirect_uri: format!("{}/welcome", *APP_URL), + password_reset_url: Some(format!("{}/login/reset", *APP_URL)), + + verification_expiry: Duration::days(1), + password_reset_expiry: Duration::hours(1), + + templates: Templates { + verify_email: Template { + title: "Verify your REVOLT account.", + text: "Verify your email here: {{url}}", + html: include_str!("../assets/templates/verify.html"), }, - - smtp: SMTP { - from: (*SMTP_FROM).to_string(), - host: (*SMTP_HOST).to_string(), - username: (*SMTP_USERNAME).to_string(), - password: (*SMTP_PASSWORD).to_string(), + reset_password: Template { + title: "Reset your REVOLT password.", + text: "Reset your password here: {{url}}", + html: include_str!("../assets/templates/reset.html"), }, - } - } else { - EmailVerification::Disabled - }), - ); + welcome: None, + }, + + smtp: SMTP { + from: (*SMTP_FROM).to_string(), + host: (*SMTP_HOST).to_string(), + username: (*SMTP_USERNAME).to_string(), + password: (*SMTP_PASSWORD).to_string(), + }, + } + } else { + EmailVerification::Disabled + }); + + if *INVITE_ONLY { + options = options.invite_only_collection(database::get_collection("invites")) + } + + if *USE_HCAPTCHA { + options = options.hcaptcha_secret(HCAPTCHA_KEY.clone()); + } + + let auth = Auth::new(database::get_collection("accounts"), options); let mut rocket = rocket::ignite(); diff --git a/src/routes/root.rs b/src/routes/root.rs index 8cf197d31e7214644150f198ff61dac65af5bafc..126479aadad45399c6082d64fe72488f0e8494fa 100644 --- a/src/routes/root.rs +++ b/src/routes/root.rs @@ -1,5 +1,5 @@ use crate::util::variables::{ - DISABLE_REGISTRATION, EXTERNAL_WS_URL, HCAPTCHA_SITEKEY, USE_EMAIL, USE_HCAPTCHA, INVITE_ONLY + DISABLE_REGISTRATION, EXTERNAL_WS_URL, HCAPTCHA_SITEKEY, INVITE_ONLY, USE_EMAIL, USE_HCAPTCHA, }; use mongodb::bson::doc; @@ -8,7 +8,7 @@ use rocket_contrib::json::JsonValue; #[get("/")] pub async fn root() -> JsonValue { json!({ - "revolt": "0.3.3-alpha.1", + "revolt": "0.3.3-alpha.2", "features": { "registration": !*DISABLE_REGISTRATION, "captcha": {