diff --git a/frontend/app.py b/frontend/app.py new file mode 100644 index 0000000..31f3120 --- /dev/null +++ b/frontend/app.py @@ -0,0 +1,37 @@ +from flask import Flask, render_template, request, redirect, url_for, flash + +app = Flask(__name__) +app.secret_key = 'your_secret_key' + +@app.route('/') +def home(): + return redirect(url_for('login')) + +@app.route('/login', methods=['GET', 'POST']) +def login(): + if request.method == 'POST': + enter_email = request.form.get('email') + enter_password = request.form.get('password') + # TODO: Add your user verification logic here, e.g. check database + import sqlLite.get as getter + import useful.hash as hasher + pwd = getter.get_password_by_email(enter_email) + password = hasher.get_password_hash(enter_password) + print(pwd) + print(password) + if password == pwd: + return redirect(url_for('dashboard')) + elif password == None: + flash("User not found!") + return redirect(url_for("login")) + elif pwd == None: + flash("Password not found!") + return redirect(url_for("login")) + else: + flash('Invalid email or password', 'error') + + return render_template('login.html') + +@app.route('/dashboard') +def dashboard(): + return "Welcome to the dashboard! Login successful." diff --git a/main.py b/main.py index 2f20172..53dd185 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,20 @@ db_type = "sqlite" import sqlLite + +from frontend.app import app + sqlLite.set_db_name("databases/test.db") if db_type == "sqlite": - import sqlLite.get as getter import sqlLite.create as create import sqlLite.set as setter - import testing as testing + import sqlLite.get as getter + #import testing as testing + #testing.sqllite_reset() create.create_table_t_user() - setter.set_login("test@test.test", "password") - getter.get_user() - #testing.sqllite_reset(sqlitename) + setter.set_login("test", "test@test.test", "password") + setter.set_login("admin","admin@test.test", "admin") + getter.get_password_by_email("admin@fuhlig.de") +if __name__ == '__main__': + app.run(debug=True, host='0.0.0.0', port=8080) diff --git a/sqlLite/get.py b/sqlLite/get.py index 95a4771..3407f72 100644 --- a/sqlLite/get.py +++ b/sqlLite/get.py @@ -1,10 +1,40 @@ import sqlite3 from . import db_name -def get_user(): +def get_all_users(): conn = sqlite3.connect(db_name) cursor = conn.cursor() cursor.execute('select * from T_USERS') rows = cursor.fetchall() for row in rows: - print(row) \ No newline at end of file + print(row) + +def get_userinfo_by_username(username): + conn = sqlite3.connect(db_name) + cursor = conn.cursor() + cursor.execute('select * from T_USERS where username = ?', (username,)) + rows = cursor.fetchall() + for row in rows: + print(row) + +def get_password_by_username(username): + conn = sqlite3.connect(db_name) + cursor = conn.cursor() + cursor.execute('SELECT PASSWORD FROM T_USERS WHERE username = ?', (username,)) + row = cursor.fetchone() + cursor.close() + conn.close() + if row is None: + return None + return row[0] # password string + +def get_password_by_email(email): + conn = sqlite3.connect(db_name) + cursor = conn.cursor() + cursor.execute('SELECT PASSWORD FROM T_USERS WHERE EMAIL = ?', (email,)) + row = cursor.fetchone() + cursor.close() + conn.close() + if row is None: + return None + return row[0] # password string \ No newline at end of file diff --git a/sqlLite/set.py b/sqlLite/set.py index b11adab..df70439 100644 --- a/sqlLite/set.py +++ b/sqlLite/set.py @@ -1,19 +1,20 @@ from hashlib import sha512 import sqlite3 import useful.check as check +import useful.hash as hash from . import db_name -def set_password_hash(password): - return sha512(password.encode('utf-8')).hexdigest() -def set_login(email, password): + +def set_login(username, email, password): db_con = sqlite3.connect(db_name) db_cur = db_con.cursor() try: if check.check_email(email): - db_cur.execute("INSERT INTO T_USERS (USERNAME, EMAIL, PASSWORD) VALUES (?,?,?)", ('test',email, set_password_hash(password))) + db_cur.execute("INSERT INTO T_USERS (USERNAME, EMAIL, PASSWORD) VALUES (?,?,?)", (username ,email , hash.get_password_hash(password))) db_con.commit() else: print("Email entered is not valid") except sqlite3.IntegrityError: - print("Username or Email entered is not unique") \ No newline at end of file + print("Username or Email entered is not unique") + db_con.close() \ No newline at end of file diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..82d8a0c --- /dev/null +++ b/templates/login.html @@ -0,0 +1,141 @@ + + +
+ + +