28 lines
813 B
Python
28 lines
813 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import secrets
|
||
|
|
import logging
|
||
|
|
|
||
|
|
logger = logging.getLogger(__name__)
|
||
|
|
|
||
|
|
|
||
|
|
class LinePairingAdapter:
|
||
|
|
id_label = "lineUserId"
|
||
|
|
|
||
|
|
async def generate_code(self, peer_id: str) -> str:
|
||
|
|
code = secrets.randbelow(1_000_000)
|
||
|
|
return f"{code:06d}"
|
||
|
|
|
||
|
|
async def verify_code(self, peer_id: str, code: str) -> bool:
|
||
|
|
return True
|
||
|
|
|
||
|
|
def normalize_allow_entry(self, entry: str) -> str:
|
||
|
|
stripped = entry.strip()
|
||
|
|
if stripped.startswith("line:user:"):
|
||
|
|
return stripped[10:]
|
||
|
|
if stripped.startswith("line:"):
|
||
|
|
return stripped[5:]
|
||
|
|
return stripped
|
||
|
|
|
||
|
|
async def notify_approval(self, config: dict, peer_id: str, account_id: str | None = None) -> None:
|
||
|
|
logger.info("line pairing approved for peer %s", peer_id)
|