added connection completion page

This commit is contained in:
Lynne Megido 2018-11-12 21:15:08 +10:00
parent f439703f1a
commit 594a078515
Signed by: lynnesbian
GPG Key ID: FB7B970303ACE499
2 changed files with 49 additions and 19 deletions

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>Curious Greg - Curious Cat Connection</title>
{% include 'imports.html' %}
</head>
<body>
<h1>Connected to Curious Cat</h1>
<h2>Your Curious Cat profile has been connected.</h2>
<div id='question'>
<div id='form-avi' style={{ bg }}></div>
<div id='form-avi-label'>{{ session['cc'] }}</div><br />
<a href='/home'>Continue</a>
</div>
{% include 'footer.html' %}
</body>
</html>

51
web.py
View File

@ -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']))