dualis-poc

This commit is contained in:
2023-11-21 23:24:31 +01:00
parent c111b93480
commit b225c2bc71
9 changed files with 173 additions and 18 deletions

88
app.py
View File

@ -2,42 +2,108 @@
import os
from flask import Flask
from flask import render_template, url_for, send_from_directory, redirect, request, send_file
from werkzeug.utils import secure_filename
from flask_sqlalchemy import SQLAlchemy
import pymysql
from werkzeug.security import generate_password_hash, check_password_hash
import hashlib
import dualisauth
from fetchRAPLA import *
from get_mysql import get_mysql
app = Flask(__name__)
db = SQLAlchemy()
dbpw = get_mysql()
app.config['SECRET_KEY'] = 'ASDF)uhdsklvbkuezafdpo12i34rewfgvoukzgp3zerfpg8owiu2301394trilfkj'
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://paulmrtn:' + dbpw + '@localhost/paulmrtn_DUALHUB'
db.init_app(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
email = db.Column(db.String(100), unique=True)
password = db.Column(db.String(100))
name = db.Column(db.String(1000))
@app.route("/")
def index():
return render_template('index.html', headermessage='Header', message='DualHub')
@app.route("/<string:msg>")
def make_msg(msg):
message = msg
return render_template('index.html', message="DualHub", headermessage=message)
@app.route("/backendpoc/error<int:ecode>")
def error(ecode):
if ecode == 900:
msg = "Ungültige RAPLA-URL! Sicher, dass der Link zum DHBW-Rapla führt?"
elif ecode == 899:
msg = "Der Kalender wurde nicht gefunden! Sicher, dass der Link korrekt ist?"
else:
msg = "Unbekannter Fehler!"
return render_template('index.html', message=msg, headermessage="DualHub")
@app.route("/rapla", methods=["GET", "POST"])
@app.route("/backendpoc/rapla")
def chooseRaplas():
r = getRaplas()
return render_template("rapla.html", raplas=r)
@app.route("/plan")
@app.route("/backendpoc/plan", methods=["POST"])
def getRapla():
file = str(request.values.get("file"))
url = str(request.values.get("url"))
file = str(request.form.get("file"))
url = str(request.form.get("url"))
if file == url == "None":
return redirect(url_for("chooseRaplas"))
if file != "None":
print(file)
return send_file("calendars/" + file)
elif url != "None":
file = getNewRapla(url)
if type(file) != int:
if type(file) is not int:
return send_file("calendars/" + file)
else:
return redirect(url_for("error", ecode=file + 900))
return render_template("index.html")
@app.route("/backendpoc/log-in")
def login(ecode: int = None):
if ecode:
print(ecode)
return render_template("login.html")
@app.route("/backendpoc/log-in", methods=["POST"])
def login_post():
email = request.form.get("email")
password = request.form.get("password")
user = User.query.filter_by(email=email).first()
if user:
if check_password_hash(user.password, password):
return redirect(url_for("index"))
else:
t = dualisauth.checkUser(email, password)
if t == -2:
return redirect(url_for("login", ecode=-2))
else:
user.password = generate_password_hash(password, method="pbkdf2:sha256")
db.session.commit()
return redirect(url_for("index"))
t = dualisauth.checkUser(email, password)
if t == -2:
return redirect(url_for("login", ecode=-2))
hashid = int(hashlib.sha1(email.encode("utf-8")).hexdigest(), 16) % (10 ** 12)
hashpw = generate_password_hash(password, method="pbkdf2:sha256")
new_user = User(id=hashid, email=email, password=hashpw)
db.session.add(new_user)
db.session.commit()
return redirect(url_for("index"))
if __name__ == "__main__":
app.run(host='0.0.0.0', port=2024, debug=True)