diff --git a/Cargo.lock b/Cargo.lock index 67669e4b..4ca0c05e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2505,7 +2505,7 @@ dependencies = [ [[package]] name = "rauth" version = "1.0.0" -source = "git+https://github.com/insertish/rauth?rev=e71d54eba4712b6c6a8a4354ad9fa39677714e1f#e71d54eba4712b6c6a8a4354ad9fa39677714e1f" +source = "git+https://github.com/insertish/rauth?rev=7a579daa6a90845fe86139edcadbd01639b330b6#7a579daa6a90845fe86139edcadbd01639b330b6" dependencies = [ "async-std", "async-trait", @@ -2986,7 +2986,7 @@ dependencies = [ [[package]] name = "rocket_rauth" version = "1.0.0" -source = "git+https://github.com/insertish/rauth?rev=e71d54eba4712b6c6a8a4354ad9fa39677714e1f#e71d54eba4712b6c6a8a4354ad9fa39677714e1f" +source = "git+https://github.com/insertish/rauth?rev=7a579daa6a90845fe86139edcadbd01639b330b6#7a579daa6a90845fe86139edcadbd01639b330b6" dependencies = [ "async-std", "base32", diff --git a/crates/delta/Cargo.toml b/crates/delta/Cargo.toml index 5e7c256c..ccba2854 100644 --- a/crates/delta/Cargo.toml +++ b/crates/delta/Cargo.toml @@ -52,7 +52,7 @@ mobc-redis = { version = "0.7.0", default-features = false, features = ["async-s # web rocket = { version = "0.5.0-rc.2", default-features = false, features = ["json"] } rocket_empty = { git = "https://github.com/insertish/rocket_empty", branch = "master" } -rocket_rauth = { git = "https://github.com/insertish/rauth", rev = "e71d54eba4712b6c6a8a4354ad9fa39677714e1f" } +rocket_rauth = { git = "https://github.com/insertish/rauth", rev = "7a579daa6a90845fe86139edcadbd01639b330b6" } # spec generation schemars = "0.8.8" diff --git a/crates/delta/src/routes/mod.rs b/crates/delta/src/routes/mod.rs index 72782fc0..4b384f35 100644 --- a/crates/delta/src/routes/mod.rs +++ b/crates/delta/src/routes/mod.rs @@ -101,7 +101,8 @@ fn custom_openapi_spec() -> OpenApi { "tags": [ "Account", "Session", - "Onboarding" + "Onboarding", + "MFA" ] }, { @@ -118,7 +119,7 @@ fn custom_openapi_spec() -> OpenApi { openapi: OpenApi::default_version(), info: Info { title: "Revolt API".to_owned(), - description: Some("User-first privacy focused chat platform.".to_owned()), + description: Some("Open source user-first chat platform.".to_owned()), terms_of_service: Some("https://revolt.chat/terms".to_owned()), contact: Some(Contact { name: Some("Revolt Support".to_owned()), @@ -243,6 +244,11 @@ fn custom_openapi_spec() -> OpenApi { description: Some("Create and manage sessions".to_owned()), ..Default::default() }, + Tag { + name: "MFA".to_owned(), + description: Some("Multi-factor Authentication".to_owned()), + ..Default::default() + }, Tag { name: "Onboarding".to_owned(), description: Some( diff --git a/crates/delta/src/routes/users/add_friend.rs b/crates/delta/src/routes/users/add_friend.rs index 4cbcb6c7..e04540fa 100644 --- a/crates/delta/src/routes/users/add_friend.rs +++ b/crates/delta/src/routes/users/add_friend.rs @@ -1,16 +1,20 @@ use revolt_quark::models::User; -use revolt_quark::{Database, Error, Result}; +use revolt_quark::{Database, Error, Ref, Result}; use rocket::serde::json::Json; use rocket::State; -/// # Send Friend Request / Accept Request +/// # Accept Friend Request /// -/// Send a friend request to another user or accept another user's friend request. +/// Accept another user's friend request. #[openapi(tag = "Relationships")] -#[put("//friend")] -pub async fn req(db: &State, user: User, username: String) -> Result> { - let mut target = db.fetch_user_by_username(&username).await?; +#[put("//friend")] +pub async fn req(db: &State, user: User, target: Ref) -> Result> { + let mut target = if let Ok(user) = db.fetch_user_by_username(&target.id).await { + user + } else { + target.as_user(db).await? + }; if user.bot.is_some() || target.bot.is_some() { return Err(Error::IsBot); diff --git a/crates/delta/src/routes/users/mod.rs b/crates/delta/src/routes/users/mod.rs index 60b92e94..008ae216 100644 --- a/crates/delta/src/routes/users/mod.rs +++ b/crates/delta/src/routes/users/mod.rs @@ -13,6 +13,7 @@ mod find_mutual; mod get_default_avatar; mod open_dm; mod remove_friend; +mod send_friend_request; mod unblock_user; pub fn routes() -> (Vec, OpenApi) { @@ -33,5 +34,6 @@ pub fn routes() -> (Vec, OpenApi) { remove_friend::req, block_user::req, unblock_user::req, + send_friend_request::req, ] } diff --git a/crates/delta/src/routes/users/send_friend_request.rs b/crates/delta/src/routes/users/send_friend_request.rs new file mode 100644 index 00000000..1c9a6d1e --- /dev/null +++ b/crates/delta/src/routes/users/send_friend_request.rs @@ -0,0 +1,32 @@ +use revolt_quark::models::User; +use revolt_quark::{Database, Error, Result}; + +use rocket::serde::json::Json; +use rocket::State; +use serde::{Deserialize, Serialize}; + +/// # User Lookup Information +#[derive(Serialize, Deserialize, JsonSchema)] +pub struct DataSendFriendRequest { + username: String, +} + +/// # Send Friend Request +/// +/// Send a friend request to another user. +#[openapi(tag = "Relationships")] +#[post("/friend", data = "")] +pub async fn req( + db: &State, + user: User, + data: Json, +) -> Result> { + let mut target = db.fetch_user_by_username(&data.username).await?; + + if user.bot.is_some() || target.bot.is_some() { + return Err(Error::IsBot); + } + + user.add_friend(db, &mut target).await?; + Ok(Json(target.with_auto_perspective(db, &user).await)) +} diff --git a/crates/quark/Cargo.toml b/crates/quark/Cargo.toml index 062b9d14..d9dad685 100644 --- a/crates/quark/Cargo.toml +++ b/crates/quark/Cargo.toml @@ -84,7 +84,7 @@ rocket_empty = { optional = true, git = "https://github.com/insertish/rocket_emp rocket_cors = { optional = true, git = "https://github.com/lawliet89/rocket_cors", rev = "5843861a88958c16bfaa0b40f0d8910772bcd2f6" } # rAuth -rauth = { git = "https://github.com/insertish/rauth", rev = "e71d54eba4712b6c6a8a4354ad9fa39677714e1f", features = [ "async-std-runtime" ] } +rauth = { git = "https://github.com/insertish/rauth", rev = "7a579daa6a90845fe86139edcadbd01639b330b6", features = [ "async-std-runtime" ] } # Sentry sentry = "0.25.0"