mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 13:36:59 +00:00
Push env variables to rAuth + cargo fmt.
This commit is contained in:
@@ -79,8 +79,12 @@ impl Channel {
|
||||
pub async fn publish_update(&self, data: JsonValue) -> Result<()> {
|
||||
let id = self.id().to_string();
|
||||
ClientboundNotification::ChannelUpdate {
|
||||
id: id.clone(), data
|
||||
}.publish(id).await.ok();
|
||||
id: id.clone(),
|
||||
data,
|
||||
}
|
||||
.publish(id)
|
||||
.await
|
||||
.ok();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -48,46 +48,48 @@ impl Message {
|
||||
let channels = get_collection("channels");
|
||||
match channel {
|
||||
Channel::DirectMessage { id, .. } => {
|
||||
channels.update_one(
|
||||
doc! { "_id": id },
|
||||
doc! {
|
||||
"$set": {
|
||||
"active": true,
|
||||
"last_message": {
|
||||
"_id": self.id.clone(),
|
||||
"author": self.author.clone(),
|
||||
"short": self.content.chars().take(24).collect::<String>()
|
||||
channels
|
||||
.update_one(
|
||||
doc! { "_id": id },
|
||||
doc! {
|
||||
"$set": {
|
||||
"active": true,
|
||||
"last_message": {
|
||||
"_id": self.id.clone(),
|
||||
"author": self.author.clone(),
|
||||
"short": self.content.chars().take(24).collect::<String>()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
None
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "channel",
|
||||
})?;
|
||||
},
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "channel",
|
||||
})?;
|
||||
}
|
||||
Channel::Group { id, .. } => {
|
||||
channels.update_one(
|
||||
doc! { "_id": id },
|
||||
doc! {
|
||||
"$set": {
|
||||
"last_message": {
|
||||
"_id": self.id.clone(),
|
||||
"author": self.author.clone(),
|
||||
"short": self.content.chars().take(24).collect::<String>()
|
||||
channels
|
||||
.update_one(
|
||||
doc! { "_id": id },
|
||||
doc! {
|
||||
"$set": {
|
||||
"last_message": {
|
||||
"_id": self.id.clone(),
|
||||
"author": self.author.clone(),
|
||||
"short": self.content.chars().take(24).collect::<String>()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
None
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "channel",
|
||||
})?;
|
||||
},
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "channel",
|
||||
})?;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -102,8 +104,12 @@ impl Message {
|
||||
pub async fn publish_update(&self, data: JsonValue) -> Result<()> {
|
||||
let channel = self.channel.clone();
|
||||
ClientboundNotification::MessageUpdate {
|
||||
id: self.id.clone(), data
|
||||
}.publish(channel).await.ok();
|
||||
id: self.id.clone(),
|
||||
data,
|
||||
}
|
||||
.publish(channel)
|
||||
.await
|
||||
.ok();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -29,7 +29,10 @@ impl<'a, 'r> FromRequest<'a, 'r> for User {
|
||||
} else {
|
||||
Outcome::Failure((
|
||||
Status::InternalServerError,
|
||||
rauth::util::Error::DatabaseError { operation: "find_one", with: "user" },
|
||||
rauth::util::Error::DatabaseError {
|
||||
operation: "find_one",
|
||||
with: "user",
|
||||
},
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
use super::super::{get_collection, get_db};
|
||||
use crate::database::get_collection;
|
||||
|
||||
use crate::rocket::futures::StreamExt;
|
||||
use log::info;
|
||||
use mongodb::bson::{doc, from_document};
|
||||
use mongodb::options::FindOptions;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
||||
27
src/main.rs
27
src/main.rs
@@ -18,10 +18,13 @@ pub mod notifications;
|
||||
pub mod routes;
|
||||
pub mod util;
|
||||
|
||||
use chrono::Duration;
|
||||
use futures::join;
|
||||
use log::info;
|
||||
use rauth::{self, options::Options};
|
||||
use rauth::auth::Auth;
|
||||
use rauth::options::{EmailVerification, Options, SMTP};
|
||||
use rocket_cors::AllowedOrigins;
|
||||
use util::variables::{PUBLIC_URL, SMTP_FROM, SMTP_HOST, SMTP_PASSWORD, SMTP_USERNAME, USE_EMAIL};
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() {
|
||||
@@ -55,7 +58,27 @@ async fn launch_web() {
|
||||
.to_cors()
|
||||
.expect("Failed to create CORS.");
|
||||
|
||||
let auth = rauth::auth::Auth::new(database::get_collection("accounts"), Options::new());
|
||||
let auth = Auth::new(
|
||||
database::get_collection("accounts"),
|
||||
Options::new()
|
||||
.base_url(format!("{}/auth", *PUBLIC_URL))
|
||||
.email_verification(if *USE_EMAIL {
|
||||
EmailVerification::Enabled {
|
||||
success_redirect_uri: format!("{}/welcome", *PUBLIC_URL),
|
||||
verification_expiry: Duration::days(1),
|
||||
verification_ratelimit: Duration::minutes(1),
|
||||
|
||||
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
|
||||
}),
|
||||
);
|
||||
|
||||
routes::mount(rocket::ignite())
|
||||
.mount("/", rocket_cors::catch_all_options_routes())
|
||||
|
||||
@@ -41,7 +41,7 @@ pub enum ClientboundNotification {
|
||||
Message(Message),
|
||||
MessageUpdate {
|
||||
id: String,
|
||||
data: JsonValue
|
||||
data: JsonValue,
|
||||
},
|
||||
MessageDelete {
|
||||
id: String,
|
||||
@@ -50,7 +50,7 @@ pub enum ClientboundNotification {
|
||||
ChannelCreate(Channel),
|
||||
ChannelUpdate {
|
||||
id: String,
|
||||
data: JsonValue
|
||||
data: JsonValue,
|
||||
},
|
||||
ChannelGroupJoin {
|
||||
id: String,
|
||||
|
||||
@@ -12,7 +12,10 @@ use futures::{pin_mut, prelude::*};
|
||||
use hive_pubsub::PubSub;
|
||||
use log::{debug, info};
|
||||
use many_to_many::ManyToMany;
|
||||
use rauth::{auth::{Auth, Session}, options::Options};
|
||||
use rauth::{
|
||||
auth::{Auth, Session},
|
||||
options::Options,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
@@ -84,9 +87,10 @@ async fn accept(stream: TcpStream) {
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(validated_session) = Auth::new(get_collection("accounts"), Options::new())
|
||||
.verify_session(new_session)
|
||||
.await
|
||||
if let Ok(validated_session) =
|
||||
Auth::new(get_collection("accounts"), Options::new())
|
||||
.verify_session(new_session)
|
||||
.await
|
||||
{
|
||||
let id = validated_session.user_id.clone();
|
||||
if let Ok(user) = (Ref { id: id.clone() }).fetch_user().await {
|
||||
|
||||
@@ -70,7 +70,7 @@ pub async fn req(user: User, info: Json<Data>) -> Result<JsonValue> {
|
||||
.unwrap_or_else(|| "A group.".to_string()),
|
||||
owner: user.id,
|
||||
recipients: set.into_iter().collect::<Vec<String>>(),
|
||||
last_message: None
|
||||
last_message: None,
|
||||
};
|
||||
|
||||
channel.clone().publish().await?;
|
||||
|
||||
@@ -27,7 +27,7 @@ pub async fn req(session: Session, user: Option<User>, data: Json<Data>) -> Resu
|
||||
|
||||
data.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
|
||||
if data.username == "revolt" {
|
||||
Err(Error::UsernameTaken)?
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
id,
|
||||
active: false,
|
||||
recipients: vec![user.id, target.id],
|
||||
last_message: None
|
||||
last_message: None,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user