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