Add rAuth captcha support.

This commit is contained in:
Paul Makles
2021-02-13 20:18:38 +00:00
parent ea8de2400a
commit 03099fb83f
4 changed files with 55 additions and 48 deletions

7
Cargo.lock generated
View File

@@ -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",

View File

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

View File

@@ -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"))
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"),
},
reset_password: Template {
title: "Reset your REVOLT password.",
text: "Reset your password here: {{url}}",
html: include_str!("../assets/templates/reset.html"),
},
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 {
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)),
EmailVerification::Disabled
});
verification_expiry: Duration::days(1),
password_reset_expiry: Duration::hours(1),
if *INVITE_ONLY {
options = options.invite_only_collection(database::get_collection("invites"))
}
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
},
if *USE_HCAPTCHA {
options = options.hcaptcha_secret(HCAPTCHA_KEY.clone());
}
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
}),
);
let auth = Auth::new(database::get_collection("accounts"), options);
let mut rocket = rocket::ignite();

View File

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