feat(auth): add user profile, phone login, and account deletion
This commit is contained in:
+23
-15
@@ -12,8 +12,12 @@ otherwise they are PNG without EXIF.
|
||||
|
||||
Configuration:
|
||||
GALO_BASE_URL base URL of the instance (default: http://localhost:8080)
|
||||
GALO_EMAIL owner email (required)
|
||||
GALO_EMAIL owner email (one of GALO_EMAIL/GALO_PHONE required)
|
||||
GALO_PHONE owner phone, E.164 (one of GALO_EMAIL/GALO_PHONE required)
|
||||
GALO_PASSWORD owner password (required)
|
||||
|
||||
Login uses the single-identifier contract: the email is preferred, otherwise the
|
||||
phone is used.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -301,9 +305,11 @@ class Stats:
|
||||
)
|
||||
|
||||
|
||||
def login(client, email, password):
|
||||
def login(client, identifier, password):
|
||||
resp = client.request(
|
||||
"POST", "/api/auth/login", json_body={"email": email, "password": password}
|
||||
"POST",
|
||||
"/api/auth/login",
|
||||
json_body={"identifier": identifier, "password": password},
|
||||
)
|
||||
client.token = resp["tokens"]["access_token"]
|
||||
|
||||
@@ -408,7 +414,7 @@ def build_plan(args):
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def run(args, base_url, email, password):
|
||||
def run(args, base_url, identifier, password):
|
||||
if args.dry_run:
|
||||
print(build_plan(args))
|
||||
return 0
|
||||
@@ -418,8 +424,8 @@ def run(args, base_url, email, password):
|
||||
client = Client(base_url, timeout=args.timeout)
|
||||
stats = Stats()
|
||||
|
||||
login(client, email, password)
|
||||
print("Вошел как {} @ {}".format(email, base_url))
|
||||
login(client, identifier, password)
|
||||
print("Вошел как {} @ {}".format(identifier, base_url))
|
||||
|
||||
if args.video and not HAVE_FFMPEG:
|
||||
print(
|
||||
@@ -516,26 +522,28 @@ def main(argv=None):
|
||||
args = parse_args(argv)
|
||||
base_url = os.environ.get("GALO_BASE_URL", DEFAULT_BASE_URL)
|
||||
email = os.environ.get("GALO_EMAIL")
|
||||
phone = os.environ.get("GALO_PHONE")
|
||||
password = os.environ.get("GALO_PASSWORD")
|
||||
identifier = email or phone
|
||||
|
||||
if not args.dry_run:
|
||||
missing = [
|
||||
name
|
||||
for name, value in (("GALO_EMAIL", email), ("GALO_PASSWORD", password))
|
||||
if not value
|
||||
]
|
||||
if missing:
|
||||
if not identifier:
|
||||
print(
|
||||
"Не заданы переменные окружения: {}".format(", ".join(missing)),
|
||||
"Не задан идентификатор входа: укажите GALO_EMAIL или GALO_PHONE",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return 2
|
||||
if not password:
|
||||
print("Не задана переменная окружения: GALO_PASSWORD", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
try:
|
||||
return run(args, base_url, email or "", password or "")
|
||||
return run(args, base_url, identifier or "", password or "")
|
||||
except ApiError as exc:
|
||||
if exc.status == 401:
|
||||
message = "Ошибка аутентификации: проверьте GALO_EMAIL и GALO_PASSWORD"
|
||||
message = (
|
||||
"Ошибка аутентификации: проверьте GALO_EMAIL/GALO_PHONE и GALO_PASSWORD"
|
||||
)
|
||||
else:
|
||||
message = "Ошибка API: {}".format(exc)
|
||||
print(message, file=sys.stderr)
|
||||
|
||||
Reference in New Issue
Block a user