Neuanlage Benutzer hinzugefügt
This commit is contained in:
parent
f15ec8e809
commit
30e06cbe86
48
admin.py
48
admin.py
@ -741,8 +741,6 @@ def page_admin():
|
||||
|
||||
with ui.tab_panel(users):
|
||||
ui.markdown("###Benutzerverwaltung")
|
||||
userlist = list_users()
|
||||
userlist.sort()
|
||||
workhours = [ ]
|
||||
|
||||
with ui.row():
|
||||
@ -819,11 +817,12 @@ def page_admin():
|
||||
|
||||
def del_definitely():
|
||||
current_user.del_user()
|
||||
userlist = list_users()
|
||||
userlist.sort()
|
||||
user_selection.clear()
|
||||
user_selection.set_options(userlist)
|
||||
user_selection.value = userlist[0]
|
||||
#userlist = list_users()
|
||||
#userlist.sort()
|
||||
#user_selection.clear()
|
||||
#user_selection.set_options(userlist)
|
||||
#user_selection.value = userlist[0]
|
||||
user_ui.refresh()
|
||||
dialog.close()
|
||||
ui.notify("Benutzer gelöscht")
|
||||
|
||||
@ -886,10 +885,37 @@ def page_admin():
|
||||
ui.button("OK", on_click=dialog.close)
|
||||
dialog.open()
|
||||
|
||||
with ui.column():
|
||||
user_selection = ui.select(options=userlist, with_input=True, on_change=user_selection_changed)
|
||||
user_selection.value = userlist[0]
|
||||
ui.button("Neu")
|
||||
def dialog_new_user():
|
||||
def create_new_user():
|
||||
if user_name_input.validate():
|
||||
print(user_name_input.value)
|
||||
new_user(user_name_input.value)
|
||||
userlist = list_users()
|
||||
user_ui.refresh()
|
||||
dialog.close()
|
||||
else:
|
||||
ui.notify("Ungültiger Benutzername")
|
||||
|
||||
with ui.dialog() as dialog, ui.card():
|
||||
ui.markdown("Geben Sie den Benutzernamen für das neue Konto an:")
|
||||
user_name_input = ui.input(label="Benutzername", validation={'Leerer Benutzername nicht erlaubt': lambda value: len(value) != 0,
|
||||
'Leerzeichen im Benutzername nicht erlaubt': lambda value: " " not in value})
|
||||
with ui.row():
|
||||
ui.button("OK", on_click=create_new_user)
|
||||
ui.button("Abbrechen", on_click=dialog.close)
|
||||
dialog.open()
|
||||
|
||||
@ui.refreshable
|
||||
def user_ui():
|
||||
userlist = list_users()
|
||||
userlist.sort()
|
||||
|
||||
with ui.column():
|
||||
global user_selection
|
||||
user_selection = ui.select(options=userlist, with_input=True, on_change=user_selection_changed)
|
||||
user_selection.value = userlist[0]
|
||||
ui.button("Neu", on_click=dialog_new_user)
|
||||
user_ui()
|
||||
|
||||
with ui.column():
|
||||
with ui.card() as usersettingscard:
|
||||
|
34
users.py
34
users.py
@ -64,8 +64,8 @@ class user:
|
||||
self.timestamp()
|
||||
|
||||
# Nach zugehörigem JSON-File suchen und bei Bedarf anlegen
|
||||
json_filename = f"{self.get_stamp_file()}.json"
|
||||
try:
|
||||
json_filename = f"{self.get_stamp_file()}.json"
|
||||
with open(json_filename, 'r') as json_file:
|
||||
pass
|
||||
except:
|
||||
@ -94,9 +94,9 @@ class user:
|
||||
if len(lines)== 0:
|
||||
print(f"Keine Einträge")
|
||||
elif len(lines) % 2 == 0:
|
||||
return (status_out)
|
||||
return status_out
|
||||
else:
|
||||
return (status_in)
|
||||
return status_in
|
||||
|
||||
def last_2_timestmaps(self):
|
||||
|
||||
@ -107,8 +107,8 @@ class user:
|
||||
if len(lines) > 2:
|
||||
second_last_line = int(lines[-2])
|
||||
last_line = int(lines[-1])
|
||||
last_2_timestmaps = [second_last_line, last_line]
|
||||
return last_2_timestmaps
|
||||
last_2_timestamps = [second_last_line, last_line]
|
||||
return last_2_timestamps
|
||||
|
||||
elif len(lines) == 1:
|
||||
return int(lines[0])
|
||||
@ -117,10 +117,10 @@ class user:
|
||||
|
||||
def write_settings(self):
|
||||
dict = { }
|
||||
dict["username"] = (self.username)
|
||||
dict["fullname"] = (self.fullname)
|
||||
dict["password"] = (self.password)
|
||||
dict["workhours"] = (self.workhours)
|
||||
dict["username"] = self.username
|
||||
dict["fullname"] = self.fullname
|
||||
dict["password"] = self.password
|
||||
dict["workhours"] = self.workhours
|
||||
|
||||
json_dict = json.dumps(dict, indent=4)
|
||||
|
||||
@ -143,7 +143,7 @@ class user:
|
||||
month = str(starting_date[0])[5:7]
|
||||
day = str(starting_date[0])[8:10]
|
||||
|
||||
return (year, month, day)
|
||||
return [year, month, day]
|
||||
|
||||
def get_years(self):
|
||||
years = [ ]
|
||||
@ -196,7 +196,7 @@ class user:
|
||||
if month not in available_months:
|
||||
available_months.append(month)
|
||||
available_months.sort()
|
||||
return(available_months)
|
||||
return available_months
|
||||
|
||||
def get_timestamps(self, year, month):
|
||||
try:
|
||||
@ -216,9 +216,9 @@ class user:
|
||||
try:
|
||||
with open(f"{self.userfolder}/{year}-{month}.json", 'r') as json_file:
|
||||
data = json.load(json_file)
|
||||
return (data["archived"])
|
||||
return data["archived"]
|
||||
except:
|
||||
return(-1)
|
||||
return -1
|
||||
|
||||
def archive_hours(self, year, month, overtime: int):
|
||||
|
||||
@ -291,6 +291,7 @@ class user:
|
||||
json_file.write(json_dict)
|
||||
|
||||
def get_day_workhours(self, year, month, day):
|
||||
global hours_to_work
|
||||
workhour_entries = list(self.workhours)
|
||||
workhour_entries.sort()
|
||||
day_to_check = datetime.datetime(int(year), int(month), int(day))
|
||||
@ -381,17 +382,19 @@ class user:
|
||||
def list_users():
|
||||
|
||||
if not os.path.exists(userfolder):
|
||||
print("Kein Benutzerverzeichnis gefunden. Lege es an.")
|
||||
os.makedirs(userfolder)
|
||||
|
||||
users = [d for d in os.listdir(userfolder) if os.path.isdir(os.path.join(userfolder, d))]
|
||||
if len(users) == 0:
|
||||
print("Keine Benutzer gefunden. Lege Standardbenutzer an.")
|
||||
new_user("default")
|
||||
users = [d for d in os.listdir(userfolder) if os.path.isdir(os.path.join(userfolder, d))]
|
||||
|
||||
users.sort()
|
||||
return users
|
||||
|
||||
def new_user(username):
|
||||
def new_user(username: str):
|
||||
if not os.path.exists(userfolder):
|
||||
os.makedirs(userfolder)
|
||||
if not os.path.exists(f"{userfolder}/{username}"):
|
||||
@ -400,6 +403,8 @@ def new_user(username):
|
||||
start_date = start_date_dt.strftime("%Y-%m-%d")
|
||||
settings_to_write = standard_usersettings
|
||||
settings_to_write["workhours"][start_date] = { }
|
||||
settings_to_write["fullname"] = username
|
||||
settings_to_write["username"] = username
|
||||
for i in range(1, 8):
|
||||
settings_to_write["workhours"][start_date][str(i)] = 0
|
||||
settings_to_write["workhours"][start_date]["vacation"] = 0
|
||||
@ -412,6 +417,7 @@ def load_adminsettings():
|
||||
# Settingsdatei einlesen
|
||||
settings_filename = f"{scriptpath}/{usersettingsfilename}"
|
||||
if not os.path.exists(settings_filename):
|
||||
print("Keine Einstellungsdatei gefunden. Lege Standarddatei an.")
|
||||
with open(settings_filename, 'w') as json_file:
|
||||
json_dict = json.dumps(standard_adminsettings, indent=4)
|
||||
json_file.write(json_dict)
|
||||
|
@ -23,9 +23,6 @@ class ValueBinder:
|
||||
def __init__(self):
|
||||
self.value = ""
|
||||
|
||||
def cookie_hash(user, password):
|
||||
return hashlib.sha256(b"{user}{app.storage.user['id']}{password}").hexdigest()
|
||||
|
||||
def hash_password(password):
|
||||
return hashlib.sha256(bytes(password, 'utf-8')).hexdigest()
|
||||
|
||||
@ -98,9 +95,9 @@ def convert_seconds_to_hours(seconds):
|
||||
minutes = str(minutes)
|
||||
|
||||
if sign == "-":
|
||||
return(f"-{hours}:{minutes}")
|
||||
return f"-{hours}:{minutes}"
|
||||
else:
|
||||
return(f"{hours}:{minutes}")
|
||||
return f"{hours}:{minutes}"
|
||||
|
||||
def login_is_valid(user = -1):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user