mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 05:26:59 +00:00
chore: implement invite join and rauth conf
This commit is contained in:
14
src/main.rs
14
src/main.rs
@@ -24,11 +24,11 @@ use rauth::{
|
||||
use revolt_quark::DatabaseInfo;
|
||||
use rocket_cors::AllowedOrigins;
|
||||
use std::str::FromStr;
|
||||
/*use util::variables::{
|
||||
use util::variables::{
|
||||
APP_URL, HCAPTCHA_KEY, INVITE_ONLY, SMTP_FROM, SMTP_HOST, SMTP_PASSWORD, SMTP_USERNAME,
|
||||
USE_EMAIL, USE_HCAPTCHA,
|
||||
};
|
||||
use crate::util::ratelimit::RatelimitState;*/
|
||||
// use crate::util::ratelimit::RatelimitState;
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() {
|
||||
@@ -76,8 +76,8 @@ async fn launch_web() {
|
||||
.to_cors()
|
||||
.expect("Failed to create CORS.");
|
||||
|
||||
let config = Config {
|
||||
email_verification: /*if *USE_EMAIL {
|
||||
let mut config = Config {
|
||||
email_verification: if *USE_EMAIL {
|
||||
EmailVerification::Enabled {
|
||||
smtp: SMTPSettings {
|
||||
from: (*SMTP_FROM).to_string(),
|
||||
@@ -107,11 +107,11 @@ async fn launch_web() {
|
||||
}
|
||||
} else {
|
||||
EmailVerification::Disabled
|
||||
},*/ EmailVerification::Disabled,
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
/*if *INVITE_ONLY {
|
||||
if *INVITE_ONLY {
|
||||
config.invite_only = true;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ async fn launch_web() {
|
||||
config.captcha = Captcha::HCaptcha {
|
||||
secret: HCAPTCHA_KEY.clone(),
|
||||
};
|
||||
}*/
|
||||
}
|
||||
|
||||
let db = DatabaseInfo::Dummy.connect().await.unwrap();
|
||||
|
||||
|
||||
@@ -1,8 +1,35 @@
|
||||
use revolt_quark::{Error, Result};
|
||||
use revolt_quark::{Error, Result, Ref, models::{User, Invite}, Db};
|
||||
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
use crate::util::variables::MAX_SERVER_COUNT;
|
||||
|
||||
#[post("/<target>")]
|
||||
pub async fn req(/*user: UserRef, target: Ref*/ target: String) -> Result<Value> {
|
||||
todo!()
|
||||
pub async fn req(db: &Db, user: User, target: Ref) -> Result<Value> {
|
||||
if user.bot.is_some() {
|
||||
return Err(Error::IsBot)
|
||||
}
|
||||
|
||||
if !user.can_acquire_server(db).await? {
|
||||
return Err(Error::TooManyServers {
|
||||
max: *MAX_SERVER_COUNT
|
||||
})
|
||||
}
|
||||
|
||||
let invite = target.as_invite(db).await?;
|
||||
match &invite {
|
||||
Invite::Server { channel, server, .. } => {
|
||||
let channel = db.fetch_channel(channel).await?;
|
||||
let server = db.fetch_server(server).await?;
|
||||
|
||||
db.insert_member(&server.id, &user.id).await?;
|
||||
|
||||
Ok(json!({
|
||||
"type": "Server",
|
||||
"channel": channel,
|
||||
"server": server
|
||||
}))
|
||||
}
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user