diff --git a/src/api/discord/mod.rs b/src/api/discord/mod.rs index 260925f7..bea797e4 100644 --- a/src/api/discord/mod.rs +++ b/src/api/discord/mod.rs @@ -18,9 +18,7 @@ pub fn global_discord_client() -> &'static Http { /// Get the ID of the verified role on the RCOS discord if it exists. pub async fn rcos_discord_verified_role_id() -> Result, TelescopeError> { // Get the RCOS Guild ID. - let rcos_discord: u64 = global_config() - .discord_config - .rcos_guild_id(); + let rcos_discord: u64 = global_config().discord_config.rcos_guild_id(); // Get role Ok(global_discord_client() diff --git a/src/api/rcos/users/delete.rs b/src/api/rcos/users/delete.rs index 2ed264d3..eb857879 100644 --- a/src/api/rcos/users/delete.rs +++ b/src/api/rcos/users/delete.rs @@ -14,8 +14,6 @@ use delete_user::{ResponseData, Variables}; impl DeleteUser { pub async fn execute(username: String) -> Result { - send_query::(Variables { - username - }).await + send_query::(Variables { username }).await } } diff --git a/src/web/services/auth/mod.rs b/src/web/services/auth/mod.rs index 12166648..5ca3e9ac 100644 --- a/src/web/services/auth/mod.rs +++ b/src/web/services/auth/mod.rs @@ -239,9 +239,7 @@ pub trait IdentityProvider: 'static { if let Some(discord_id) = user_discord { // Get RCOS Discord ID. - let rcos_discord = global_config() - .discord_config - .rcos_guild_id(); + let rcos_discord = global_config().discord_config.rcos_guild_id(); // Kick user from RCOS Discord. global_discord_client() diff --git a/src/web/services/auth/oauth2_providers/discord.rs b/src/web/services/auth/oauth2_providers/discord.rs index 8e2775f2..5d86d92b 100644 --- a/src/web/services/auth/oauth2_providers/discord.rs +++ b/src/web/services/auth/oauth2_providers/discord.rs @@ -1,6 +1,5 @@ //! Discord OAuth2 flow. -use std::sync::Arc; use crate::api::rcos::send_query; use crate::api::rcos::users::accounts::reverse_lookup::ReverseLookup; use crate::api::rcos::users::UserAccountType; @@ -18,6 +17,7 @@ use oauth2::{AuthUrl, TokenUrl}; use reqwest::header::AUTHORIZATION; use serenity::model::id::RoleId; use serenity::model::user::CurrentUser; +use std::sync::Arc; /// The Discord API endpoint to query for user data. pub const DISCORD_API_ENDPOINT: &'static str = "https://discord.com/api/v8"; @@ -245,13 +245,15 @@ impl DiscordIdentity { error!("Discord returned non-success status code when adding user to RCOS Guild. Response: {:#?}", response); return Err(TelescopeError::GatewayError { header: "Discord API Error".to_string(), - message: format!("Discord API returned status {}{}.", - response.status() - .as_u16(), - response.status() - .canonical_reason() - .map(|s| format!(" ({})", s)) - .unwrap_or("".to_string())) + message: format!( + "Discord API returned status {}{}.", + response.status().as_u16(), + response + .status() + .canonical_reason() + .map(|s| format!(" ({})", s)) + .unwrap_or("".to_string()) + ), }); } diff --git a/src/web/services/auth/oauth2_providers/mod.rs b/src/web/services/auth/oauth2_providers/mod.rs index ff72c31d..2a3f8154 100644 --- a/src/web/services/auth/oauth2_providers/mod.rs +++ b/src/web/services/auth/oauth2_providers/mod.rs @@ -1,9 +1,12 @@ use super::{make_redirect_url, IdentityProvider}; +use crate::api::rcos::users::accounts::for_user::UserAccounts; use crate::api::rcos::users::accounts::link::LinkUserAccount; +use crate::api::rcos::users::accounts::unlink::UnlinkUserAccount; use crate::api::rcos::users::UserAccountType; use crate::api::rcos::{send_query, users::accounts::reverse_lookup}; use crate::error::TelescopeError; use crate::web::services::auth::identity::{AuthenticationCookie, Identity, RootIdentity}; +use crate::web::services::auth::AUTHENTICATOR_ACCOUNT_TYPES; use crate::web::{csrf, profile_for}; use actix_web::http::header::LOCATION; use actix_web::web::Query; @@ -15,9 +18,6 @@ use oauth2::{AuthorizationCode, AuthorizationRequest, CsrfToken, RedirectUrl, Sc use std::borrow::Cow; use std::collections::HashMap; use std::sync::Arc; -use crate::api::rcos::users::accounts::for_user::UserAccounts; -use crate::api::rcos::users::accounts::unlink::UnlinkUserAccount; -use crate::web::services::auth::AUTHENTICATOR_ACCOUNT_TYPES; pub mod discord; pub mod github; @@ -298,8 +298,12 @@ where // First get the authenticated user's username. let rcos_username: String = cookie.get_rcos_username_or_error().await?; - info!("Linking {} account ID {} to Telescope User {}", - Self::USER_ACCOUNT_TY, platform_id, rcos_username); + info!( + "Linking {} account ID {} to Telescope User {}", + Self::USER_ACCOUNT_TY, + platform_id, + rcos_username + ); // Check if there is already an account of this type linked. // Lookup all linked accounts. @@ -319,8 +323,8 @@ where // Return user to their profile. return Ok(HttpResponse::Found() - .header(LOCATION, profile_for(&rcos_username)) - .finish()); + .header(LOCATION, profile_for(&rcos_username)) + .finish()); } // Otherwise try to replace the linked account. @@ -337,8 +341,7 @@ where info!("Replacing currently linked account."); // Send unlink mutation. - UnlinkUserAccount::send(rcos_username.clone(), Self::USER_ACCOUNT_TY) - .await?; + UnlinkUserAccount::send(rcos_username.clone(), Self::USER_ACCOUNT_TY).await?; } } diff --git a/src/web/services/user/delete.rs b/src/web/services/user/delete.rs index 8d0f997c..2ff826d8 100644 --- a/src/web/services/user/delete.rs +++ b/src/web/services/user/delete.rs @@ -1,11 +1,11 @@ +use crate::api::discord::global_discord_client; +use crate::api::rcos::users::accounts::lookup::AccountLookup; use crate::api::rcos::users::{delete::DeleteUser, profile::Profile, UserAccountType}; +use crate::env::global_config; use crate::error::TelescopeError; use crate::templates::{forms::FormTemplate, jumbotron, Template}; use crate::web::services::auth::identity::{AuthenticationCookie, Identity}; use actix_web::HttpRequest; -use crate::api::discord::global_discord_client; -use crate::api::rcos::users::accounts::lookup::AccountLookup; -use crate::env::global_config; /// Confirmation form to delete the profile #[get("/profile_delete")] @@ -20,7 +20,10 @@ pub async fn confirm_delete(auth: AuthenticationCookie) -> Result Result { +pub async fn profile_delete( + req: HttpRequest, + identity: Identity, +) -> Result { // Get the viewer's RCOS username. let rcos_username: String = identity .get_rcos_username() @@ -28,9 +31,10 @@ pub async fn profile_delete(req: HttpRequest, identity: Identity) -> Result = AccountLookup::send(rcos_username.clone(), UserAccountType::Discord) - .await? - .and_then(|string| string.as_str().parse::().ok()); + let discord_id: Option = + AccountLookup::send(rcos_username.clone(), UserAccountType::Discord) + .await? + .and_then(|string| string.as_str().parse::().ok()); // If there is one, kick it from the RCOS Discord. if let Some(discord_id) = discord_id { @@ -52,6 +56,6 @@ pub async fn profile_delete(req: HttpRequest, identity: Identity) -> Result