1
0
Fork 0

Setup database, settings with start of trello connexion

This commit is contained in:
Ethanell 2019-04-28 12:29:03 +02:00
parent 1b19e93ffe
commit 8fdfae03f3
7 changed files with 135 additions and 194 deletions

42
database.py Normal file
View file

@ -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")

79
site.py
View file

@ -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")

View file

@ -1,42 +1,5 @@
<!DOCTYPE HTML>
<!--
Spectral by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
<head>
<title>Elements - Spectral by HTML5 UP</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="assets/css/main.css" />
<noscript><link rel="stylesheet" href="assets/css/noscript.css" /></noscript>
</head>
<body class="is-preload">
<!-- Page Wrapper -->
<div id="page-wrapper">
<!-- Header -->
<header id="header">
<h1><a href="index.html">Spectral</a></h1>
<nav id="nav">
<ul>
<li class="special">
<a href="#menu" class="menuToggle"><span>Menu</span></a>
<div id="menu">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="generic.html">Generic</a></li>
<li><a href="elements.html">Elements</a></li>
<li><a href="#">Sign Up</a></li>
<li><a href="#">Log In</a></li>
</ul>
</div>
</li>
</ul>
</nav>
</header>
{% extends "template.html" %}
{% block content %}
<!-- Main -->
<article id="main">
@ -357,30 +320,4 @@ print 'It took ' + i + ' iterations to sort the deck.';</code></pre>
</section>
</article>
<!-- Footer -->
<footer id="footer">
<ul class="icons">
<li><a href="#" class="icon fa-twitter"><span class="label">Twitter</span></a></li>
<li><a href="#" class="icon fa-facebook"><span class="label">Facebook</span></a></li>
<li><a href="#" class="icon fa-instagram"><span class="label">Instagram</span></a></li>
<li><a href="#" class="icon fa-dribbble"><span class="label">Dribbble</span></a></li>
<li><a href="#" class="icon fa-envelope-o"><span class="label">Email</span></a></li>
</ul>
<ul class="copyright">
<li>&copy; Untitled</li><li>Design: <a href="http://html5up.net">HTML5 UP</a></li>
</ul>
</footer>
</div>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.scrollex.min.js"></script>
<script src="assets/js/jquery.scrolly.min.js"></script>
<script src="assets/js/browser.min.js"></script>
<script src="assets/js/breakpoints.min.js"></script>
<script src="assets/js/util.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>
{% endblock %}

View file

@ -1,92 +0,0 @@
<!DOCTYPE HTML>
<!--
Spectral by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
<head>
<title>Generic - Spectral by HTML5 UP</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="assets/css/main.css" />
<noscript><link rel="stylesheet" href="assets/css/noscript.css" /></noscript>
</head>
<body class="is-preload">
<!-- Page Wrapper -->
<div id="page-wrapper">
<!-- Header -->
<header id="header">
<h1><a href="index.html">Spectral</a></h1>
<nav id="nav">
<ul>
<li class="special">
<a href="#menu" class="menuToggle"><span>Menu</span></a>
<div id="menu">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="generic.html">Generic</a></li>
<li><a href="elements.html">Elements</a></li>
<li><a href="#">Sign Up</a></li>
<li><a href="#">Log In</a></li>
</ul>
</div>
</li>
</ul>
</nav>
</header>
<!-- Main -->
<article id="main">
<header>
<h2>Generic Page</h2>
<p>Aliquam ut ex ut interdum donec amet imperdiet eleifend</p>
</header>
<section class="wrapper style5">
<div class="inner">
<h3>Lorem ipsum dolor</h3>
<p>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.</p>
<p>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.</p>
<hr />
<h4>Feugiat aliquam</h4>
<p>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.</p>
<p>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.</p>
</div>
</section>
</article>
<!-- Footer -->
<footer id="footer">
<ul class="icons">
<li><a href="#" class="icon fa-twitter"><span class="label">Twitter</span></a></li>
<li><a href="#" class="icon fa-facebook"><span class="label">Facebook</span></a></li>
<li><a href="#" class="icon fa-instagram"><span class="label">Instagram</span></a></li>
<li><a href="#" class="icon fa-dribbble"><span class="label">Dribbble</span></a></li>
<li><a href="#" class="icon fa-envelope-o"><span class="label">Email</span></a></li>
</ul>
<ul class="copyright">
<li>&copy; Untitled</li><li>Design: <a href="http://html5up.net">HTML5 UP</a></li>
</ul>
</footer>
</div>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.scrollex.min.js"></script>
<script src="assets/js/jquery.scrolly.min.js"></script>
<script src="assets/js/browser.min.js"></script>
<script src="assets/js/breakpoints.min.js"></script>
<script src="assets/js/util.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>

View file

@ -5,11 +5,13 @@
<section id="banner">
<div class="inner">
<h2>Cyberplanificateur</h2>
<p>Another fine responsive<br />
site template freebie<br />
crafted by <a href="http://html5up.net">HTML5 UP</a>.</p>
<p>Manage your commissions was never so easy with with the Cyberplanificateur</p>
<ul class="actions special">
<li><a href="#" class="button primary">Activate</a></li>
{% if login %}
<li><a href="#" class="button primary">Dashboard</a></li>
{% else %}
<li><a href="{{ url_for('twlogin')}}" class="button primary">Login !</a></li>
{% endif %}
</ul>
</div>
<a href="#one" class="more scrolly">Learn More</a>

31
templates/settings.html Normal file
View file

@ -0,0 +1,31 @@
{% extends "template.html" %}
{% block content %}
<!-- Main -->
<article id="main">
<header>
<h2>Settings</h2>
<p>Aliquam ut ex ut interdum donec amet imperdiet eleifend</p>
</header>
<section class="wrapper style5">
<div class="inner">
<h3>Connexions</h3>
<p>Trello :
{% if trlogin %}
<font color="green">Connected</font></p>
<a href="{{ url_for('trlogout')}}" class="button">Disconnect</a>
{% else %}
<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="submit" value="Connect" class="button primary">
</form>
{% endif %}
</div>
</section>
</article>
{% endblock %}

View file

@ -28,10 +28,10 @@
<ul>
<li><a href="{{ url_for('home') }}">Home</a></li>
{% if login %}
<li><a href="#">?</a></li>
<li><a href="{{ url_for('t_logout')}}">Log Out</a></li>
<li><a href="{{ url_for('settings')}}">Settings</a></li>
<li><a href="{{ url_for('twlogout')}}">Log Out</a></li>
{% else %}
<li><a href="{{ url_for('t_login')}}">Log In</a></li>
<li><a href="{{ url_for('twlogin')}}">Log In</a></li>
{% endif %}
</ul>
</div>