Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
vcfxb committed Nov 3, 2021
1 parent 43a9025 commit 1660c12
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 36 deletions.
4 changes: 1 addition & 3 deletions src/api/discord/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<RoleId>, 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()
Expand Down
4 changes: 1 addition & 3 deletions src/api/rcos/users/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ use delete_user::{ResponseData, Variables};

impl DeleteUser {
pub async fn execute(username: String) -> Result<ResponseData, TelescopeError> {
send_query::<Self>(Variables {
username
}).await
send_query::<Self>(Variables { username }).await
}
}
4 changes: 1 addition & 3 deletions src/web/services/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
18 changes: 10 additions & 8 deletions src/web/services/auth/oauth2_providers/discord.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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())
),
});
}

Expand Down
21 changes: 12 additions & 9 deletions src/web/services/auth/oauth2_providers/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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?;
}
}

Expand Down
22 changes: 13 additions & 9 deletions src/web/services/user/delete.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand All @@ -20,17 +20,21 @@ pub async fn confirm_delete(auth: AuthenticationCookie) -> Result<FormTemplate,
}

#[post("/profile_delete")]
pub async fn profile_delete(req: HttpRequest, identity: Identity) -> Result<Template, TelescopeError> {
pub async fn profile_delete(
req: HttpRequest,
identity: Identity,
) -> Result<Template, TelescopeError> {
// Get the viewer's RCOS username.
let rcos_username: String = identity
.get_rcos_username()
.await?
.ok_or(TelescopeError::NotAuthenticated)?;

// Check if the viewer has a discord account linked.
let discord_id: Option<u64> = AccountLookup::send(rcos_username.clone(), UserAccountType::Discord)
.await?
.and_then(|string| string.as_str().parse::<u64>().ok());
let discord_id: Option<u64> =
AccountLookup::send(rcos_username.clone(), UserAccountType::Discord)
.await?
.and_then(|string| string.as_str().parse::<u64>().ok());

// If there is one, kick it from the RCOS Discord.
if let Some(discord_id) = discord_id {
Expand All @@ -52,6 +56,6 @@ pub async fn profile_delete(req: HttpRequest, identity: Identity) -> Result<Temp

// Show the user a jumbotron indicating account deletion.
jumbotron::new("Account deletion", "Your account was deleted successfully.")
.render_into_page(&req, "Account deletion")
.await
.render_into_page(&req, "Account deletion")
.await
}
2 changes: 1 addition & 1 deletion src/web/services/user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
use actix_web::web::ServiceConfig;

mod delete;
pub mod developers;
mod join_discord;
mod login;
pub mod profile;
mod register;
mod delete;

/// Register user related services.
pub fn register(config: &mut ServiceConfig) {
Expand Down

0 comments on commit 1660c12

Please sign in to comment.