Add Trello valid token check and warning
This commit is contained in:
parent
8fdfae03f3
commit
b3d68828b4
3 changed files with 19 additions and 14 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -108,3 +108,7 @@ venv.bak/
|
|||
|
||||
# Credentials files
|
||||
twitter_credentials.py
|
||||
trello_credentials.py
|
||||
|
||||
# Database
|
||||
database.db
|
||||
|
|
24
site.py
24
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():
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
<div class="inner">
|
||||
|
||||
<h3>Connexions</h3>
|
||||
{% if trloginfail and not trlogin %}
|
||||
<h4><font color="red">Invalid Trello token !</font></h4>
|
||||
{% endif %}
|
||||
<p>Trello :
|
||||
{% if trlogin %}
|
||||
<font color="green">Connected</font></p>
|
||||
|
@ -19,7 +22,7 @@
|
|||
<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>
|
||||
<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">
|
||||
</form>
|
||||
{% endif %}
|
||||
|
|
Reference in a new issue