Compare commits
3 commits
7e66e47656
...
db54460a85
Author | SHA1 | Date | |
---|---|---|---|
db54460a85 | |||
22ff8c6767 | |||
3ab5364ef0 |
6 changed files with 60 additions and 16 deletions
|
@ -1,6 +1,6 @@
|
|||
body {
|
||||
font-family: sans-serif;
|
||||
margin: 5%;
|
||||
margin: 2.5%;
|
||||
text-align: center;
|
||||
background-color: #282c37;
|
||||
color: white;
|
||||
|
@ -19,8 +19,10 @@ h2 {
|
|||
}
|
||||
#footer {
|
||||
position:absolute;
|
||||
bottom:5%;
|
||||
width:90%;
|
||||
bottom:2.5%;
|
||||
width:95%;
|
||||
color:#aaa;
|
||||
font-size:0.8em;
|
||||
}
|
||||
#logo-main {
|
||||
height:300px;
|
||||
|
@ -37,7 +39,7 @@ input {
|
|||
margin:20px;
|
||||
font-size:1.2em;
|
||||
}
|
||||
button {
|
||||
button, .button {
|
||||
font-size:1em;
|
||||
text-transform: uppercase;
|
||||
color:#2b90d9;
|
||||
|
@ -47,8 +49,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;
|
||||
}
|
||||
|
|
5
templates/footer.html
Normal file
5
templates/footer.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
<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,9 +16,6 @@
|
|||
<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>
|
||||
<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>
|
||||
{% include 'footer.html' %}
|
||||
</body>
|
||||
</html>
|
|
@ -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.
|
||||
|
|
25
templates/login.html
Normal file
25
templates/login.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
<!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,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,11 +51,11 @@ 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",
|
||||
}
|
||||
|
||||
|
||||
url = "{}/oauth/authorize?{}".format(session['instance_url'], urllib.parse.urlencode(params))
|
||||
|
||||
return url
|
||||
|
@ -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