Add self-service profile email management
Magent CI/CD / verify (push) Canceled after 10m22s
Magent CI/CD / deploy-prod (push) Canceled after 0s
Magent CI/CD / deploy-beta (push) Canceled after 0s

This commit is contained in:
2026-09-01 22:26:53 +12:00
parent c6d449dc17
commit ded794a819
4 changed files with 208 additions and 0 deletions
+44
View File
@@ -17,6 +17,7 @@ from ..db import (
set_last_login,
get_user_by_username,
get_users_by_username_ci,
get_all_users,
set_user_password,
set_user_jellyseerr_id,
set_user_email,
@@ -108,6 +109,18 @@ def _optional_recipient_email(value: object) -> str | None:
return _require_recipient_email(value)
def _optional_account_email(value: object) -> str | None:
if value is None or not str(value).strip():
return None
normalized = normalize_delivery_email(value)
if normalized:
return normalized
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Enter a valid email address.",
)
def _auth_client_ip(request: Request) -> str:
direct_host = request.client.host if request.client else None
if request_trusts_forwarded_headers(direct_host):
@@ -1165,6 +1178,37 @@ async def profile(current_user: dict = Depends(get_current_user)) -> dict:
}
@router.put("/profile/email")
async def update_profile_email(payload: dict, current_user: dict = Depends(get_current_user)) -> dict:
if not isinstance(payload, dict):
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid payload")
username = str(current_user.get("username") or "").strip()
if not username:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid user")
email = _optional_account_email(payload.get("email"))
if email:
duplicate = next(
(
candidate
for candidate in get_all_users()
if str(candidate.get("username") or "").casefold() != username.casefold()
and str(candidate.get("email") or "").strip().casefold() == email.casefold()
),
None,
)
if duplicate:
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail="That email address is already assigned to another account.",
)
if not set_user_email(username, email):
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="User not found")
logger.info("User updated profile contact email: username=%s email_set=%s", username, bool(email))
return {"status": "ok", "email": email}
@router.get("/profile/invites")
async def profile_invites(current_user: dict = Depends(get_current_user)) -> dict:
username = str(current_user.get("username") or "").strip()