Compare commits
No commits in common. "7e66e476564530a86b45d906638b264156bf1b2e" and "694537fdf1308c55556b34b612c645f98220b685" have entirely different histories.
7e66e47656
...
694537fdf1
3 changed files with 27 additions and 40 deletions
|
@ -1,2 +1 @@
|
||||||
Flask==1.0.2
|
Flask==1.0.2
|
||||||
bcrypt==3.1.4
|
|
|
@ -7,14 +7,14 @@
|
||||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Welcome</h1>
|
<h1>Welcome, {{ acct }}</h1>
|
||||||
<h2>You're all set up and ready to go.</h2>
|
<h2>You're all set up and ready to go.</h2>
|
||||||
<noscript>
|
<noscript>
|
||||||
Curious Greg will not function without JavaScript. Please ensure you have JavaScript enabled.
|
Curious Greg will not function without JavaScript. Please ensure you have JavaScript enabled.
|
||||||
</noscript>
|
</noscript>
|
||||||
<!-- <div id='logo-main'></div> -->
|
<!-- <div id='logo-main'></div> -->
|
||||||
<div id='body'>
|
<div id='body'>
|
||||||
You haven't posted to Curious Cat in a while, so we'll wait <strong>14 minutes</strong> until we check for new answers.
|
You haven't posted to Curious Cat in a while, so we'll wait <em>14 minutes</em> until we check for new answers.
|
||||||
</div>
|
</div>
|
||||||
<div id='footer'>
|
<div id='footer'>
|
||||||
Note that Curious Greg requires first-party cookies to be enabled. You may safely delete the cookie upon completing the connection process.<br />
|
Note that Curious Greg requires first-party cookies to be enabled. You may safely delete the cookie upon completing the connection process.<br />
|
||||||
|
|
60
web.py
60
web.py
|
@ -7,13 +7,12 @@
|
||||||
import requests, sqlite3, json
|
import requests, sqlite3, json
|
||||||
from mastodon import Mastodon
|
from mastodon import Mastodon
|
||||||
from flask import Flask, render_template, request, session, redirect, url_for
|
from flask import Flask, render_template, request, session, redirect, url_for
|
||||||
import urllib
|
|
||||||
|
|
||||||
cfg = json.load(open("meta.json"))
|
cfg = json.load(open("meta.json"))
|
||||||
|
|
||||||
db = sqlite3.connect("database.db")
|
db = sqlite3.connect("database.db")
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
c.execute("CREATE TABLE IF NOT EXISTS `data` (secret TEXT NOT NULL, appid TEXT NOT NULL, appsecret TEXT NOT NULL, cc VARCHAR, latest_post VARCHAR)")
|
c.execute("CREATE TABLE IF NOT EXISTS `data` (username VARCHAR NOT NULL, appid VARCHAR NOT NULL, appsecret VARCHAR NOT NULL, secret VARCHAR NOT NULL, latest_post VARCHAR)")
|
||||||
|
|
||||||
app = Flask(cfg['name'])
|
app = Flask(cfg['name'])
|
||||||
app.secret_key = cfg['flask_key']
|
app.secret_key = cfg['flask_key']
|
||||||
|
@ -27,47 +26,36 @@ def main():
|
||||||
|
|
||||||
@app.route('/home')
|
@app.route('/home')
|
||||||
def home():
|
def home():
|
||||||
if 'acct' in session:
|
return render_template("home.html")
|
||||||
acct = session['acct']
|
|
||||||
return render_template("home.html", acct=acct)
|
|
||||||
else:
|
|
||||||
return redirect(url_for('main'))
|
|
||||||
|
|
||||||
@app.route('/internal/auth_a')
|
@app.route('/internal/auth_a')
|
||||||
def internal_auth_a():
|
def internal_auth_a():
|
||||||
|
|
||||||
session['instance_url'] = request.args.get('url', default='mastodon.social', type=str)
|
client_id = "abc"
|
||||||
if not session['instance_url'].startswith("https://"):
|
client_secret = "123"
|
||||||
session['instance_url'] = "https://{}".format(session['instance_url'])
|
instance_url = request.args.get('url', default='mastodon.social', type=str)
|
||||||
|
if not instance_url.startswith("https://"):
|
||||||
|
instance_url = "https://{}".format(instance_url)
|
||||||
|
|
||||||
session['client_id'], session['client_secret'] = Mastodon.create_app(cfg['name'],
|
# client_id, client_secret = Mastodon.create_app(cfg['name'],
|
||||||
api_base_url=session['instance_url'],
|
# api_base_url=instance_url,
|
||||||
scopes=["write:statuses"],
|
# scopes="write:statuses",
|
||||||
website=cfg['website'],
|
# website=cfg['website'])
|
||||||
redirect_uris=['https://cg.lynnesbian.space/internal/auth_b']
|
|
||||||
|
#example URL:
|
||||||
|
#https://fedi.lynnesbian.space/oauth/authorize?scope=read:favourites&response_type=code&redirect_uri=https://t5.codesections.com&client_id=CLIENT_ID_HERE&client_secret=CLIENT_SECRET_HERE
|
||||||
|
|
||||||
|
# client_info = {
|
||||||
|
# "client_id": client_id,
|
||||||
|
# "client_secret":client_secret,
|
||||||
|
# "scopes":"write:statuses",
|
||||||
|
# "website": cfg['website']
|
||||||
|
# }
|
||||||
|
|
||||||
|
url = "{}/oauth/authorize?scope=write:statuses&response_type=code&redirect_url=https://lynnesbian.space/cg/internal/auth_b&client_id={}&client_secret={}".format(
|
||||||
|
instance_url, client_id, client_secret
|
||||||
)
|
)
|
||||||
|
|
||||||
params = {
|
|
||||||
"client_id": session['client_id'],
|
|
||||||
"client_secret":session['client_secret'],
|
|
||||||
"scope":"write:statuses",
|
|
||||||
"redirect_uri": "https://cg.lynnesbian.space/internal/auth_b",
|
|
||||||
"response_type":"code",
|
|
||||||
}
|
|
||||||
|
|
||||||
url = "{}/oauth/authorize?{}".format(session['instance_url'], urllib.parse.urlencode(params))
|
|
||||||
|
|
||||||
return url
|
return url
|
||||||
|
|
||||||
@app.route('/internal/auth_b')
|
|
||||||
def internal_auth_b():
|
|
||||||
session['secret'] = request.args.get('code')
|
|
||||||
#write details to DB
|
|
||||||
c.execute("INSERT INTO data (secret, appid, appsecret) VALUES (?, ?, ?, ?)", (session['secret'], session['client_id'], session['client_secret']))
|
|
||||||
db.commit()
|
|
||||||
|
|
||||||
@app.route('/debug')
|
|
||||||
def print_debug_info():
|
|
||||||
return json.dumps(session._get_current_object())
|
|
||||||
|
|
||||||
# return(json.dumps(client_info))
|
# return(json.dumps(client_info))
|
||||||
|
|
Loading…
Reference in a new issue