1
0
Fork 0

Add Trello valid token check and warning

This commit is contained in:
Ethanell 2019-04-28 13:59:39 +02:00
parent 8fdfae03f3
commit b3d68828b4
3 changed files with 19 additions and 14 deletions

4
.gitignore vendored
View file

@ -108,3 +108,7 @@ venv.bak/
# Credentials files # Credentials files
twitter_credentials.py twitter_credentials.py
trello_credentials.py
# Database
database.db

24
site.py
View file

@ -1,5 +1,5 @@
from flask import Flask, request, redirect, session, render_template 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 = Flask(__name__)
app.secret_key = "*i9uld6u@t!kxl9%o+byxqf14&a&&@y@q=l$!lg4m%b-a*^o(a" 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) session.pop("access_secret_token", None)
return redirect("/") 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") @app.route("/trlogout")
def trlogout(): def trlogout():
@ -71,11 +64,16 @@ def home():
def settings(): def settings():
if not is_twlogin(session): if not is_twlogin(session):
return redirect("/") return redirect("/")
api = twapi_login(session)
if "token" in request.form: trloginfail = False
database.tradd(api.me().id, request.form["token"]) if "trtoken" in request.form:
return redirect("/settings") try:
return render_template("settings.html", login = True, trlogin = is_trlogin(session)) 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") @app.route("/twpost")
def twpost(): def twpost():

View file

@ -11,6 +11,9 @@
<div class="inner"> <div class="inner">
<h3>Connexions</h3> <h3>Connexions</h3>
{% if trloginfail and not trlogin %}
<h4><font color="red">Invalid Trello token !</font></h4>
{% endif %}
<p>Trello : <p>Trello :
{% if trlogin %} {% if trlogin %}
<font color="green">Connected</font></p> <font color="green">Connected</font></p>
@ -19,7 +22,7 @@
<font color="red">Disconnected</font></p> <font color="red">Disconnected</font></p>
<p><a href="https://trello.com/1/authorize?expiration=never&name=Cyberplanificateur&scope=read,write&response_type=token&key=4b9aa97a8ec693574d819aeaf9e0eefa&return_url=https://cyberplanificateur.flifloo.fr/settings">Click here</a> and give the token bellow</p> <p><a href="https://trello.com/1/authorize?expiration=never&name=Cyberplanificateur&scope=read,write&response_type=token&key=4b9aa97a8ec693574d819aeaf9e0eefa&return_url=https://cyberplanificateur.flifloo.fr/settings">Click here</a> and give the token bellow</p>
<form action = "https://cyberplanificateur.flifloo.fr/settings" method = "POST"> <form action = "https://cyberplanificateur.flifloo.fr/settings" method = "POST">
<input type="text" name="token" placeholder="Trello token" /> <input type="text" name="trtoken" placeholder="Trello token" />
<input type="submit" value="Connect" class="button primary"> <input type="submit" value="Connect" class="button primary">
</form> </form>
{% endif %} {% endif %}