From b3d68828b416c568dae63c3054122747242336b4 Mon Sep 17 00:00:00 2001 From: flifloo Date: Sun, 28 Apr 2019 13:59:39 +0200 Subject: [PATCH] Add Trello valid token check and warning --- .gitignore | 4 ++++ site.py | 24 +++++++++++------------- templates/settings.html | 5 ++++- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index e10cc03..00f2186 100644 --- a/.gitignore +++ b/.gitignore @@ -108,3 +108,7 @@ venv.bak/ # Credentials files twitter_credentials.py +trello_credentials.py + +# Database +database.db diff --git a/site.py b/site.py index a5ce564..4d63c8c 100644 --- a/site.py +++ b/site.py @@ -1,5 +1,5 @@ from flask import Flask, request, redirect, session, render_template -import twitter_credentials, tweepy, database +import twitter_credentials, tweepy, database, trello_credentials, trello app = Flask(__name__) app.secret_key = "*i9uld6u@t!kxl9%o+byxqf14&a&&@y@q=l$!lg4m%b-a*^o(a" @@ -47,13 +47,6 @@ def twlogout(): session.pop("access_secret_token", None) return redirect("/") -@app.route("/trlogin") -def trlogin(): - if not is_twlogin(session): - return redirect("/") - if request.args.get("token"): - database.tradd(twapi_login(session).me().id, request.args.get("token")) - return redirect("/settings") @app.route("/trlogout") def trlogout(): @@ -71,11 +64,16 @@ def home(): def settings(): if not is_twlogin(session): return redirect("/") - api = twapi_login(session) - if "token" in request.form: - database.tradd(api.me().id, request.form["token"]) - return redirect("/settings") - return render_template("settings.html", login = True, trlogin = is_trlogin(session)) + + trloginfail = False + if "trtoken" in request.form: + try: + trello.TrelloClient(api_key = trello_credentials.api_key, token = request.form["trtoken"]).list_boards() + except: + trloginfail = True + else: + database.tradd(twapi_login(session).me().id, request.form["trtoken"]) + return render_template("settings.html", login = True, trlogin = is_trlogin(session), trloginfail = trloginfail) @app.route("/twpost") def twpost(): diff --git a/templates/settings.html b/templates/settings.html index fc09e9d..21d1dca 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -11,6 +11,9 @@

Connexions

+ {% if trloginfail and not trlogin %} +

Invalid Trello token !

+ {% endif %}

Trello : {% if trlogin %} Connected

@@ -19,7 +22,7 @@ Disconnected

Click here and give the token bellow

- +
{% endif %}