From ea8de2400a4dc5ec223ef85efc225873b2d50456 Mon Sep 17 00:00:00 2001 From: Paul Makles <paulmakles@gmail.com> Date: Fri, 12 Feb 2021 20:37:24 +0000 Subject: [PATCH] Add support for rAuth invite-only mode. --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- Dockerfile | 1 + src/main.rs | 9 +++++++-- src/routes/root.rs | 5 +++-- src/util/mod.rs | 15 --------------- src/util/variables.rs | 1 + 7 files changed, 16 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7e2e1c2..726f8a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2309,7 +2309,7 @@ dependencies = [ [[package]] name = "rauth" version = "0.2.2" -source = "git+https://gitlab.insrt.uk/insert/rauth?rev=1e5f671144772a28f3faac55dd98647235736923#1e5f671144772a28f3faac55dd98647235736923" +source = "git+https://gitlab.insrt.uk/insert/rauth?rev=73fd602f0aba3d3689307fb1f811f211422fb4d3#73fd602f0aba3d3689307fb1f811f211422fb4d3" dependencies = [ "chrono", "handlebars", @@ -2453,7 +2453,7 @@ dependencies = [ [[package]] name = "revolt" -version = "0.3.3-alpha.2" +version = "0.3.3-alpha.1" dependencies = [ "async-std", "async-tungstenite", diff --git a/Cargo.toml b/Cargo.toml index 3b7f57b..be0b430 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "revolt" -version = "0.3.3-alpha.2" +version = "0.3.3-alpha.1" 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 = "1e5f671144772a28f3faac55dd98647235736923" } +rauth = { git = "https://gitlab.insrt.uk/insert/rauth", rev = "73fd602f0aba3d3689307fb1f811f211422fb4d3" } hive_pubsub = { version = "0.4.3", features = ["mongo"] } rocket_cors = { git = "https://github.com/insertish/rocket_cors", branch = "master" } diff --git a/Dockerfile b/Dockerfile index 16c5c47..56763d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ WORKDIR /home/rust/src RUN USER=root cargo new --bin revolt WORKDIR /home/rust/src/revolt COPY Cargo.toml Cargo.lock ./ +COPY assets/templates ./assets/templates COPY src ./src RUN cargo build --release diff --git a/src/main.rs b/src/main.rs index aa0bc4d..019ca0a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ use rauth::options::{EmailVerification, Options, SMTP}; 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 + PUBLIC_URL, SMTP_FROM, SMTP_HOST, SMTP_PASSWORD, SMTP_USERNAME, USE_EMAIL, USE_PROMETHEUS, APP_URL, INVITE_ONLY }; #[async_std::main] @@ -63,7 +63,12 @@ async fn launch_web() { let auth = Auth::new( database::get_collection("accounts"), - Options::new() + 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 { diff --git a/src/routes/root.rs b/src/routes/root.rs index a247f8a..8cf197d 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, + DISABLE_REGISTRATION, EXTERNAL_WS_URL, HCAPTCHA_SITEKEY, USE_EMAIL, USE_HCAPTCHA, INVITE_ONLY }; 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.2", + "revolt": "0.3.3-alpha.1", "features": { "registration": !*DISABLE_REGISTRATION, "captcha": { @@ -16,6 +16,7 @@ pub async fn root() -> JsonValue { "key": HCAPTCHA_SITEKEY.to_string() }, "email": *USE_EMAIL, + "invite_only": *INVITE_ONLY }, "ws": *EXTERNAL_WS_URL, }) diff --git a/src/util/mod.rs b/src/util/mod.rs index a22135d..7743f0e 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,17 +1,2 @@ -use rand::{distributions::Alphanumeric, Rng}; -use std::collections::HashSet; -use std::iter::FromIterator; - pub mod result; pub mod variables; - -pub fn vec_to_set<T: Clone + Eq + std::hash::Hash>(data: &[T]) -> HashSet<T> { - HashSet::from_iter(data.iter().cloned()) -} - -pub fn gen_token(l: usize) -> String { - rand::thread_rng() - .sample_iter(&Alphanumeric) - .take(l) - .collect::<String>() -} diff --git a/src/util/variables.rs b/src/util/variables.rs index 37acdce..00f3d02 100644 --- a/src/util/variables.rs +++ b/src/util/variables.rs @@ -22,6 +22,7 @@ lazy_static! { // Application Flags pub static ref DISABLE_REGISTRATION: bool = env::var("REVOLT_DISABLE_REGISTRATION").map_or(false, |v| v == "1"); + pub static ref INVITE_ONLY: bool = env::var("REVOLT_INVITE_ONLY").map_or(false, |v| v == "1"); pub static ref USE_EMAIL: bool = env::var("REVOLT_USE_EMAIL_VERIFICATION").map_or( env::var("REVOLT_SMTP_HOST").is_ok() && env::var("REVOLT_SMTP_USERNAME").is_ok() -- GitLab