From 594a078515509d8aa0ec5d056068dd77845af439 Mon Sep 17 00:00:00 2001 From: Lynne Date: Mon, 12 Nov 2018 21:15:08 +1000 Subject: [PATCH] added connection completion page --- templates/cc_connect_complete.html | 17 ++++++++++ web.py | 51 +++++++++++++++++++----------- 2 files changed, 49 insertions(+), 19 deletions(-) create mode 100644 templates/cc_connect_complete.html diff --git a/templates/cc_connect_complete.html b/templates/cc_connect_complete.html new file mode 100644 index 0000000..39828fd --- /dev/null +++ b/templates/cc_connect_complete.html @@ -0,0 +1,17 @@ + + + + Curious Greg - Curious Cat Connection + {% include 'imports.html' %} + + +

Connected to Curious Cat

+

Your Curious Cat profile has been connected.

+
+
+
{{ session['cc'] }}

+ Continue +
+{% include 'footer.html' %} + + \ No newline at end of file diff --git a/web.py b/web.py index 098bab9..be4cf15 100755 --- a/web.py +++ b/web.py @@ -23,24 +23,23 @@ db = mysql.connector.connect(user=cfg['dbuser'], password=cfg['dbpass'], databas c = db.cursor() dc = db.cursor(dictionary=True) # MariaDB [curiousgreg]> DESCRIBE data; -# +---------------------+--------------+------+-----+------------------------------------------------+-----------------------------+ -# | Field | Type | Null | Key | Default | Extra | -# +---------------------+--------------+------+-----+------------------------------------------------+-----------------------------+ -# | username | varchar(64) | NO | PRI | NULL | | -# | instance | varchar(128) | NO | PRI | NULL | | -# | password | tinytext | NO | | NULL | | -# | avi | text | NO | | NULL | | -# | secret | tinytext | NO | | NULL | | -# | client_id | varchar(128) | NO | | NULL | | -# | client_secret | tinytext | NO | | NULL | | -# | cc | tinytext | YES | | NULL | | -# | ccavi | varchar(128) | YES | | https://lynnesbian.space/res/ceres/cc-smol.png | | -# | latest_post | tinytext | YES | | NULL | | -# | latest_timestamp | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP | -# | time_between_checks | int(11) | YES | | NULL | | -# | settings | longtext | YES | | NULL | | -# +---------------------+--------------+------+-----+------------------------------------------------+-----------------------------+ -c.execute("CREATE TABLE IF NOT EXISTS `data` (username VARCHAR(64) NOT NULL, instance VARCHAR(128) NOT NULL, password TINYTEXT NOT NULL, avi TEXT NOT NULL, secret TINYTEXT NOT NULL, client_id VARCHAR(128) NOT NULL, client_secret TINYTEXT NOT NULL, cc TINYTEXT, ccavi VARCHAR(128) DEFAULT 'https://lynnesbian.space/res/ceres/cc-smol.png', latest_post TINYTEXT, latest_timestamp TIMESTAMP, time_between_checks INT, settings LONGTEXT, PRIMARY KEY(username, instance))") +# +---------------------+--------------+------+-----+------------------------------------------------+-------+ +# | Field | Type | Null | Key | Default | Extra | +# +---------------------+--------------+------+-----+------------------------------------------------+-------+ +# | username | varchar(64) | NO | PRI | NULL | | +# | instance | varchar(128) | NO | PRI | NULL | | +# | password | tinytext | NO | | NULL | | +# | avi | text | NO | | NULL | | +# | secret | tinytext | NO | | NULL | | +# | client_id | varchar(128) | NO | | NULL | | +# | client_secret | tinytext | NO | | NULL | | +# | cc | tinytext | YES | | NULL | | +# | ccavi | varchar(128) | YES | | https://lynnesbian.space/res/ceres/cc-smol.png | | +# | latest_post | tinytext | YES | | NULL | | +# | time_between_checks | int(11) | YES | | NULL | | +# | settings | longtext | YES | | NULL | | +# +---------------------+--------------+------+-----+------------------------------------------------+-------+ +c.execute("CREATE TABLE IF NOT EXISTS `data` (username VARCHAR(64) NOT NULL, instance VARCHAR(128) NOT NULL, password TINYTEXT NOT NULL, avi TEXT NOT NULL, secret TINYTEXT NOT NULL, client_id VARCHAR(128) NOT NULL, client_secret TINYTEXT NOT NULL, cc TINYTEXT, ccavi VARCHAR(128) DEFAULT 'https://lynnesbian.space/res/ceres/cc-smol.png', latest_post TINYTEXT, time_between_checks INT, settings LONGTEXT, PRIMARY KEY(username, instance))") app = Flask(cfg['name']) app.secret_key = cfg['flask_key'] @@ -194,7 +193,8 @@ def ccc_a(): #step one of curiouscat connection: retreive details session['cctemp'] = { "cc":j['userData']['username'], "ccavi":j['userData']['avatar'], - "ccid":j['userData']['id'] + "ccid":j['userData']['id'], + "latest_post":j['posts'][0]['timestamp'] } return redirect('/cc_connect/confirm') @@ -222,3 +222,16 @@ def ccc_b(): @app.route('/cc_connect/code') def cc_connect_code(): return render_template('cc_connect_code.html') + +@app.route('/internal/ccc_c', methods=['POST']) +def ccc_c(): + if request.form['challenge'] != session['cctemp']['challenge']: + return redirect('/cc_connect/code?invalid') + for item in ['cc', 'ccavi']: + session[item] = session['cctemp'][item] + c.execute("UPDATE data SET cc = %s, ccavi = %s, latest_post = %s, time_between_checks = %s WHERE username = %s AND instance = %s", (session['cc'], session['ccavi'], session['cctemp']['latest_post'], 1, session['username'], session['instance'])) + redirect('/cc_connect/complete') + +@app.route('/cc_connect/complete') +def cc_connect_complete(): + return render_template('cc_connect_complete.html', bg="background-image:url('{}')".format(session['ccavi']))