|
@@ -71,12 +71,14 @@ class ShopifyMultipass:
|
|
|
return response.json()
|
|
|
|
|
|
@staticmethod
|
|
|
- def get_timezone_by_country(iso2):
|
|
|
+ def get_timezone_by_country(iso2: str):
|
|
|
+ iso2 = iso2.lower()
|
|
|
timezone_map = {
|
|
|
"us": "America/New_York", # 美国时区(例如:纽约)
|
|
|
"jp": "Asia/Tokyo", # 日本时区
|
|
|
"de": "Europe/Berlin", # 德国时区
|
|
|
"uk": "Europe/London", # 英国时区
|
|
|
+ "gb": "Europe/London", # 英国时区
|
|
|
"eu": "Europe/Paris", # 欧盟时区(默认设为法国巴黎)
|
|
|
}
|
|
|
# 获取当前时间并格式化时间戳
|
|
@@ -122,8 +124,7 @@ class ShopifyView(View):
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
|
- @staticmethod
|
|
|
- def shopify_login(request_dict, response):
|
|
|
+ def shopify_login(self, request_dict, response):
|
|
|
email = request_dict.get("email", None)
|
|
|
password = request_dict.get("password", None)
|
|
|
account_iso2 = request_dict.get("accountCountry", None)
|
|
@@ -145,88 +146,15 @@ class ShopifyView(View):
|
|
|
return response.json(111)
|
|
|
|
|
|
# 根据条件选择配置键
|
|
|
- if shopify_country:
|
|
|
- timestamp = ShopifyMultipass.get_timezone_by_country(shopify_country)
|
|
|
- secret_key = f"{shopify_country}_multipass_secret"
|
|
|
- multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
- if shopify_country == "eu":
|
|
|
- customer_data = {
|
|
|
- "email": email,
|
|
|
- "created_at": timestamp,
|
|
|
- }
|
|
|
- token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
- redirect_url = f"https://eu.zositech.com/account/login/multipass/{token}"
|
|
|
- elif shopify_country == "uk":
|
|
|
- customer_data = {
|
|
|
- "email": email,
|
|
|
- "created_at": timestamp,
|
|
|
- }
|
|
|
- token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
- redirect_url = f"https://www.zositech.co.uk/account/login/multipass/{token}"
|
|
|
- elif shopify_country == "us":
|
|
|
- customer_data = {
|
|
|
- "email": email,
|
|
|
- "created_at": timestamp,
|
|
|
- }
|
|
|
- token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
- redirect_url = f"https://www.zositech.com/account/login/multipass/{token}"
|
|
|
- else:
|
|
|
- customer_data = {
|
|
|
- "email": email,
|
|
|
- "created_at": timestamp,
|
|
|
- }
|
|
|
- token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
- redirect_url = f"https://www.zositech.{shopify_country}/account/login/multipass/{token}"
|
|
|
- return response.json(0, redirect_url)
|
|
|
- elif account_iso2 in ["de", "jp"]:
|
|
|
- timestamp = ShopifyMultipass.get_timezone_by_country(account_iso2)
|
|
|
- secret_key = f"{account_iso2}_multipass_secret"
|
|
|
- multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
- customer_data = {
|
|
|
- "email": email,
|
|
|
- "created_at": timestamp,
|
|
|
- }
|
|
|
- token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
- redirect_url = f"https://www.zositech.{account_iso2}/account/login/multipass/{token}"
|
|
|
- return response.json(0, redirect_url)
|
|
|
- elif account_iso2 == "uk":
|
|
|
- timestamp = ShopifyMultipass.get_timezone_by_country(account_iso2)
|
|
|
- secret_key = f"{account_iso2}_multipass_secret"
|
|
|
- multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
- customer_data = {
|
|
|
- "email": email,
|
|
|
- "created_at": timestamp,
|
|
|
- }
|
|
|
- token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
- redirect_url = f"https://www.zositech.co.uk/account/login/multipass/{token}"
|
|
|
- return response.json(0, redirect_url)
|
|
|
- elif CONFIG_INFO == CONFIG_EUR:
|
|
|
- timestamp = ShopifyMultipass.get_timezone_by_country("eu")
|
|
|
- secret_key = "eu_multipass_secret"
|
|
|
- multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
- customer_data = {
|
|
|
- "email": email,
|
|
|
- "created_at": timestamp,
|
|
|
- }
|
|
|
- token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
- redirect_url = f"https://eu.zositech.com/account/login/multipass/{token}"
|
|
|
- return response.json(0, redirect_url)
|
|
|
- elif CONFIG_INFO == CONFIG_US:
|
|
|
- timestamp = ShopifyMultipass.get_timezone_by_country("us")
|
|
|
- secret_key = "us_multipass_secret"
|
|
|
- multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
- customer_data = {
|
|
|
- "email": email,
|
|
|
- "created_at": timestamp,
|
|
|
- }
|
|
|
- token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
- redirect_url = f"https://www.zositech.com/account/login/multipass/{token}"
|
|
|
+ shopify_domain = shopify_country
|
|
|
+ iso2 = account_iso2
|
|
|
+ redirect_url = self.shopify_login_url(shopify_domain, iso2, email)
|
|
|
+
|
|
|
+ if redirect_url:
|
|
|
return response.json(0, redirect_url)
|
|
|
- else:
|
|
|
- return response.json(444)
|
|
|
+ return response.json(444)
|
|
|
|
|
|
- @staticmethod
|
|
|
- def shopify_register(request_dict, response):
|
|
|
+ def shopify_register(self, request_dict, response):
|
|
|
email = request_dict.get("email", None)
|
|
|
country_code = request_dict.get("countryCode", None)
|
|
|
password = request_dict.get("password", None)
|
|
@@ -283,7 +211,8 @@ class ShopifyView(View):
|
|
|
}
|
|
|
Device_User.objects.create(**user_data)
|
|
|
reds.del_data(key=email + '_identifyingCode')
|
|
|
- return response.json(0)
|
|
|
+ redirect_url = self.shopify_login_url("", country_code, email)
|
|
|
+ return response.json(0, redirect_url)
|
|
|
|
|
|
def search_account(self, request_dict, response):
|
|
|
email = request_dict.get("email")
|
|
@@ -505,3 +434,54 @@ class ShopifyView(View):
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def shopify_login_url(shopify_domain: str, iso2: str, email: str):
|
|
|
+ iso2 = iso2.lower()
|
|
|
+ shopify_domain = shopify_domain.lower()
|
|
|
+ shopify_country_to_use = shopify_domain or iso2
|
|
|
+ timestamp = ShopifyMultipass.get_timezone_by_country(shopify_country_to_use)
|
|
|
+ customer_data = {
|
|
|
+ "email": email,
|
|
|
+ "created_at": timestamp,
|
|
|
+ }
|
|
|
+ if shopify_domain:
|
|
|
+ secret_key = f"{shopify_domain}_multipass_secret"
|
|
|
+ multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
+ if shopify_domain == "eu":
|
|
|
+ token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
+ redirect_url = f"https://eu.zositech.com/account/login/multipass/{token}"
|
|
|
+ elif shopify_domain == "uk":
|
|
|
+ token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
+ redirect_url = f"https://www.zositech.co.uk/account/login/multipass/{token}"
|
|
|
+ elif shopify_domain == "us":
|
|
|
+ token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
+ redirect_url = f"https://www.zositech.com/account/login/multipass/{token}"
|
|
|
+ else:
|
|
|
+ token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
+ redirect_url = f"https://www.zositech.{shopify_domain}/account/login/multipass/{token}"
|
|
|
+ return redirect_url
|
|
|
+ elif iso2 in ["de", "jp"]:
|
|
|
+ secret_key = f"{iso2}_multipass_secret"
|
|
|
+ multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
+ token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
+ redirect_url = f"https://www.zositech.{iso2}/account/login/multipass/{token}"
|
|
|
+ elif iso2 == "gb":
|
|
|
+ secret_key = f"uk_multipass_secret"
|
|
|
+ multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
+ token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
+ redirect_url = f"https://www.zositech.co.uk/account/login/multipass/{token}"
|
|
|
+ elif CONFIG_INFO == CONFIG_EUR:
|
|
|
+ secret_key = "eu_multipass_secret"
|
|
|
+ multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
+ token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
+ redirect_url = f"https://eu.zositech.com/account/login/multipass/{token}"
|
|
|
+ elif CONFIG_INFO == CONFIG_US:
|
|
|
+ secret_key = "us_multipass_secret"
|
|
|
+ multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
+ token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
+ redirect_url = f"https://www.zositech.com/account/login/multipass/{token}"
|
|
|
+ else:
|
|
|
+ return ""
|
|
|
+
|
|
|
+ return redirect_url
|