2018-12-04 17:21:08 +01:00
|
|
|
# coding: utf-8
|
|
|
|
from flask import Flask, render_template, session, request, redirect, flash
|
|
|
|
import os
|
2018-11-28 11:08:23 +01:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
2018-12-04 17:21:08 +01:00
|
|
|
@app.route('/')
|
|
|
|
def home():
|
|
|
|
if not session.get('logged_in'):
|
|
|
|
return render_template('login.html')
|
|
|
|
else:
|
|
|
|
if session.get('user_type') == 'lecturer':
|
|
|
|
return redirect('/lecturer')
|
|
|
|
else:
|
|
|
|
return redirect('/student')
|
|
|
|
|
2018-12-05 10:57:01 +01:00
|
|
|
@app.route('/student',methods=['GET', 'POST'])
|
2018-11-28 11:08:23 +01:00
|
|
|
def student():
|
2018-12-05 10:57:01 +01:00
|
|
|
if request.method == 'POST':
|
|
|
|
question = request.get_data().decode("utf-8")
|
|
|
|
question = question.split('=')
|
|
|
|
print(question[1])
|
|
|
|
return '200'
|
|
|
|
else:
|
|
|
|
return render_template('student.html')
|
2018-11-28 11:08:23 +01:00
|
|
|
|
|
|
|
@app.route('/lecturer')
|
|
|
|
def lecturer():
|
2018-12-04 17:21:08 +01:00
|
|
|
return render_template('lecturer.html')
|
2018-11-28 11:08:23 +01:00
|
|
|
|
2018-12-04 17:21:08 +01:00
|
|
|
@app.route('/login', methods=['POST'])
|
|
|
|
def do_login():
|
|
|
|
if request.form['password'] == 'lecturer' and request.form['name'] == 'lecturer':
|
|
|
|
session['logged_in'] = True
|
|
|
|
session['user_type'] = 'lecturer'
|
|
|
|
elif request.form['password'] == 'student' and request.form['name'] == 'student':
|
|
|
|
session['logged_in'] = True
|
|
|
|
session['user_type'] = 'student'
|
|
|
|
else:
|
|
|
|
flash('Niepoprawne hasło/nazwa użytkownika!'.decode('utf-8'))
|
|
|
|
return redirect('/')
|
2018-11-28 11:08:23 +01:00
|
|
|
|
2018-12-04 17:21:08 +01:00
|
|
|
@app.route('/logout', methods=['GET', 'POST'])
|
|
|
|
def logout():
|
|
|
|
session['logged_in'] = False
|
|
|
|
return redirect('/')
|
2018-11-28 11:08:23 +01:00
|
|
|
|
2018-12-05 11:26:32 +01:00
|
|
|
@app.route('/upvote', methods=['POST'])
|
|
|
|
def upvote():
|
|
|
|
if request.method == 'POST':
|
|
|
|
print("upvoted")
|
|
|
|
return '200'
|
|
|
|
|
|
|
|
|
2018-11-28 11:08:23 +01:00
|
|
|
if __name__ == '__main__':
|
2018-12-04 17:21:08 +01:00
|
|
|
app.secret_key = os.urandom(12)
|
|
|
|
app.run(host='0.0.0.0', debug = True)
|