diff --git a/database.py b/database.py new file mode 100644 index 0000000..1fe73b3 --- /dev/null +++ b/database.py @@ -0,0 +1,42 @@ +import sqlite3 + +def tradd(id, token): + with sqlite3.connect('database.db') as db: + sucess = True + dbc = db.cursor() + for u in dbc.execute("SELECT * FROM trello WHERE id=?", (id,)): + sucess = False + if sucess: + dbc.execute("INSERT INTO trello (id, token) VALUES (?, ?)", (id, token)) + dbc.close() + db.commit() + return sucess + +def trrm(id): + with sqlite3.connect('database.db') as db: + dbc = db.cursor() + dbc.execute("DELETE FROM trello WHERE id=?", (id,)) + dbc.close() + db.commit() + +def trtoken(id): + with sqlite3.connect('database.db') as db: + token = False + dbc = db.cursor() + for u in dbc.execute("SELECT * FROM trello WHERE id=?;", (id,)): + token = u + dbc.close() + return token + +with sqlite3.connect('database.db') as db: + Table = False + dbc = db.cursor() + log = False + iid = None + for t in dbc.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='trello';"): + Table = True + if not Table: + dbc.execute('''CREATE TABLE trello (id text, token text)''') + dbc.close() + db.commit() + #register("flifloo", "flifloo@gmail.com", "owo") diff --git a/site.py b/site.py index f3abf66..a5ce564 100644 --- a/site.py +++ b/site.py @@ -1,10 +1,10 @@ from flask import Flask, request, redirect, session, render_template -import twitter_credentials, tweepy +import twitter_credentials, tweepy, database app = Flask(__name__) app.secret_key = "*i9uld6u@t!kxl9%o+byxqf14&a&&@y@q=l$!lg4m%b-a*^o(a" -def is_keys(session): +def is_twkeys(session): try: session["access_token"] session["access_secret_token"] @@ -13,28 +13,20 @@ def is_keys(session): else: return True -def api_login(session): +def twapi_login(session): auth = tweepy.OAuthHandler(twitter_credentials.consumer_key, twitter_credentials.consumer_secret_key) auth.set_access_token(session["access_token"], session["access_secret_token"]) return tweepy.API(auth) -def api_valid(session): - try: - api_login(session).me() - except: - return False - else: - return True +def is_twlogin(session): + return is_twkeys(session) and twapi_login(session).verify_credentials() -def is_login(session): - if is_keys(session) and api_valid(session): - return True - else: - return False +def is_trlogin(session): + return is_twkeys(session) and database.trtoken(twapi_login(session).me().id) -@app.route("/tlogin") -def t_login(): - auth = tweepy.OAuthHandler(twitter_credentials.consumer_key, twitter_credentials.consumer_secret_key, "https://cyberplanificateur.flifloo.fr/tlogin") +@app.route("/twlogin") +def twlogin(): + auth = tweepy.OAuthHandler(twitter_credentials.consumer_key, twitter_credentials.consumer_secret_key, "https://cyberplanificateur.flifloo.fr/twlogin") if request.args.get("oauth_token") and request.args.get("oauth_verifier"): auth.request_token = {"oauth_token" : request.args.get("oauth_token"), "oauth_token_secret" : request.args.get("oauth_verifier")} try: @@ -44,30 +36,59 @@ def t_login(): else: session["access_token"] = auth.access_token session["access_secret_token"] = auth.access_token_secret - elif not is_login(session): + elif not is_twlogin(session): return redirect(auth.get_authorization_url()) return redirect("/") -@app.route("/tlogout") -def t_logout(): - if is_keys(session): +@app.route("/twlogout") +def twlogout(): + if is_twkeys(session): session.pop("access_token", None) 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("/tpost") -def t_post(): - if is_login(session): - api = api_login(session) +@app.route("/trlogout") +def trlogout(): + if not is_twlogin(session): + return redirect("/") + if is_trlogin(session): + database.trrm(twapi_login(session).me().id) + return redirect("/settings") + +@app.route("/") +def home(): + return render_template("index.html", login = is_twlogin(session)) + +@app.route("/settings", methods = ['POST', 'GET']) +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)) + +@app.route("/twpost") +def twpost(): + if is_twlogin(session): + api = twapi_login(session) api.update_status("bloup") return "Send !" else: return "Not login !" -@app.route("/") -def home(): - return render_template("index.html", login = is_login(session)) +@app.route("/test") +def test(): + return render_template("elements.html") if __name__ == "__main__": app.run(debug=True, port=5000, host="0.0.0.0") diff --git a/templates/elements.html b/templates/elements.html index 8b522be..0cc993d 100644 --- a/templates/elements.html +++ b/templates/elements.html @@ -1,42 +1,5 @@ - - - - - Elements - Spectral by HTML5 UP - - - - - - - - -
- - - +{% extends "template.html" %} +{% block content %}
@@ -357,30 +320,4 @@ print 'It took ' + i + ' iterations to sort the deck.';
- - - -
- - - - - - - - - - - - \ No newline at end of file +{% endblock %} diff --git a/templates/generic.html b/templates/generic.html deleted file mode 100644 index 6017b75..0000000 --- a/templates/generic.html +++ /dev/null @@ -1,92 +0,0 @@ - - - - - Generic - Spectral by HTML5 UP - - - - - - - - -
- - - - - -
-
-

Generic Page

-

Aliquam ut ex ut interdum donec amet imperdiet eleifend

-
-
-
- -

Lorem ipsum dolor

-

Morbi mattis mi consectetur tortor elementum, varius pellentesque velit convallis. Aenean tincidunt lectus auctor mauris maximus, ac scelerisque ipsum tempor. Duis vulputate ex et ex tincidunt, quis lacinia velit aliquet. Duis non efficitur nisi, id malesuada justo. Maecenas sagittis felis ac sagittis semper. Curabitur purus leo, tempus sed finibus eget, fringilla quis risus. Maecenas et lorem quis sem varius sagittis et a est. Maecenas iaculis iaculis sem. Donec vel dolor at arcu tincidunt bibendum. Interdum et malesuada fames ac ante ipsum primis in faucibus. Fusce ut aliquet justo. Donec id neque ipsum. Integer eget ultricies odio. Nam vel ex a orci fringilla tincidunt. Aliquam eleifend ligula non velit accumsan cursus. Etiam ut gravida sapien.

- -

Vestibulum ultrices risus velit, sit amet blandit massa auctor sit amet. Sed eu lectus sem. Phasellus in odio at ipsum porttitor mollis id vel diam. Praesent sit amet posuere risus, eu faucibus lectus. Vivamus ex ligula, tempus pulvinar ipsum in, auctor porta quam. Proin nec dui cursus, posuere dui eget interdum. Fusce lectus magna, sagittis at facilisis vitae, pellentesque at etiam. Quisque posuere leo quis sem commodo, vel scelerisque nisi scelerisque. Suspendisse id quam vel tortor tincidunt suscipit. Nullam auctor orci eu dolor consectetur, interdum ullamcorper ante tincidunt. Mauris felis nec felis elementum varius.

- -
- -

Feugiat aliquam

-

Nam sapien ante, varius in pulvinar vitae, rhoncus id massa. Donec varius ex in mauris ornare, eget euismod urna egestas. Etiam lacinia tempor ipsum, sodales porttitor justo. Aliquam dolor quam, semper in tortor eu, volutpat efficitur quam. Fusce nec fermentum nisl. Aenean erat diam, tempus aliquet erat.

- -

Etiam iaculis nulla ipsum, et pharetra libero rhoncus ut. Phasellus rutrum cursus velit, eget condimentum nunc blandit vel. In at pulvinar lectus. Morbi diam ante, vulputate et imperdiet eget, fermentum non dolor. Ut eleifend sagittis tincidunt. Sed viverra commodo mi, ac rhoncus justo. Duis neque ligula, elementum ut enim vel, posuere finibus justo. Vivamus facilisis maximus nibh quis pulvinar. Quisque hendrerit in ipsum id tellus facilisis fermentum. Proin mauris dui, at vestibulum sit amet, auctor bibendum neque.

- -
-
-
- - - - -
- - - - - - - - - - - - \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index b1f4eff..09d65e0 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,11 +5,13 @@