added login page links and redirect
This commit is contained in:
parent
7e66e47656
commit
3ab5364ef0
3 changed files with 24 additions and 9 deletions
|
@ -37,7 +37,7 @@ input {
|
|||
margin:20px;
|
||||
font-size:1.2em;
|
||||
}
|
||||
button {
|
||||
button, .button {
|
||||
font-size:1em;
|
||||
text-transform: uppercase;
|
||||
color:#2b90d9;
|
||||
|
@ -47,8 +47,9 @@ button {
|
|||
padding:10px 25px;
|
||||
transition:0.2s all ease-in;
|
||||
cursor: pointer;
|
||||
text-decoration:none;
|
||||
}
|
||||
button:hover{
|
||||
button:hover, .button:hover{
|
||||
background-color:#2b90d9;
|
||||
color:white;
|
||||
}
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
<form onsubmit='cont(); return false'>
|
||||
<label for='instance'>Instance URL</label><br />
|
||||
<input name='instance' placeholder='mastodon.social' id='instance-input' /><br />
|
||||
<button class='loading'>Continue</button>
|
||||
<button class='loading'>Sign Up</button>
|
||||
</form>
|
||||
<br /><br />
|
||||
<a class='button' href='/login'>Log In</a>
|
||||
<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 />
|
||||
Curious Greg will not function without JavaScript. Please ensure you have JavaScript enabled.
|
||||
|
|
22
web.py
22
web.py
|
@ -7,13 +7,14 @@
|
|||
import requests, sqlite3, json
|
||||
from mastodon import Mastodon
|
||||
from flask import Flask, render_template, request, session, redirect, url_for
|
||||
import bcrypt
|
||||
import urllib
|
||||
|
||||
cfg = json.load(open("meta.json"))
|
||||
|
||||
db = sqlite3.connect("database.db")
|
||||
db = sqlite3.connect("database.db") #TODO: switch to mysql so concurrency is possible
|
||||
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 TEXT NOT NULL, instance TEXT NOT NULL, secret TEXT NOT NULL, appid TEXT NOT NULL, appsecret TEXT NOT NULL, cc TEXT, latest_post TEXT, latest_timestamp TEXT, time_between_checks INT)")
|
||||
|
||||
app = Flask(cfg['name'])
|
||||
app.secret_key = cfg['flask_key']
|
||||
|
@ -42,7 +43,7 @@ def internal_auth_a():
|
|||
|
||||
session['client_id'], session['client_secret'] = Mastodon.create_app(cfg['name'],
|
||||
api_base_url=session['instance_url'],
|
||||
scopes=["write:statuses"],
|
||||
scopes=["write:statuses", "read:accounts"],
|
||||
website=cfg['website'],
|
||||
redirect_uris=['https://cg.lynnesbian.space/internal/auth_b']
|
||||
)
|
||||
|
@ -50,7 +51,7 @@ def internal_auth_a():
|
|||
params = {
|
||||
"client_id": session['client_id'],
|
||||
"client_secret":session['client_secret'],
|
||||
"scope":"write:statuses",
|
||||
"scope":"write:statuses+read:accounts",
|
||||
"redirect_uri": "https://cg.lynnesbian.space/internal/auth_b",
|
||||
"response_type":"code",
|
||||
}
|
||||
|
@ -63,11 +64,22 @@ def internal_auth_a():
|
|||
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']))
|
||||
client = Mastodon(access_token = session['secret'], api_base_url=session['instance_url'])
|
||||
session['username'] = client.account_verify_credentials()['username']
|
||||
session['acct'] = "@{}@{}".format(session['username'], session['instance_url'].replace("https://", ""))
|
||||
if c.execute("SELECT COUNT(*) FROM data WHERE username LIKE ? AND instance LIKE ?", (session['username'], session['instance_url'])).fetchone()[0] > 0:
|
||||
#user already has an account with CG
|
||||
return redirect(url_for('log_in'))
|
||||
c.execute("INSERT INTO data (username, instance, secret, appid, appsecret) VALUES (?, ?, ?, ?, ?)", (session['username'], session['instance_url'], session['secret'], session['client_id'], session['client_secret']))
|
||||
db.commit()
|
||||
return redirect(url_for('home'))
|
||||
|
||||
@app.route('/debug')
|
||||
def print_debug_info():
|
||||
return json.dumps(session._get_current_object())
|
||||
|
||||
@app.route('/login')
|
||||
def log_in():
|
||||
return render_template("login.html")
|
||||
|
||||
# return(json.dumps(client_info))
|
||||
|
|
Loading…
Reference in a new issue