forked from jmug/stoatchat
98
src/main.rs
98
src/main.rs
@@ -21,20 +21,18 @@ pub mod util;
|
||||
pub mod version;
|
||||
|
||||
use async_std::task;
|
||||
use chrono::Duration;
|
||||
use futures::join;
|
||||
use log::info;
|
||||
use rauth::options::{EmailVerification, Options, SMTP};
|
||||
use rauth::{
|
||||
auth::Auth,
|
||||
options::{Template, Templates},
|
||||
config::{Captcha, Config, EmailVerification, SMTPSettings, Template, Templates},
|
||||
logic::Auth,
|
||||
};
|
||||
use std::str::FromStr;
|
||||
use rocket_cors::AllowedOrigins;
|
||||
use rocket::catchers;
|
||||
use rocket_cors::AllowedOrigins;
|
||||
use std::str::FromStr;
|
||||
use util::variables::{
|
||||
APP_URL, HCAPTCHA_KEY, INVITE_ONLY, PUBLIC_URL, SMTP_FROM, SMTP_HOST, SMTP_PASSWORD,
|
||||
SMTP_USERNAME, USE_EMAIL, USE_HCAPTCHA,
|
||||
APP_URL, HCAPTCHA_KEY, INVITE_ONLY, SMTP_FROM, SMTP_HOST, SMTP_PASSWORD, SMTP_USERNAME,
|
||||
USE_EMAIL, USE_HCAPTCHA,
|
||||
};
|
||||
|
||||
#[async_std::main]
|
||||
@@ -71,79 +69,67 @@ async fn launch_web() {
|
||||
let cors = rocket_cors::CorsOptions {
|
||||
allowed_origins: AllowedOrigins::All,
|
||||
allowed_methods: [
|
||||
"Get",
|
||||
"Put",
|
||||
"Post",
|
||||
"Delete",
|
||||
"Options",
|
||||
"Head",
|
||||
"Trace",
|
||||
"Connect",
|
||||
"Patch",
|
||||
"Get", "Put", "Post", "Delete", "Options", "Head", "Trace", "Connect", "Patch",
|
||||
]
|
||||
.iter()
|
||||
.map(|s| FromStr::from_str(s).unwrap())
|
||||
.collect(),
|
||||
.iter()
|
||||
.map(|s| FromStr::from_str(s).unwrap())
|
||||
.collect(),
|
||||
..Default::default()
|
||||
}
|
||||
.to_cors()
|
||||
.expect("Failed to create CORS.");
|
||||
|
||||
let mut options = Options::new()
|
||||
.base_url(format!("{}/auth", *PUBLIC_URL))
|
||||
.email_verification(if *USE_EMAIL {
|
||||
let mut config = Config {
|
||||
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: "You're almost there!
|
||||
If you did not perform this action you can safely ignore this email.
|
||||
|
||||
Please verify your account here: {{url}}",
|
||||
html: None,
|
||||
},
|
||||
reset_password: Template {
|
||||
title: "Reset your Revolt password.",
|
||||
text: "You requested a password reset, if you did not perform this action you can safely ignore this email.
|
||||
|
||||
Reset your password here: {{url}}",
|
||||
html: None,
|
||||
},
|
||||
welcome: None,
|
||||
},
|
||||
|
||||
smtp: SMTP {
|
||||
smtp: SMTPSettings {
|
||||
from: (*SMTP_FROM).to_string(),
|
||||
host: (*SMTP_HOST).to_string(),
|
||||
username: (*SMTP_USERNAME).to_string(),
|
||||
password: (*SMTP_PASSWORD).to_string(),
|
||||
reply_to: Some("support@revolt.chat".into()),
|
||||
port: None,
|
||||
use_tls: None,
|
||||
},
|
||||
expiry: Default::default(),
|
||||
templates: Templates {
|
||||
verify: Template {
|
||||
title: "Verify your Revolt account.".into(),
|
||||
text: include_str!("../assets/templates/verify.txt").into(),
|
||||
url: format!("{}/login/verify/", *APP_URL),
|
||||
html: None,
|
||||
},
|
||||
reset: Template {
|
||||
title: "Reset your Revolt password.".into(),
|
||||
text: include_str!("../assets/templates/reset.txt").into(),
|
||||
url: format!("{}/login/reset/", *APP_URL),
|
||||
html: None,
|
||||
},
|
||||
welcome: None,
|
||||
},
|
||||
}
|
||||
} else {
|
||||
EmailVerification::Disabled
|
||||
});
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
if *INVITE_ONLY {
|
||||
options = options.invite_only_collection(database::get_collection("invites"))
|
||||
config.invite_only = true;
|
||||
}
|
||||
|
||||
if *USE_HCAPTCHA {
|
||||
options = options.hcaptcha_secret(HCAPTCHA_KEY.clone());
|
||||
config.captcha = Captcha::HCaptcha {
|
||||
secret: HCAPTCHA_KEY.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
let auth = Auth::new(database::get_collection("accounts"), options);
|
||||
let auth = Auth::new(database::get_db(), config);
|
||||
let rocket = rocket::build();
|
||||
|
||||
routes::mount(rocket)
|
||||
.mount("/", rocket_cors::catch_all_options_routes())
|
||||
.mount("/auth", rauth::routes::routes())
|
||||
.mount("/auth/account", rauth::web::account::routes())
|
||||
.mount("/auth/session", rauth::web::session::routes())
|
||||
.manage(auth)
|
||||
.manage(cors.clone())
|
||||
.attach(cors)
|
||||
|
||||
Reference in New Issue
Block a user