log in and store info in database
This commit is contained in:
parent
db85203d78
commit
7e66e47656
3 changed files with 39 additions and 26 deletions
|
@ -1 +1,2 @@
|
|||
Flask==1.0.2
|
||||
Flask==1.0.2
|
||||
bcrypt==3.1.4
|
|
@ -7,7 +7,7 @@
|
|||
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome, {{ acct }}</h1>
|
||||
<h1>Welcome</h1>
|
||||
<h2>You're all set up and ready to go.</h2>
|
||||
<noscript>
|
||||
Curious Greg will not function without JavaScript. Please ensure you have JavaScript enabled.
|
||||
|
|
60
web.py
60
web.py
|
@ -7,12 +7,13 @@
|
|||
import requests, sqlite3, json
|
||||
from mastodon import Mastodon
|
||||
from flask import Flask, render_template, request, session, redirect, url_for
|
||||
import urllib
|
||||
|
||||
cfg = json.load(open("meta.json"))
|
||||
|
||||
db = sqlite3.connect("database.db")
|
||||
c = db.cursor()
|
||||
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)")
|
||||
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)")
|
||||
|
||||
app = Flask(cfg['name'])
|
||||
app.secret_key = cfg['flask_key']
|
||||
|
@ -26,36 +27,47 @@ def main():
|
|||
|
||||
@app.route('/home')
|
||||
def home():
|
||||
return render_template("home.html")
|
||||
if 'acct' in session:
|
||||
acct = session['acct']
|
||||
return render_template("home.html", acct=acct)
|
||||
else:
|
||||
return redirect(url_for('main'))
|
||||
|
||||
@app.route('/internal/auth_a')
|
||||
def internal_auth_a():
|
||||
|
||||
client_id = "abc"
|
||||
client_secret = "123"
|
||||
instance_url = request.args.get('url', default='mastodon.social', type=str)
|
||||
if not instance_url.startswith("https://"):
|
||||
instance_url = "https://{}".format(instance_url)
|
||||
session['instance_url'] = request.args.get('url', default='mastodon.social', type=str)
|
||||
if not session['instance_url'].startswith("https://"):
|
||||
session['instance_url'] = "https://{}".format(session['instance_url'])
|
||||
|
||||
# client_id, client_secret = Mastodon.create_app(cfg['name'],
|
||||
# api_base_url=instance_url,
|
||||
# scopes="write:statuses",
|
||||
# website=cfg['website'])
|
||||
|
||||
#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
|
||||
session['client_id'], session['client_secret'] = Mastodon.create_app(cfg['name'],
|
||||
api_base_url=session['instance_url'],
|
||||
scopes=["write:statuses"],
|
||||
website=cfg['website'],
|
||||
redirect_uris=['https://cg.lynnesbian.space/internal/auth_b']
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
@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))
|
||||
|
|
Loading…
Reference in a new issue