refactor donation code

master
Aevann 2023-02-01 21:49:39 +02:00
parent f4d75100b6
commit 06a70f7fd7
8 changed files with 38 additions and 48 deletions

View File

@ -13,7 +13,8 @@ export TURNSTILE_SECRET="blahblahblah"
export YOUTUBE_KEY="blahblahblah"
export VAPID_PUBLIC_KEY="blahblahblah"
export VAPID_PRIVATE_KEY="blahblahblah"
export GUMROAD_LINK="blahblahblah"
export DONATE_SERVICE="blahblahblah"
export DONATE_LINK="https://blahblahblah"
export CF_KEY="blahblahblah"
export CF_ZONE="blahblahblah"
export DEBIAN_FRONTEND="noninteractive"

View File

@ -2,9 +2,6 @@
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
# then load our required constants...
from files.helpers.config.const import FEATURES, KOFI_TOKEN
# then load all of our classes :)
from .alts import *
from .clients import *

View File

@ -42,15 +42,14 @@ TURNSTILE_SECRET = environ.get("TURNSTILE_SECRET").strip()
YOUTUBE_KEY = environ.get("YOUTUBE_KEY").strip()
VAPID_PUBLIC_KEY = environ.get("VAPID_PUBLIC_KEY").strip()
VAPID_PRIVATE_KEY = environ.get("VAPID_PRIVATE_KEY").strip()
GUMROAD_LINK = environ.get("GUMROAD_LINK").strip()
DONATE_SERVICE = environ.get("DONATE_SERVICE").strip()
DONATE_LINK = environ.get("DONATE_LINK").strip()
CF_KEY = environ.get("CF_KEY").strip()
CF_ZONE = environ.get("CF_ZONE").strip()
GLOBAL = environ.get("GLOBAL", "").strip()
blackjack = environ.get("BLACKJACK", "").strip()
blackjack2 = environ.get("BLACKJACK2", "").strip()
FP = environ.get("FP", "").strip()
KOFI_TOKEN = environ.get("KOFI_TOKEN", "").strip()
KOFI_LINK = environ.get("KOFI_LINK", "").strip()
PROGSTACK_MUL = float(environ.get("PROGSTACK_MUL", 2.0))
ENCOURAGED = environ.get("ENCOURAGED", "").strip().split()
ENCOURAGED2 = environ.get("ENCOURAGED2", "").strip().split()
@ -665,8 +664,6 @@ LEADERBOARD_LIMIT = PAGE_SIZE
HOUSE_JOIN_COST = 500
HOUSE_SWITCH_COST = 2000
DONATE_SERVICE = "KoFi" if KOFI_TOKEN else "Gumroad"
DONATE_LINK = KOFI_LINK if KOFI_TOKEN else GUMROAD_LINK
TIERS_ID_TO_NAME = {
1: "Paypig",
2: "Renthog",

View File

@ -105,12 +105,11 @@ def inject_constants():
"PIZZASHILL_ID":PIZZASHILL_ID, "DEFAULT_COLOR":DEFAULT_COLOR,
"COLORS":COLORS, "time":time, "PERMS":PERMS, "FEATURES":FEATURES,
"HOLE_NAME":HOLE_NAME, "HOLE_STYLE_FLAIR":HOLE_STYLE_FLAIR, "HOLE_REQUIRED":HOLE_REQUIRED,
"GUMROAD_LINK":GUMROAD_LINK, "DEFAULT_THEME":DEFAULT_THEME, "DESCRIPTION":DESCRIPTION,
"DEFAULT_THEME":DEFAULT_THEME, "DESCRIPTION":DESCRIPTION,
"has_sidebar":has_sidebar, "has_logo":has_logo,
"FP":FP, "patron":patron, "get_setting": get_setting,
"SIDEBAR_THREAD":SIDEBAR_THREAD, "BANNER_THREAD":BANNER_THREAD,
"BADGE_THREAD":BADGE_THREAD, "SNAPPY_THREAD":SNAPPY_THREAD,
"KOFI_TOKEN":KOFI_TOKEN, "KOFI_LINK":KOFI_LINK,
"approved_embed_hosts":approved_embed_hosts,
"site_settings":get_settings(), "EMAIL":EMAIL, "max": max, "min": min, "user_can_see":User.can_see,
"TELEGRAM_ID":TELEGRAM_ID, "EMAIL_REGEX_PATTERN":EMAIL_REGEX_PATTERN,

View File

@ -1302,39 +1302,39 @@ def claim_rewards(v):
g.db.delete(badge)
badge_grant(badge_id=20+highest_tier, user=v)
KOFI_TOKEN = environ.get("KOFI_TOKEN", "").strip()
if KOFI_TOKEN:
@app.post("/kofi")
def kofi():
data = json.loads(request.values['data'])
verification_token = data['verification_token']
if verification_token != KOFI_TOKEN: abort(400)
@app.post("/kofi")
def kofi():
if not KOFI_TOKEN: abort(404)
data = json.loads(request.values['data'])
verification_token = data['verification_token']
if verification_token != KOFI_TOKEN: abort(400)
id = data['kofi_transaction_id']
created_utc = int(time.mktime(time.strptime(data['timestamp'].split('.')[0], "%Y-%m-%dT%H:%M:%SZ")))
type = data['type']
amount = 0
try:
amount = int(float(data['amount']))
except:
abort(400, 'invalid amount')
email = data['email']
id = data['kofi_transaction_id']
created_utc = int(time.mktime(time.strptime(data['timestamp'].split('.')[0], "%Y-%m-%dT%H:%M:%SZ")))
type = data['type']
amount = 0
try:
amount = int(float(data['amount']))
except:
abort(400, 'invalid amount')
email = data['email']
transaction = Transaction(
id=id,
created_utc=created_utc,
type=type,
amount=amount,
email=email
)
transaction = Transaction(
id=id,
created_utc=created_utc,
type=type,
amount=amount,
email=email
)
g.db.add(transaction)
g.db.add(transaction)
user = g.db.query(User).filter_by(email=email, is_activated=True).order_by(User.truescore.desc()).first()
if user:
claim_rewards(user)
user = g.db.query(User).filter_by(email=email, is_activated=True).order_by(User.truescore.desc()).first()
if user:
claim_rewards(user)
return ''
return ''
@app.post("/gumroad")
def gumroad():

View File

@ -7,8 +7,8 @@
<tbody>
{% if v and v.truescore >= TRUESCORE_DONATE_MINIMUM %}
<tr>
<td>Kofi</td>
<td><a rel="nofollow noopener" href="{{KOFI_LINK}}">{{KOFI_LINK}}</a></td>
<td>{{DONATE_SERVICE}}</td>
<td><a rel="nofollow noopener" href="{{DONATE_LINK}}">{{DONATE_LINK}}</a></td>
</tr>
{% endif %}
<tr>

View File

@ -7,8 +7,8 @@
<tbody>
{% if v and v.truescore >= TRUESCORE_DONATE_MINIMUM %}
<tr>
<td>Gumroad</td>
<td><a rel="nofollow noopener" href="{{GUMROAD_LINK}}">{{GUMROAD_LINK}}</a></td>
<td>{{DONATE_SERVICE}}</td>
<td><a rel="nofollow noopener" href="{{DONATE_LINK}}">{{DONATE_LINK}}</a></td>
</tr>
{% endif %}
<tr>

View File

@ -47,11 +47,7 @@
<span class="text-small text-muted pl-1">Must be same email as the one you used to donate
{% if v.truescore >= TRUESCORE_DONATE_MINIMUM %}
on
{% if KOFI_TOKEN %}
<a rel="nofollow noopener" class="text-primary" href="{{KOFI_LINK}}">Kofi</a>
{% else %}
<a rel="nofollow noopener" class="text-primary" href="{{GUMROAD_LINK}}">Gumroad</a>
{% endif %}
<a rel="nofollow noopener" class="text-primary" href="{{DONATE_LINK}}">{{DONATE_SERVICE}}</a>
{% endif %}
</span>
{% endif %}