def patreon_sync_post(): if "patreon" not in session: abort(401) api_client = patreon.API(session["patreon"]["access_token"]) user_response = api_client.fetch_user( None, { 'pledge': [ "amount_cents", "total_historical_amount_cents", "declined_since", "created_at", "pledge_cap_cents", "patron_pays_fees", "outstanding_payment_amount_cents" ] }) user = user_response.data() if not (user): abort(403) usr = format_patreon_user(user) if usr["titan"]["eligible_tokens"] <= 0: return ('', 402) dbpatreon = db.session.query(Patreon).filter( Patreon.user_id == usr["id"]).first() if not dbpatreon: dbpatreon = Patreon(usr["id"]) dbpatreon.total_synced = usr["titan"]["total_cents_pledged"] db.session.add(dbpatreon) set_titan_token( session["user_id"], usr["titan"]["eligible_tokens"], "PATREON {} [{}]".format(usr["attributes"]["full_name"], usr["id"])) add_badge(session["user_id"], "supporter") session["tokens"] = get_titan_token(session["user_id"]) return ('', 204)
def callback(): state = session.get('oauth2_state') if not state or request.values.get('error'): return redirect(url_for('user.logout')) discord = make_authenticated_session(state=state) discord_token = discord.fetch_token(token_url, client_secret=config['client-secret'], authorization_response=request.url) if not discord_token: return redirect(url_for('user.logout')) session['user_keys'] = discord_token session['unauthenticated'] = False session.permanent = True user = get_current_authenticated_user() session['user_id'] = int(user['id']) session['username'] = user['username'] session['discriminator'] = user['discriminator'] session['avatar'] = generate_avatar_url(user['id'], user['avatar'], user['discriminator']) session["tokens"] = get_titan_token(session["user_id"]) if session["tokens"] == -1: session["tokens"] = 0 if session["redirect"]: redir = session["redirect"] session['redirect'] = None return redirect(redir) return redirect(url_for("user.dashboard"))
def patch_titan_tokens(): user_id = request.form.get("user_id", None) amount = request.form.get("amount", None, type=int) if not user_id or not amount: abort(400) if get_titan_token(user_id) == -1: abort(409) set_titan_token(user_id, amount, "MODIFY VIA ADMIN") return ('', 204)
def post_titan_tokens(): user_id = request.form.get("user_id", None) amount = request.form.get("amount", None, type=int) reason = request.form.get("reason", None) if not user_id or not amount: abort(400) if get_titan_token(user_id) != -1: abort(409) set_titan_token(user_id, amount, "NEW VIA ADMIN [{}]".format(str(reason))) return ('', 204)
def patch_titan_tokens(): user_id = request.form.get("user_id", None) amount = request.form.get("amount", None, type=int) reason = request.form.get("reason", None) if not user_id or not amount: abort(400) if get_titan_token(user_id) == -1: abort(409) set_titan_token(user_id, amount, "MODIFY VIA ADMIN [{}]".format(str(reason))) db.session.commit() return ('', 204)
def donate_confirm(): if not request.args.get('success'): return redirect(url_for('index')) payment = paypalrestsdk.Payment.find(request.args.get('paymentId'), api=get_paypal_api()) if payment.execute({"payer_id": request.args.get('PayerID')}): trans_id = str(payment.transactions[0]["related_resources"][0]["sale"]["id"]) amount = float(payment.transactions[0]["amount"]["total"]) tokens = int(amount * 100) action = "PAYPAL {}".format(trans_id) set_titan_token(session["user_id"], tokens, action) session["tokens"] = get_titan_token(session["user_id"]) return redirect(url_for('user.donate_thanks', transaction=trans_id)) else: return redirect(url_for('index'))
def donate_thanks(): tokens = get_titan_token(session["user_id"]) transaction = request.args.get("transaction") return render_template("donate_thanks.html.j2", tokens=tokens, transaction=transaction)