firefly: check password by username fallback
This commit is contained in:
parent
e4533f7c51
commit
f50ec538db
@ -190,10 +190,11 @@ _FIREFLY_PASSWORD_CHECK_SCRIPT = textwrap.dedent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
$email = trim((string) getenv('FIREFLY_USER_EMAIL'));
|
$email = trim((string) getenv('FIREFLY_USER_EMAIL'));
|
||||||
|
$username = trim((string) getenv('FIREFLY_USER_USERNAME'));
|
||||||
$password = (string) getenv('FIREFLY_USER_PASSWORD');
|
$password = (string) getenv('FIREFLY_USER_PASSWORD');
|
||||||
|
|
||||||
if ($email === '' || $password === '') {
|
if (($email === '' && $username === '') || $password === '') {
|
||||||
error_line('missing FIREFLY_USER_EMAIL or FIREFLY_USER_PASSWORD');
|
error_line('missing FIREFLY_USER_EMAIL or FIREFLY_USER_USERNAME or FIREFLY_USER_PASSWORD');
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,7 +224,17 @@ _FIREFLY_PASSWORD_CHECK_SCRIPT = textwrap.dedent(
|
|||||||
error_line('failed to enforce single_user_mode: ' . $exc->getMessage());
|
error_line('failed to enforce single_user_mode: ' . $exc->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
$existing_user = User::where('email', $email)->first();
|
if ($email !== '') {
|
||||||
|
$query = User::where('email', $email);
|
||||||
|
} else {
|
||||||
|
$query = User::where('username', $username);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($email !== '' && $username !== '') {
|
||||||
|
$query = $query->orWhere('username', $username);
|
||||||
|
}
|
||||||
|
|
||||||
|
$existing_user = $query->first();
|
||||||
if (!$existing_user) {
|
if (!$existing_user) {
|
||||||
error_line('firefly user missing');
|
error_line('firefly user missing');
|
||||||
exit(3);
|
exit(3);
|
||||||
@ -537,10 +548,12 @@ class FireflyService:
|
|||||||
output = (result.stdout or result.stderr).strip()
|
output = (result.stdout or result.stderr).strip()
|
||||||
return {"status": "ok", "detail": output}
|
return {"status": "ok", "detail": output}
|
||||||
|
|
||||||
def check_password(self, email: str, password: str) -> dict[str, Any]:
|
def check_password(self, email: str, password: str, username: str = "") -> dict[str, Any]:
|
||||||
email = (email or "").strip()
|
email = (email or "").strip()
|
||||||
|
username = (username or "").strip()
|
||||||
if not email:
|
if not email:
|
||||||
raise RuntimeError("missing email")
|
if not username:
|
||||||
|
raise RuntimeError("missing email")
|
||||||
if not password:
|
if not password:
|
||||||
raise RuntimeError("missing password")
|
raise RuntimeError("missing password")
|
||||||
if not settings.firefly_namespace:
|
if not settings.firefly_namespace:
|
||||||
@ -548,6 +561,7 @@ class FireflyService:
|
|||||||
|
|
||||||
env = {
|
env = {
|
||||||
"FIREFLY_USER_EMAIL": email,
|
"FIREFLY_USER_EMAIL": email,
|
||||||
|
"FIREFLY_USER_USERNAME": username,
|
||||||
"FIREFLY_USER_PASSWORD": password,
|
"FIREFLY_USER_PASSWORD": password,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -573,7 +587,7 @@ class FireflyService:
|
|||||||
def _rotation_outcome(self, prepared: FireflySyncInput) -> UserSyncOutcome:
|
def _rotation_outcome(self, prepared: FireflySyncInput) -> UserSyncOutcome:
|
||||||
if prepared.rotated_at:
|
if prepared.rotated_at:
|
||||||
return UserSyncOutcome("skipped")
|
return UserSyncOutcome("skipped")
|
||||||
check = self.check_password(prepared.mailu_email, prepared.password)
|
check = self.check_password(prepared.mailu_email, prepared.password, prepared.username)
|
||||||
status = check.get("status") if isinstance(check, dict) else "error"
|
status = check.get("status") if isinstance(check, dict) else "error"
|
||||||
if status == "match":
|
if status == "match":
|
||||||
return UserSyncOutcome("skipped")
|
return UserSyncOutcome("skipped")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user