1
0
Fork 0
mirror of https://github.com/Lynnesbian/FediBooks/ synced 2024-11-25 16:48:58 +00:00

step one - basic instance validation

This commit is contained in:
Lynne Megido 2019-09-02 01:07:50 +10:00
parent ef27eacb69
commit 7572536361
2 changed files with 34 additions and 3 deletions

View file

@ -21,7 +21,7 @@
{% elif session['step'] == 2 %} {% elif session['step'] == 2 %}
<h2 class="thin centred">Detected instance type: {{ session['instance_type'] }}</h2> <h2 class="thin centred">Detected instance type: {{ session['instance_type'] }}</h2>
<p>{{ session['instance'] }} is a {{ session['instance_type'] }} instance. {% if session['instance_type'] == Pleroma %}Unfortunately, bots on Pleroma instances cannot listen for replies yet. This means that your bot will have its reply functionality disabled.{% else %}{{ session['instance_type'] }} instances are fully supported, and your bot will have all functionality available.{% endif %}</p> <p>{{ session['instance'] }} is a {{ session['instance_type'] }} instance. {% if session['instance_type'] == 'Pleroma' %}Unfortunately, bots on Pleroma instances cannot listen for replies yet. This means that your bot will have its reply functionality disabled.{% else %}{{ session['instance_type'] }} instances are fully supported, and your bot will have all functionality available.{% endif %}</p>
{% elif session['step'] == 3 %} {% elif session['step'] == 3 %}
<p>You now need to give your bot access to the {{ session['instance'] }} account you have created for it. If you have not yet created an account on {{ session['instance'] }} for your bot to use, please do so now.</p> <p>You now need to give your bot access to the {{ session['instance'] }} account you have created for it. If you have not yet created an account on {{ session['instance'] }} for your bot to use, please do so now.</p>

View file

@ -3,7 +3,7 @@ from flask_mysqldb import MySQL
import requests import requests
import MySQLdb import MySQLdb
import bcrypt import bcrypt
import json, hashlib import json, hashlib, re
cfg = json.load(open("config.json")) cfg = json.load(open("config.json"))
@ -70,8 +70,39 @@ def bot_accounts(id):
def bot_accounts_add(): def bot_accounts_add():
return render_template("bot_accounts_add.html") return render_template("bot_accounts_add.html")
@app.route("/bot/create/") @app.route("/bot/create/", methods=['GET', 'POST'])
def bot_create(): def bot_create():
if request.method == 'POST':
if session['step'] == 1:
# strip leading https://, if provided
session['instance'] = re.match(r"^(?:https?:\/\/)?(.*)", request.form['instance']).group(1)
# check for mastodon/pleroma
r = requests.get("https://{}/api/v1/instance".format(session['instance']))
if r.status_code == 200:
j = r.json()
if "Pleroma" in j['version']:
session['instance_type'] = "Pleroma"
session['step'] += 1
else:
if 'is_pro' in j['contact_account']:
# gab instance
session['error'] = "Eat shit and die, fascist scum."
else:
session['instance_type'] = "Mastodon"
session['step'] += 1
else:
# not a masto/pleroma instance
# misskey is currently unsupported
# all other instance types are also unsupported
# return an error message
#TODO: misskey
session['error'] = "Unsupported instance type."
elif session['step'] == 2:
pass
return render_template("bot_create.html") return render_template("bot_create.html")
@app.route("/do/signup", methods=['POST']) @app.route("/do/signup", methods=['POST'])