145 lines
4.1 KiB
Python
145 lines
4.1 KiB
Python
from nicegui import ui, app
|
|
from users import *
|
|
from definitions import *
|
|
import hashlib
|
|
|
|
def cookie_hash(user, password):
|
|
return hashlib.sha256(b"{user}{app.storage.user['id']}{password}").hexdigest()
|
|
|
|
def adminsettings():
|
|
# Settingsdatei einlesen
|
|
try:
|
|
with open(f"{scriptpath}/{usersettingsfilename}") as json_file:
|
|
data = json.load(json_file)
|
|
json_file.close()
|
|
return(data)
|
|
except:
|
|
return(-1)
|
|
|
|
@ui.page('/login')
|
|
def page_login():
|
|
|
|
# Settingsdatei einlesen
|
|
data = adminsettings()
|
|
|
|
def login():
|
|
nonlocal data
|
|
|
|
if username.value == data["admin_user"]:
|
|
if password.value == data["admin_password"]:
|
|
active_login = cookie_hash(data["admin_user"], data["admin_password"])
|
|
app.storage.user['secret'] = active_login
|
|
ui.navigate.to("/admin")
|
|
else:
|
|
ui.notify("Login fehlgeschlagen")
|
|
|
|
ui.markdown(f"## {app_title} {app_version}")
|
|
ui.markdown("Bitte einloggen")
|
|
with ui.grid(columns=2):
|
|
ui.markdown("Benutzer:")
|
|
username = ui.input('Benutzername')
|
|
ui.markdown("Passwort:")
|
|
password = ui.input('Passwort', password=True)
|
|
ui.button(text="Login", on_click=lambda: login())
|
|
|
|
@ui.page('/admin')
|
|
def page_admin():
|
|
data = adminsettings()
|
|
active_login = cookie_hash(data["admin_user"], data["admin_password"])
|
|
try:
|
|
browser_cookie = app.storage.user['secret']
|
|
except:
|
|
browser_cookie = ""
|
|
|
|
# Adminseite
|
|
if browser_cookie == active_login:
|
|
ui.markdown(f"##{app_title} {app_version}")
|
|
ui.markdown("###Administrator Benutzer")
|
|
with ui.grid(columns=2):
|
|
ui.label("Benutzername des Adminstrators")
|
|
admin_user = ui.input()
|
|
admin_user.value = data["admin_user"]
|
|
ui.label("Passwort des Adminsistrators")
|
|
admin_password = ui.input(password=True)
|
|
admin_password.value = data["admin_password"]
|
|
|
|
ui.markdown("###Benutzerverwaltung")
|
|
userlist = list_users()
|
|
with ui.grid(columns=2):
|
|
for name in userlist:
|
|
ui.label(name)
|
|
ui.button("Löschen")
|
|
|
|
# Alternativ zur Loginseite navigieren
|
|
else:
|
|
ui.navigate.to("/login")
|
|
|
|
@ui.page('/stamping')
|
|
def page_stamping():
|
|
ui.label('Stempelsteite')
|
|
|
|
@ui.page('/touchscreen')
|
|
def page_touchscreen():
|
|
|
|
def button_click(name):
|
|
nonlocal buttons
|
|
current_user = user(name)
|
|
current_user.timestamp()
|
|
if current_user.stamp_status() == status_in:
|
|
buttons[name].props('color=green')
|
|
ui.notify(status_in)
|
|
else:
|
|
buttons[name].props('color=red')
|
|
ui.notify(status_out)
|
|
|
|
ui.markdown(f"##{app_title} {app_version}")
|
|
|
|
userlist = list_users()
|
|
number_of_users = len(userlist)
|
|
buttons = { }
|
|
|
|
if number_of_users > 5:
|
|
number_of_columns = 5
|
|
else:
|
|
number_of_columns = number_of_users
|
|
|
|
|
|
with ui.grid(columns=number_of_columns):
|
|
for name in userlist:
|
|
current_user = user(name)
|
|
current_button = ui.button(on_click=lambda name=name: button_click(name))
|
|
with current_button:
|
|
try:
|
|
with open(current_user.photofile, 'r') as file:
|
|
pass
|
|
file.close()
|
|
ui.image(current_user.photofile)
|
|
except:
|
|
pass
|
|
ui.label(current_user.fullname)
|
|
if current_user.stamp_status() == status_in:
|
|
current_button.props('color=green')
|
|
else:
|
|
current_button.props('color=red')
|
|
buttons[name] = current_button
|
|
|
|
|
|
@ui.page('/userlist')
|
|
def page_userlist():
|
|
|
|
def click_button(button):
|
|
ui.notify(button)
|
|
|
|
ui.markdown(f"#{app_title} {app_version}")
|
|
|
|
userlist = list_users()
|
|
buttons = { }
|
|
|
|
for name in userlist:
|
|
button = ui.button(text=name, on_click=lambda name=name:click_button(name) )
|
|
buttons[name] = button
|
|
|
|
ui.run(port=8090, storage_secret="test")
|
|
|
|
|