Compare commits
No commits in common. "db54460a85d2a535182171a56ef2de61a2bbeec8" and "7e66e476564530a86b45d906638b264156bf1b2e" have entirely different histories.
db54460a85
...
7e66e47656
6 changed files with 16 additions and 60 deletions
|
@ -1,6 +1,6 @@
|
|||
body {
|
||||
font-family: sans-serif;
|
||||
margin: 2.5%;
|
||||
margin: 5%;
|
||||
text-align: center;
|
||||
background-color: #282c37;
|
||||
color: white;
|
||||
|
@ -19,10 +19,8 @@ h2 {
|
|||
}
|
||||
#footer {
|
||||
position:absolute;
|
||||
bottom:2.5%;
|
||||
width:95%;
|
||||
color:#aaa;
|
||||
font-size:0.8em;
|
||||
bottom:5%;
|
||||
width:90%;
|
||||
}
|
||||
#logo-main {
|
||||
height:300px;
|
||||
|
@ -39,7 +37,7 @@ input {
|
|||
margin:20px;
|
||||
font-size:1.2em;
|
||||
}
|
||||
button, .button {
|
||||
button {
|
||||
font-size:1em;
|
||||
text-transform: uppercase;
|
||||
color:#2b90d9;
|
||||
|
@ -49,9 +47,8 @@ button, .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;
|
||||
}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
<div id='footer'>
|
||||
Note that Curious Greg uses a cookie to store your login state. Deleting the cookie used by Curious Greg will log you out of your account. Posting will still function as normal.<br />
|
||||
Curious Greg will not function without JavaScript. Please ensure you have JavaScript enabled.<br />
|
||||
Created by <a href='https://fedi.lynnesbian.space/@lynnesbian'>@lynnesbian@fedi.lynnesbian.space</a> (message her about any bugs you find). Source code is available <a href='https://git.lynnesbian.space/curious-greg'>here</a>, under the <a href='https://www.mozilla.org/en-US/MPL/2.0/'>Mozilla Public License Version 2.0</a>.
|
||||
</div>
|
|
@ -16,6 +16,9 @@
|
|||
<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.
|
||||
</div>
|
||||
{% include 'footer.html' %}
|
||||
<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.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -16,10 +16,8 @@
|
|||
<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'>Sign Up</button>
|
||||
<button class='loading'>Continue</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.
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Curious Greg - Login</title>
|
||||
<link rel='stylesheet' type='text/css' href="{{ url_for('static', filename='style.css') }}" />
|
||||
<script type="text/javascript" src="{{ url_for('static', filename='script.js') }}"></script>
|
||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Log in</h1>
|
||||
<h2>Log in to your Curious Greg account.</h2>
|
||||
<noscript>
|
||||
Curious Greg will not function without JavaScript. Please ensure you have JavaScript enabled.
|
||||
</noscript>
|
||||
<!-- <div id='logo-main'></div> -->
|
||||
<form action='/internal/do_login' method='POST'>
|
||||
<label for='acct'>Mastodon Account</label><br />
|
||||
<input name='acct' placeholder='@you@instan.ce' required /><br />
|
||||
<label for='pw'>Password</label><br />
|
||||
<input type='password' placeholder='••••••••' name='pw' required /><br />
|
||||
<button>Log In</button>
|
||||
</form>
|
||||
{% include 'footer.html' %}
|
||||
</body>
|
||||
</html>
|
24
web.py
24
web.py
|
@ -7,14 +7,13 @@
|
|||
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") #TODO: switch to mysql so concurrency is possible
|
||||
db = sqlite3.connect("database.db")
|
||||
c = db.cursor()
|
||||
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)")
|
||||
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']
|
||||
|
@ -43,7 +42,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", "read:accounts"],
|
||||
scopes=["write:statuses"],
|
||||
website=cfg['website'],
|
||||
redirect_uris=['https://cg.lynnesbian.space/internal/auth_b']
|
||||
)
|
||||
|
@ -51,11 +50,11 @@ def internal_auth_a():
|
|||
params = {
|
||||
"client_id": session['client_id'],
|
||||
"client_secret":session['client_secret'],
|
||||
"scope":"write:statuses+read:accounts",
|
||||
"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
|
||||
|
@ -64,22 +63,11 @@ def internal_auth_a():
|
|||
def internal_auth_b():
|
||||
session['secret'] = request.args.get('code')
|
||||
#write details to DB
|
||||
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']))
|
||||
c.execute("INSERT INTO data (secret, appid, appsecret) VALUES (?, ?, ?, ?)", (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