feat: update authentication and profile management features
- Enhanced login response to include additional user information such as email, tier, and role. - Updated profile update logic to restrict access based on user roles and ensure only authorized users can modify profiles. - Replaced ProfilePage with AccountSettingsPage in routing and updated related components to reflect this change. - Added new API functions for updating profiles and changing passwords to improve user account management.
This commit is contained in:
1 parent
d9d2d9e506
commit
fae673670a
10 files changed
+283
-73
No files matched your search
@@ -82,7 +82,12 @@ def get_profile(pid: str, session=Depends(require_auth)):
|
||||
|
||||
@router.put("/profiles/{pid}")
|
||||
def update_profile(pid: str, p: ProfileUpdate, session=Depends(require_auth)):
|
||||
"""Update profile by ID."""
|
||||
"""Update profile — nur eigenes Profil oder Admin."""
|
||||
sess_pid = session.get('profile_id')
|
||||
role = (session.get('role') or '').lower()
|
||||
if str(sess_pid) != str(pid) and role not in ('admin', 'superadmin'):
|
||||
raise HTTPException(403, 'Keine Berechtigung für dieses Profil')
|
||||
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute("SELECT * FROM profiles WHERE id=%s", (pid,))
|
||||
@@ -134,7 +139,7 @@ def update_profile(pid: str, p: ProfileUpdate, session=Depends(require_auth)):
|
||||
if not data:
|
||||
return get_profile(pid, session)
|
||||
|
||||
data["updated"] = datetime.now().isoformat()
|
||||
data["updated_at"] = datetime.now()
|
||||
cols = ", ".join(f"{k}=%s" for k in data)
|
||||
vals = list(data.values()) + [pid]
|
||||
cur.execute(f"UPDATE profiles SET {cols} WHERE id=%s", vals)
|
||||
|
||||
Reference in new issue
Block a user