portal: derive mail username from Keycloak email
This commit is contained in:
parent
a1fbfe604e
commit
a5ab2ad896
@ -19,26 +19,30 @@ def register(app) -> None:
|
|||||||
return resp
|
return resp
|
||||||
|
|
||||||
username = g.keycloak_username
|
username = g.keycloak_username
|
||||||
mailu_username = ""
|
keycloak_email = g.keycloak_email or ""
|
||||||
if g.keycloak_email and g.keycloak_email.lower().endswith(f"@{settings.MAILU_DOMAIN.lower()}"):
|
|
||||||
mailu_username = g.keycloak_email
|
|
||||||
elif username:
|
|
||||||
mailu_username = f"{username}@{settings.MAILU_DOMAIN}"
|
|
||||||
|
|
||||||
mailu_app_password = ""
|
mailu_app_password = ""
|
||||||
|
|
||||||
if admin_client().ready() and username:
|
if admin_client().ready() and username:
|
||||||
try:
|
try:
|
||||||
user = admin_client().find_user(username)
|
user = admin_client().find_user(username) or {}
|
||||||
user_id = (user or {}).get("id") or ""
|
user_id = user.get("id") or ""
|
||||||
if user_id:
|
if user_id:
|
||||||
full = admin_client().get_user(str(user_id))
|
full = admin_client().get_user(str(user_id))
|
||||||
|
if not keycloak_email:
|
||||||
|
keycloak_email = str(full.get("email") or "")
|
||||||
attrs = full.get("attributes") or {}
|
attrs = full.get("attributes") or {}
|
||||||
if isinstance(attrs, dict):
|
if isinstance(attrs, dict):
|
||||||
values = attrs.get("mailu_app_password") or []
|
values = attrs.get("mailu_app_password") or []
|
||||||
if isinstance(values, list) and values:
|
if isinstance(values, list) and values:
|
||||||
mailu_app_password = str(values[0])
|
mailu_app_password = str(values[0])
|
||||||
except Exception:
|
except Exception:
|
||||||
mailu_app_password = ""
|
pass
|
||||||
|
|
||||||
|
mailu_username = ""
|
||||||
|
if keycloak_email and keycloak_email.lower().endswith(f"@{settings.MAILU_DOMAIN.lower()}"):
|
||||||
|
mailu_username = keycloak_email
|
||||||
|
elif username:
|
||||||
|
mailu_username = f"{username}@{settings.MAILU_DOMAIN}"
|
||||||
|
|
||||||
mailu_status = "ready"
|
mailu_status = "ready"
|
||||||
jellyfin_status = "ready"
|
jellyfin_status = "ready"
|
||||||
@ -49,7 +53,7 @@ def register(app) -> None:
|
|||||||
|
|
||||||
return jsonify(
|
return jsonify(
|
||||||
{
|
{
|
||||||
"user": {"username": username, "email": g.keycloak_email, "groups": g.keycloak_groups},
|
"user": {"username": username, "email": keycloak_email, "groups": g.keycloak_groups},
|
||||||
"mailu": {"status": mailu_status, "username": mailu_username, "app_password": mailu_app_password},
|
"mailu": {"status": mailu_status, "username": mailu_username, "app_password": mailu_app_password},
|
||||||
"jellyfin": {"status": jellyfin_status, "username": username},
|
"jellyfin": {"status": jellyfin_status, "username": username},
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user