ventilaar
/
twitter_zuil
Archived
1
Fork 0

moderator gui has login system

This commit is contained in:
ventilaar 2020-10-31 14:07:19 +01:00
parent c5856a40a4
commit 3c7ebc5568
7 changed files with 123 additions and 2 deletions

View File

@ -1,7 +1,7 @@
"""
deze python script werkt, en werkt in de terminal
voor een web versie, zie moderator_web.py
deze script en moderator_web.py werken onafhankelijk van elkaar
voor een gui versie, zie moderator_gui.py
deze script en moderator_gui.py werken onafhankelijk van elkaar
"""
import hashlib
import getpass

60
moderator_gui.py Normal file
View File

@ -0,0 +1,60 @@
from flask import Flask, request, render_template, session, redirect, url_for, flash
from TwitterAPI import TwitterAPI
from api_keys import *
import database_connector
import hashlib
conn = database_connector.conn
cur = database_connector.cur
app = Flask(__name__)
app.secret_key = b'890hj3h5gh0i8n5h0g8ni3hg50n8i'
def check_login(uname, pword):
hashedpass = hashlib.sha256(pword.encode('UTF-8') + 'saltandpepper'.encode('UTF-8')).hexdigest()
cur.execute("SELECT * FROM moderators WHERE naam = (%s);", [uname])
sqlreturn = cur.fetchone()
if sqlreturn == None:
return False
elif hashedpass != sqlreturn[2]:
return False
else:
return True
@app.route('/')
def root():
return render_template('root.html')
@app.route('/login', methods=['POST', 'GET'])
def login():
if request.method == 'POST':
if check_login(request.form['uname'], request.form['pword']):
session['username'] = request.form['uname']
return redirect(url_for('home'))
else:
flash('Wrong username and or password')
return render_template('login.html')
else:
if 'username' in session:
session.pop('username', None)
flash('You logged out!')
return render_template('login.html')
@app.route('/home')
def home():
if 'username' in session:
return render_template('home.html', username = session['username'])
return render_template('home.html', username = False)
@app.route('/moderation/moderate')
def moderate():
return 'Hello, World!'
@app.route('/moderation/adduser')
def adduser():
return 'Hello, World!'
if __name__ == "__main__":
app.run('0.0.0.0', debug=True)

View File

View File

@ -0,0 +1,13 @@
{% with messages = get_flashed_messages() %}
{% if messages %}
<div class="messages">
<ul class="flashes">
{% for message in messages %}
<li>
{{ message }}
</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endwith %}

16
templates/home.html Normal file
View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home</title>
</head>
<body>
{% if username == False %}
<h1>Not logged in!</h1>
<p>Click <a href="login">here</a> for the login page</p>
{% else %}
<h1>Hello {{ username }}</h1>
<p>Click <a href="login">here</a> to logout</p>
{% endif %}
</body>
</html>

20
templates/login.html Normal file
View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
{% include 'flash_template.html' %}
<h1>Please login to access home page</h1>
<form method="POST">
<label>
<input type="text" placeholder="Username" name="uname" required>
</label>
<label>
<input type="password" placeholder="Password" name="pword" required>
</label>
<button type="submit">Login</button>
</form>
</body>
</html>

12
templates/root.html Normal file
View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Root</title>
</head>
<body>
<h1>Welcome to the index page!</h1>
<p>Click <a href="login">here</a> for the login page</p>
<p>Click <a href="home">here</a> for the home page</p>
</body>
</html>