-
-
Notifications
You must be signed in to change notification settings - Fork 365
feat: add email module for Alza #492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
beranka
wants to merge
1
commit into
kaifcodec:main
Choose a base branch
from
beranka:feat/add-alza-email-module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| import httpx | ||
|
|
||
| from user_scanner.core.result import Result, Status | ||
|
|
||
| ALZA_COUNTRY_CODES = ("cz", "sk", "de", "hu", "at") | ||
|
|
||
|
|
||
| async def _check_given_website(email: str, main_url: str) -> Result: | ||
| """ | ||
| Checks whether a given email is associated with an account or order on a specified Alza regional website. | ||
|
|
||
| The check has two steps: | ||
|
|
||
| 1. Retrieve cookies by fetching the main page. | ||
| 2. Use the CheckLoginAvailability API endpoint. Example response: | ||
| { | ||
| "LoginAvailabilityType": 1, | ||
| "DevErrorMessage": null, | ||
| "Message": null, | ||
| "ErrorNeoPurchaseFailed": false, | ||
| "ErrorLevel": 0, | ||
| "RedirectUrlOrderDetail": null, | ||
| "PaymentAction": null, | ||
| "CanShowFastCheckoutButton": false | ||
| } | ||
| The value of LoginAvailabilityType indicates whether the email is associated with a registered account (1), | ||
| was used for an order but is not associated with an account (2), or neither (0). | ||
|
|
||
| I do not know whether the other fields can have different values; they remained unchanged during testing. | ||
| """ | ||
|
|
||
| check_login_availability_url = ( | ||
| f"{main_url}/Services/EShopService.svc/CheckLoginAvailability" | ||
| ) | ||
|
|
||
| headers = { | ||
| "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0", | ||
| "Referer": main_url, | ||
| "Origin": main_url, | ||
| "Accept": "application/json", | ||
| } | ||
|
|
||
| async with httpx.AsyncClient(timeout=15.0, follow_redirects=True) as client: | ||
| # Fetch the main page to retrieve cookies | ||
| response = await client.get(main_url, headers=headers) | ||
|
|
||
| if response.status_code != 200: | ||
| return Result.error( | ||
| f"Failed to access the {main_url}, HTTP {response.status_code}" | ||
| ) | ||
|
|
||
| # Send post request to the API | ||
| payload = {"login": email} | ||
| response = await client.post( | ||
| check_login_availability_url, headers=headers, json=payload | ||
| ) | ||
|
|
||
| if response.status_code != 200: | ||
| return Result.error( | ||
| f"Failed to retrieve information from API, HTTP {response.status_code}" | ||
| ) | ||
|
|
||
| try: | ||
| data = response.json() | ||
| login_availability_type = data.get("LoginAvailabilityType") | ||
| except (ValueError, AttributeError): | ||
| return Result.error( | ||
| "Unexpected response structure, please report it via GitHub issues" | ||
| ) | ||
|
|
||
| match login_availability_type: | ||
| case 0: | ||
| # Not registered, no orders with this email | ||
| return Result.available(url=main_url) | ||
| case 1: | ||
| # Account with this email exists | ||
| return Result.taken(url=main_url, extra={"has_account": True}) | ||
| case 2: | ||
| # Orders with this email were created, but the email does not belong to any account | ||
| return Result.taken(url=main_url, extra={"has_account": False}) | ||
| case _: | ||
| return Result.error( | ||
| "Unexpected response structure, please report it via GitHub issues" | ||
| ) | ||
|
|
||
|
|
||
| async def _check(email: str) -> Result: | ||
| """ | ||
| Check whether an email is associated with an account or order across the following Alza regional websites: | ||
|
|
||
| - Czech Republic (www.alza.cz) | ||
| - Slovakia (www.alza.sk) | ||
| - Germany (www.alza.de) | ||
| - Hungary (www.alza.hu) | ||
| - Austria (www.alza.at) | ||
|
|
||
| Returns: | ||
| Result: | ||
| - with status=TAKEN if email was found on at least one website, also returns the list of websites where the given email | ||
| is associated with an account and a list of websites where the email was used for an order without a registered account, | ||
| - with status=AVAILABLE if the email was not found on any of the websites, | ||
| - with status=ERROR if an error occurred while checking any of the websites. | ||
| """ | ||
| domain_name_template = "https://www.alza.{cctld}" | ||
| order_only_countries = [] | ||
| account_countries = [] | ||
| for cctld in ALZA_COUNTRY_CODES: | ||
| url = domain_name_template.format(cctld=cctld) | ||
| result = await _check_given_website(email, url) | ||
| if result.status == Status.TAKEN: | ||
| if result.extra["has_account"]: | ||
| account_countries.append(cctld) | ||
| else: | ||
| order_only_countries.append(cctld) | ||
| elif result.status == Status.ERROR: | ||
| return result | ||
|
|
||
| if not account_countries and not order_only_countries: | ||
| return Result.available() | ||
|
|
||
| return Result.taken( | ||
| extra={ | ||
| "account_countries": ", ".join(account_countries), | ||
| "order_only_countries": ", ".join(order_only_countries), | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| async def validate_alza(email: str) -> Result: | ||
| """ | ||
| Checks whether an email is associated with an account or order across supported Alza regional websites. | ||
| Each regional website has its own database and users. | ||
| """ | ||
| return await _check(email) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case will definitely become confusing for users without reading source code - the module will report the email as "registered", but simultaneously says an account does not exist. I'm not even sure how to express these results better... I definitely wouldn't exclude this case, since even "has made an order" is useful information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@beranka
You don't need to pass the
extradictionary for case 1. ReturningResult.taken(...)already conveys thathas_account=True, so including it inextrais redundant.For case 2, you can use the
reasonparameter instead. All three result types (.taken(),.error(), and.available()) support it, so you can do something like:@kristoisberg
I think this better represents the OSINT value of the result. Even if the email isn't registered, it has still interacted with the site, so returning
Result.taken(...)is reasonable. Thereasonexplains why it's considered a hit, whileextraprovides the additional context that the email doesn't actually have an account.