With first webui
This commit is contained in:
37
frontend/app.py
Normal file
37
frontend/app.py
Normal file
@@ -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."
|
||||
16
main.py
16
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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
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
|
||||
@@ -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")
|
||||
db_con.close()
|
||||
141
templates/login.html
Normal file
141
templates/login.html
Normal file
@@ -0,0 +1,141 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Login</title>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;600&display=swap');
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
font-family: 'Poppins', sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
height: 100vh;
|
||||
background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.login-container {
|
||||
background: white;
|
||||
max-width: 400px;
|
||||
width: 100%;
|
||||
padding: 40px 30px 50px;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 20px 40px rgba(0,0,0,0.2);
|
||||
text-align: center;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.login-container:hover {
|
||||
transform: translateY(-8px);
|
||||
box-shadow: 0 30px 60px rgba(0,0,0,0.3);
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 30px;
|
||||
font-size: 28px;
|
||||
letter-spacing: 1.2px;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
margin-bottom: 25px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #555;
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
input[type="email"],
|
||||
input[type="password"] {
|
||||
width: 100%;
|
||||
padding: 14px 18px;
|
||||
font-size: 16px;
|
||||
border-radius: 12px;
|
||||
border: 2px solid #ddd;
|
||||
transition: 0.3s border-color ease;
|
||||
box-shadow: 0 2px 5px rgba(0,0,0,0.05);
|
||||
}
|
||||
|
||||
input[type="email"]:focus,
|
||||
input[type="password"]:focus {
|
||||
border-color: #2575fc;
|
||||
outline: none;
|
||||
box-shadow: 0 0 12px rgba(37, 117, 252, 0.5);
|
||||
}
|
||||
|
||||
button {
|
||||
width: 100%;
|
||||
padding: 16px 0;
|
||||
margin-top: 10px;
|
||||
background-color: #2575fc;
|
||||
border: none;
|
||||
border-radius: 14px;
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 1px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 10px 20px rgba(37, 117, 252, 0.4);
|
||||
transition: background-color 0.3s ease, box-shadow 0.3s ease;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #1859d6;
|
||||
box-shadow: 0 15px 25px rgba(24, 89, 214, 0.6);
|
||||
}
|
||||
|
||||
.error-message {
|
||||
margin-top: 20px;
|
||||
color: #ff4d4f;
|
||||
font-weight: 600;
|
||||
font-size: 15px;
|
||||
text-align: center;
|
||||
background: #ffe6e6;
|
||||
padding: 10px 15px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 2px 6px rgba(255,77,79,0.3);
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-container">
|
||||
<h2>Login to Your Account</h2>
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
<div class="error-message" style="display: block;">
|
||||
{% for category, message in messages %}
|
||||
{{ message }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
<form method="POST" action="{{ url_for('login') }}">
|
||||
<div class="input-group">
|
||||
<label for="email">Email Address</label>
|
||||
<input type="email" id="email" name="email" placeholder="you@example.com" required />
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" name="password" placeholder="Your password" required />
|
||||
</div>
|
||||
<button type="submit">Log In</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,4 @@
|
||||
from hashlib import sha512
|
||||
|
||||
def get_password_hash(password):
|
||||
return sha512(password.encode('utf-8')).hexdigest()
|
||||
Reference in New Issue
Block a user