forked from jmug/stoatchat
Add rAuth captcha support.
This commit is contained in:
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -2308,8 +2308,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rauth"
|
name = "rauth"
|
||||||
version = "0.2.2"
|
version = "0.2.4"
|
||||||
source = "git+https://gitlab.insrt.uk/insert/rauth?rev=73fd602f0aba3d3689307fb1f811f211422fb4d3#73fd602f0aba3d3689307fb1f811f211422fb4d3"
|
source = "git+https://gitlab.insrt.uk/insert/rauth?rev=8c96882057f85d950578a6324abf1f7268862edd#8c96882057f85d950578a6324abf1f7268862edd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"handlebars",
|
"handlebars",
|
||||||
@@ -2319,6 +2319,7 @@ dependencies = [
|
|||||||
"mongodb",
|
"mongodb",
|
||||||
"nanoid",
|
"nanoid",
|
||||||
"regex",
|
"regex",
|
||||||
|
"reqwest",
|
||||||
"rocket",
|
"rocket",
|
||||||
"rocket_contrib",
|
"rocket_contrib",
|
||||||
"rust-argon2",
|
"rust-argon2",
|
||||||
@@ -2453,7 +2454,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "revolt"
|
name = "revolt"
|
||||||
version = "0.3.3-alpha.1"
|
version = "0.3.3-alpha.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"async-tungstenite",
|
"async-tungstenite",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt"
|
name = "revolt"
|
||||||
version = "0.3.3-alpha.1"
|
version = "0.3.3-alpha.2"
|
||||||
authors = ["Paul Makles <paulmakles@gmail.com>"]
|
authors = ["Paul Makles <paulmakles@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ many-to-many = "0.1.2"
|
|||||||
ctrlc = { version = "3.0", features = ["termination"] }
|
ctrlc = { version = "3.0", features = ["termination"] }
|
||||||
async-std = { version = "1.8.0", features = ["tokio02", "attributes"] }
|
async-std = { version = "1.8.0", features = ["tokio02", "attributes"] }
|
||||||
async-tungstenite = { version = "0.10.0", features = ["async-std-runtime"] }
|
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"] }
|
hive_pubsub = { version = "0.4.3", features = ["mongo"] }
|
||||||
rocket_cors = { git = "https://github.com/insertish/rocket_cors", branch = "master" }
|
rocket_cors = { git = "https://github.com/insertish/rocket_cors", branch = "master" }
|
||||||
|
|||||||
88
src/main.rs
88
src/main.rs
@@ -21,12 +21,16 @@ pub mod util;
|
|||||||
use chrono::Duration;
|
use chrono::Duration;
|
||||||
use futures::join;
|
use futures::join;
|
||||||
use log::info;
|
use log::info;
|
||||||
use rauth::{auth::Auth, options::{Template, Templates}};
|
|
||||||
use rauth::options::{EmailVerification, Options, SMTP};
|
use rauth::options::{EmailVerification, Options, SMTP};
|
||||||
|
use rauth::{
|
||||||
|
auth::Auth,
|
||||||
|
options::{Template, Templates},
|
||||||
|
};
|
||||||
use rocket_cors::AllowedOrigins;
|
use rocket_cors::AllowedOrigins;
|
||||||
use rocket_prometheus::PrometheusMetrics;
|
use rocket_prometheus::PrometheusMetrics;
|
||||||
use util::variables::{
|
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]
|
#[async_std::main]
|
||||||
@@ -61,49 +65,51 @@ async fn launch_web() {
|
|||||||
.to_cors()
|
.to_cors()
|
||||||
.expect("Failed to create CORS.");
|
.expect("Failed to create CORS.");
|
||||||
|
|
||||||
let auth = Auth::new(
|
let mut options = Options::new()
|
||||||
database::get_collection("accounts"),
|
.base_url(format!("{}/auth", *PUBLIC_URL))
|
||||||
if *INVITE_ONLY {
|
.email_verification(if *USE_EMAIL {
|
||||||
Options::new()
|
EmailVerification::Enabled {
|
||||||
.invite_only_collection(database::get_collection("invites"))
|
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 {
|
} else {
|
||||||
Options::new()
|
EmailVerification::Disabled
|
||||||
}
|
});
|
||||||
.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),
|
if *INVITE_ONLY {
|
||||||
password_reset_expiry: Duration::hours(1),
|
options = options.invite_only_collection(database::get_collection("invites"))
|
||||||
|
}
|
||||||
|
|
||||||
templates: Templates {
|
if *USE_HCAPTCHA {
|
||||||
verify_email: Template {
|
options = options.hcaptcha_secret(HCAPTCHA_KEY.clone());
|
||||||
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 {
|
let auth = Auth::new(database::get_collection("accounts"), options);
|
||||||
from: (*SMTP_FROM).to_string(),
|
|
||||||
host: (*SMTP_HOST).to_string(),
|
|
||||||
username: (*SMTP_USERNAME).to_string(),
|
|
||||||
password: (*SMTP_PASSWORD).to_string(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
EmailVerification::Disabled
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut rocket = rocket::ignite();
|
let mut rocket = rocket::ignite();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::util::variables::{
|
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;
|
use mongodb::bson::doc;
|
||||||
@@ -8,7 +8,7 @@ use rocket_contrib::json::JsonValue;
|
|||||||
#[get("/")]
|
#[get("/")]
|
||||||
pub async fn root() -> JsonValue {
|
pub async fn root() -> JsonValue {
|
||||||
json!({
|
json!({
|
||||||
"revolt": "0.3.3-alpha.1",
|
"revolt": "0.3.3-alpha.2",
|
||||||
"features": {
|
"features": {
|
||||||
"registration": !*DISABLE_REGISTRATION,
|
"registration": !*DISABLE_REGISTRATION,
|
||||||
"captcha": {
|
"captcha": {
|
||||||
|
|||||||
Reference in New Issue
Block a user