Add some new fields for users table
This commit is contained in:
@@ -10,31 +10,39 @@ from db import get_conn
|
||||
# DB Initialisierung: `users`-Tabelle
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def init_auth_db():
|
||||
"""
|
||||
Legt die users-Tabelle an.
|
||||
WICHTIG: password_hash wird als TEXT gespeichert, damit sowohl
|
||||
streamlit-authenticator als auch dein eigener bcrypt-Code kompatibel sind.
|
||||
"""
|
||||
with closing(get_conn()) as conn, conn:
|
||||
conn.execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT UNIQUE NOT NULL,
|
||||
email TEXT,
|
||||
password_hash TEXT NOT NULL,
|
||||
role TEXT NOT NULL DEFAULT 'user'
|
||||
)
|
||||
"""
|
||||
)
|
||||
# def init_auth_db():
|
||||
# """
|
||||
# Legt die users-Tabelle an.
|
||||
# WICHTIG: password_hash wird als TEXT gespeichert, damit sowohl
|
||||
# streamlit-authenticator als auch dein eigener bcrypt-Code kompatibel sind.
|
||||
# """
|
||||
# with closing(get_conn()) as conn, conn:
|
||||
# conn.execute(
|
||||
# """
|
||||
# CREATE TABLE IF NOT EXISTS users (
|
||||
# id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
# username TEXT UNIQUE NOT NULL,
|
||||
# email TEXT,
|
||||
# password_hash TEXT NOT NULL,
|
||||
# role TEXT NOT NULL DEFAULT 'user'
|
||||
# )
|
||||
# """
|
||||
# )
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Benutzer anlegen
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def create_user(username: str, password: str, role: str = "user", email: str | None = None) -> bool:
|
||||
def create_user(
|
||||
username: str,
|
||||
password: str,
|
||||
role: str = "user",
|
||||
email: str | None = None,
|
||||
firstname: str | None = None,
|
||||
lastname: str | None = None
|
||||
) -> bool:
|
||||
|
||||
"""
|
||||
Passwort wird als bcrypt-Hash (TEXT) gespeichert.
|
||||
"""
|
||||
@@ -43,8 +51,8 @@ def create_user(username: str, password: str, role: str = "user", email: str | N
|
||||
try:
|
||||
with closing(get_conn()) as conn, conn:
|
||||
conn.execute(
|
||||
"INSERT INTO users (username, email, password_hash, role) VALUES (?, ?, ?, ?)",
|
||||
(username, email, pw_hash, role),
|
||||
"INSERT INTO users (username, email, password_hash, role, firstname, lastname) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
(username, email, pw_hash, role, firstname, lastname),
|
||||
)
|
||||
return True
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user