Compare commits

..

6 commits

5 changed files with 118 additions and 2 deletions

View file

@ -30,12 +30,15 @@ h2 {
height:300px;
width:300px;
}
form, .profilecard {
form, .profilecard, #question, #codebox {
background-color: #444b5d;
display:inline-block;
padding:50px;
border-radius:5px;
font-size:1.4em;
min-width:250px;
max-width: 60vw;
line-height: 1.4em;
}
.profilecard {
padding: 30px;
@ -45,6 +48,9 @@ form, .profilecard {
white-space: nowrap;
text-overflow:ellipsis;
}
#codebox {
font-size: 1.2em;
}
input {
margin:20px;
font-size:1.2em;
@ -60,11 +66,17 @@ button, .button {
transition:0.2s all ease-in;
cursor: pointer;
text-decoration:none;
display:inline-block;
margin: 5px 0;
}
button:hover, .button:hover{
background-color:#2b90d9;
color:white;
}
button.fullwidth, .button.fullwidth {
width:100%;
box-sizing: border-box;
}
#form-avi, .pc-avi {
height: 128px;
width:128px;
@ -80,4 +92,18 @@ button:hover, .button:hover{
margin: 20px auto;
font-size:1.8em;
font-weight:300;
}
#ccprompt {
font-size: 1.2em;
line-height:2.6em;
}
.code {
background-color: white;
color: black;
font-size: 3em;
font-family: monospace;
display: inline-block;
padding: 15px;
border-radius: 10px;
margin: 15px;
}

18
templates/cc_connect.html Normal file
View file

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>Curious Greg - Curious Cat Connection</title>
{% include 'imports.html' %}
</head>
<body>
<h1>Connect to Curious Cat</h1>
<!-- <div id='logo-main'></div> -->
<form action='/internal/ccc_a' method='POST'>
<div id='form-avi' style="background-image:url('https://lynnesbian.space/res/ceres/cc-smol.png')"></div>
<label for='cc'>Curious Cat username</label><br />
<input name='cc' required /><br />
<button>Connect</button>
</form>
{% include 'footer.html' %}
</body>
</html>

View file

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Curious Greg - Curious Cat Connection</title>
{% include 'imports.html' %}
</head>
<body>
<h1>Connect to Curious Cat</h1>
<!-- <div id='logo-main'></div> -->
<div id='question'>
Continue with this account?<br /><br />
<div id='form-avi' style={{ bg }}></div>
<div id='form-avi-label'>{{ session['cctemp']['cc'] }}</div><br />
<a class='button fullwidth' href='/internal/ccc_b'>Yes</a><br />
<a class='button fullwidth' href='/cc_connect'>No</a>
</div>
{% include 'footer.html' %}
</body>
</html>

View file

@ -17,6 +17,12 @@
<div class='pc-avi' style={{ ccbg }}></div>
<span class='pc-avi-label'>{{ session['cc'] }}</span><br /><br />
</div>
{% if session['cc'] == "None" or session['cc'] == None %}
<div id='ccprompt'>
You haven't connected your Curious Cat account yet.<br>
<a href='/cc_connect' class='button'>Connect</a>
</div>
{% endif %}
{% include 'footer.html' %}
</body>
</html>

49
web.py
View file

@ -4,7 +4,9 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import requests, json, hashlib, urllib, time, re
#TODO: ADD RETROSPRING SUPPORT!
import requests, json, hashlib, urllib, time, re, random
from mastodon import Mastodon
from flask import Flask, render_template, request, session, redirect, url_for
import mysql.connector
@ -176,3 +178,48 @@ def create_account():
c.execute("INSERT INTO data (username, instance, avi, password, secret, client_id, client_secret) VALUES (%s, %s, %s, %s, %s, %s, %s)", (session['username'], session['instance'], session['avi'], pw, session['secret'], session['client_id'], session['client_secret']))
db.commit()
return redirect(url_for('home'))
#cc connection
@app.route('/cc_connect')
def cc_connect():
return render_template('cc_connect.html')
@app.route('/internal/ccc_a', methods=['POST'])
def ccc_a(): #step one of curiouscat connection: retreive details
r = requests.get("https://curiouscat.me/api/v2/profile?username={}".format(request.form['cc']))
j = r.json()
if 'error' in j:
return redirect('/cc_connect?invalid')
session['cctemp'] = {
"cc":j['userData']['username'],
"ccavi":j['userData']['avatar'],
"ccid":j['userData']['id']
}
return redirect('/cc_connect/confirm')
@app.route('/cc_connect/confirm')
def cc_connect_confirm():
return render_template('cc_connect_confirm.html', bg="background-image:url('{}')".format(session['cctemp']['ccavi']))
@app.route('/internal/ccc_b')
def ccc_b():
session['cctemp']['challenge'] = random.randint(100000, 999999) #provided by CG
session['cctemp']['response'] = random.randint(100000, 999999) #user will be asked to answer with this code to prove it's really them
session.modified = True
form_data = {
"addressees": session['cctemp']['ccid'],
"anon": "true",
"question": "Hi! Please respond to this question with the code given to you by Curious Greg. If you did not request this code, you may safely delete this question. Challenge: {}".format(session['cctemp']['challenge'])
}
r = requests.post("https://curiouscat.me/api/v2/post/create", data=form_data)
j = r.json()
if 'success' in j and j['success'] == True:
return redirect('/cc_connect/code')
else:
#todo: handle error properly
return False
@app.route('/cc_connect/code')
def cc_connect_code():
return render_template('cc_connect_code.html')