From 784455fe1d4650ad02f732b635b739194c348268 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Wed, 8 Nov 2023 13:33:17 +1100 Subject: [PATCH] feat: Add cookie for referral --- main.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index b04ded1..6f14be5 100644 --- a/main.py +++ b/main.py @@ -22,9 +22,17 @@ def send_report(path): @app.route('/') def index(): params = request.args + if 'r' in request.cookies: + print("Referer: " + request.cookies['r']) + return render_template('index.html', hidden=request.cookies['r'],address=address) + + if 'r' in params: print("Referer: " + params['r']) - return render_template('index.html', hidden=params['r'],address=address) + # Set cookie + resp = make_response(render_template('index.html', hidden=params['r'],address=address)) + resp.set_cookie('r', params['r'], max_age=60*60*24) + return resp return render_template('index.html',address=address) @@ -45,6 +53,9 @@ def submit(): if hidden == '': hidden = 'None' + if 'r' in request.cookies: + hidden = request.cookies['r'] + status = gift.gift(name, email, hidden, ip) print(status,flush=True)