Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
most of trolley
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically committed Sep 21, 2023
1 parent a1cfdf1 commit f6da325
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 389 deletions.
6 changes: 3 additions & 3 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ WHITELISTED_MODPACK_DOMAINS='["cdn.modrinth.com", "github.com", "raw.githubuserc

ALLOWED_CALLBACK_URLS='["localhost", ".modrinth.com", "127.0.0.1"]'

PAYPAL_API_URL=https://api-m.sandbox.paypal.com/v1/
PAYPAL_CLIENT_ID=none
PAYPAL_CLIENT_SECRET=none
TROLLEY_ACCESS_KEY=none
TROLLEY_SECRET_KEY=none
TROLLEY_WEBHOOK_SIGNATURE=none

GITHUB_CLIENT_ID=none
GITHUB_CLIENT_SECRET=none
Expand Down
13 changes: 13 additions & 0 deletions migrations/20230919183129_trolley.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ALTER TABLE users
ADD COLUMN trolley_id text NULL,
ADD COLUMN trolley_account_status text NULL,
DROP COLUMN midas_expires,
DROP COLUMN is_overdue,
DROP COLUMN stripe_customer_id,
DROP COLUMN payout_wallet,
DROP COLUMN payout_wallet_type,
DROP COLUMN payout_address;

ALTER TABLE historical_payouts
ADD COLUMN batch_id text NULL,
ADD COLUMN payment_id text NULL;
6 changes: 0 additions & 6 deletions src/auth/flows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,6 @@ impl TempUser {
role: Role::Developer.to_string(),
badges: Badges::default(),
balance: Decimal::ZERO,
payout_wallet: None,
payout_wallet_type: None,
payout_address: None,
}
.insert(transaction)
.await?;
Expand Down Expand Up @@ -1384,9 +1381,6 @@ pub async fn create_account_with_password(
role: Role::Developer.to_string(),
badges: Badges::default(),
balance: Decimal::ZERO,
payout_wallet: None,
payout_wallet_type: None,
payout_address: None,
}
.insert(&mut transaction)
.await?;
Expand Down
9 changes: 2 additions & 7 deletions src/auth/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::auth::session::get_session_metadata;
use crate::auth::AuthenticationError;
use crate::database::models::user_item;
use crate::models::pats::Scopes;
use crate::models::users::{Role, User, UserId, UserPayoutData};
use crate::models::users::{Role, User, UserId};
use crate::queue::session::AuthQueue;
use actix_web::HttpRequest;
use chrono::Utc;
Expand Down Expand Up @@ -56,16 +56,11 @@ where
created: db_user.created,
role: Role::from_string(&db_user.role),
badges: db_user.badges,
payout_data: Some(UserPayoutData {
balance: db_user.balance,
payout_wallet: db_user.payout_wallet,
payout_wallet_type: db_user.payout_wallet_type,
payout_address: db_user.payout_address,
}),
auth_providers: Some(auth_providers),
has_password: Some(db_user.password.is_some()),
has_totp: Some(db_user.totp_secret.is_some()),
github_id: None,
payout_data: None,
};

if let Some(required_scopes) = required_scopes {
Expand Down
12 changes: 2 additions & 10 deletions src/database/models/user_item.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::ids::{ProjectId, UserId};
use crate::database::models::DatabaseError;
use crate::models::ids::base62_impl::{parse_base62, to_base62};
use crate::models::users::{Badges, RecipientType, RecipientWallet};
use crate::models::users::Badges;
use chrono::{DateTime, Utc};
use redis::cmd;
use rust_decimal::Decimal;
Expand Down Expand Up @@ -36,9 +36,6 @@ pub struct User {
pub role: String,
pub badges: Badges,
pub balance: Decimal,
pub payout_wallet: Option<RecipientWallet>,
pub payout_wallet_type: Option<RecipientType>,
pub payout_address: Option<String>,
}

impl User {
Expand Down Expand Up @@ -206,7 +203,7 @@ impl User {
SELECT id, name, email,
avatar_url, username, bio,
created, role, badges,
balance, payout_wallet, payout_wallet_type, payout_address,
balance,
github_id, discord_id, gitlab_id, google_id, steam_id, microsoft_id,
email_verified, password, totp_secret
FROM users
Expand Down Expand Up @@ -238,11 +235,6 @@ impl User {
role: u.role,
badges: Badges::from_bits(u.badges as u64).unwrap_or_default(),
balance: u.balance,
payout_wallet: u.payout_wallet.map(|x| RecipientWallet::from_string(&x)),
payout_wallet_type: u
.payout_wallet_type
.map(|x| RecipientType::from_string(&x)),
payout_address: u.payout_address,
password: u.password,
totp_secret: u.totp_secret,
}))
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,9 @@ fn check_env_vars() -> bool {
failed |= true;
}

failed |= check_var::<String>("PAYPAL_API_URL");
failed |= check_var::<String>("PAYPAL_CLIENT_ID");
failed |= check_var::<String>("PAYPAL_CLIENT_SECRET");
failed |= check_var::<String>("TROLLEY_ACCESS_KEY");
failed |= check_var::<String>("TROLLEY_SECRET_KEY");
failed |= check_var::<String>("TROLLEY_WEBHOOK_SIGNATURE");

failed |= check_var::<String>("GITHUB_CLIENT_ID");
failed |= check_var::<String>("GITHUB_CLIENT_SECRET");
Expand Down
75 changes: 3 additions & 72 deletions src/models/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ pub struct User {
pub role: Role,
pub badges: Badges,

pub payout_data: Option<UserPayoutData>,
pub auth_providers: Option<Vec<AuthProvider>>,
pub email: Option<String>,
pub email_verified: Option<bool>,
pub has_password: Option<bool>,
pub has_totp: Option<bool>,
pub payout_data: Option<UserPayoutData>,

// DEPRECATED. Always returns None
pub github_id: Option<u64>,
Expand All @@ -60,77 +60,8 @@ pub struct User {
#[derive(Serialize, Deserialize, Clone)]
pub struct UserPayoutData {
pub balance: Decimal,
pub payout_wallet: Option<RecipientWallet>,
pub payout_wallet_type: Option<RecipientType>,
pub payout_address: Option<String>,
}

#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Debug)]
#[serde(rename_all = "snake_case")]
pub enum RecipientType {
Email,
Phone,
UserHandle,
}

impl std::fmt::Display for RecipientType {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
fmt.write_str(self.as_str())
}
}

impl RecipientType {
pub fn from_string(string: &str) -> RecipientType {
match string {
"user_handle" => RecipientType::UserHandle,
"phone" => RecipientType::Phone,
_ => RecipientType::Email,
}
}

pub fn as_str(&self) -> &'static str {
match self {
RecipientType::Email => "email",
RecipientType::Phone => "phone",
RecipientType::UserHandle => "user_handle",
}
}
}

#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Debug)]
#[serde(rename_all = "snake_case")]
pub enum RecipientWallet {
Venmo,
Paypal,
}

impl std::fmt::Display for RecipientWallet {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
fmt.write_str(self.as_str())
}
}

impl RecipientWallet {
pub fn from_string(string: &str) -> RecipientWallet {
match string {
"venmo" => RecipientWallet::Venmo,
_ => RecipientWallet::Paypal,
}
}

pub fn as_str(&self) -> &'static str {
match self {
RecipientWallet::Paypal => "paypal",
RecipientWallet::Venmo => "venmo",
}
}

pub fn as_str_api(&self) -> &'static str {
match self {
RecipientWallet::Paypal => "PayPal",
RecipientWallet::Venmo => "Venmo",
}
}
pub trolley_id: Option<String>,
pub trolley_status: Option<String>,
}

use crate::database::models::user_item::User as DBUser;
Expand Down
Loading

0 comments on commit f6da325

Please sign in to comment.