|
| 1 | +import httpx |
| 2 | +from user_scanner.core.result import Result |
| 3 | + |
| 4 | + |
| 5 | +async def _check(email: str) -> Result: |
| 6 | + headers = { |
| 7 | + 'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", |
| 8 | + 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', |
| 9 | + 'Accept': '*/*', |
| 10 | + 'Origin': 'https://accounts.zoho.com', |
| 11 | + 'Sec-Fetch-Site': 'same-origin', |
| 12 | + 'Sec-Fetch-Mode': 'cors', |
| 13 | + 'Sec-Fetch-Dest': 'empty', |
| 14 | + 'Accept-Language': 'en-US,en;q=0.9', |
| 15 | + } |
| 16 | + |
| 17 | + try: |
| 18 | + async with httpx.AsyncClient(timeout=5.0, follow_redirects=True) as client: |
| 19 | + await client.get("https://accounts.zoho.com/register", headers=headers) |
| 20 | + |
| 21 | + csrf_cookie = client.cookies.get("iamcsr") |
| 22 | + if not csrf_cookie: |
| 23 | + return Result.error("CSRF cookie not found") |
| 24 | + |
| 25 | + headers['X-ZCSRF-TOKEN'] = f'iamcsrcoo={csrf_cookie}' |
| 26 | + |
| 27 | + payload = { |
| 28 | + 'mode': 'primary', |
| 29 | + 'servicename': 'ZohoCRM', |
| 30 | + 'serviceurl': 'https://crm.zoho.com/crm/ShowHomePage.do', |
| 31 | + 'service_language': 'en' |
| 32 | + } |
| 33 | + |
| 34 | + response = await client.post( |
| 35 | + f'https://accounts.zoho.com/signin/v2/lookup/{email}', |
| 36 | + headers=headers, |
| 37 | + data=payload |
| 38 | + ) |
| 39 | + |
| 40 | + if response.status_code == 200: |
| 41 | + data = response.json() |
| 42 | + message = data.get("message") |
| 43 | + status = data.get("status_code") |
| 44 | + |
| 45 | + if message == "User exists" and status == 201: |
| 46 | + return Result.taken() |
| 47 | + |
| 48 | + elif status == 400: |
| 49 | + return Result.available() |
| 50 | + |
| 51 | + else: |
| 52 | + return Result.error(data) |
| 53 | + |
| 54 | + return Result.error(f"HTTP {response.status_code}") |
| 55 | + |
| 56 | + except httpx.TimeoutException: |
| 57 | + return Result.error("Connection timed out") |
| 58 | + except Exception as e: |
| 59 | + return Result.error(str(e)) |
| 60 | + |
| 61 | + |
| 62 | +async def validate_zoho(email: str) -> Result: |
| 63 | + return await _check(email) |
0 commit comments