|
@@ -86,13 +86,13 @@ class ShopifyView(View):
|
|
|
def validation(self, request, request_dict, operation):
|
|
|
language = request_dict.get('language', 'cn')
|
|
|
response = ResponseObject(language)
|
|
|
- if operation == 'shopifyLogin': # APP查詢定制客户信息
|
|
|
+ if operation == 'shopifyLogin':
|
|
|
return self.shopify_login(request_dict, response)
|
|
|
- elif operation == 'shopifyRegister': # APP注册定制客户信息
|
|
|
+ elif operation == 'shopifyRegister':
|
|
|
return self.shopify_register(request_dict, response)
|
|
|
- elif operation == 'searchCustomer':
|
|
|
+ elif operation == 'searchCustomer': # 查询APP注册账号情况
|
|
|
return self.search_customer(request_dict, response)
|
|
|
- elif operation == 'searchAccount':
|
|
|
+ elif operation == 'searchAccount': # 官网检测账号接口
|
|
|
return self.search_account(request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
@@ -101,6 +101,9 @@ class ShopifyView(View):
|
|
|
def shopify_login(request_dict, response):
|
|
|
email = request_dict.get("email", None)
|
|
|
password = request_dict.get("password", None)
|
|
|
+ account_region = request_dict.get("accountRegion", "")
|
|
|
+ account_iso2 = request_dict.get("accountIso2", "")
|
|
|
+ shopify_country = request_dict.get("shopifyCountry", "")
|
|
|
|
|
|
if not all([email, password]):
|
|
|
return response.json(444)
|
|
@@ -108,30 +111,51 @@ class ShopifyView(View):
|
|
|
user_qs = Device_User.objects.filter(Q(username=email) | Q(userEmail=email))
|
|
|
if not user_qs.exists():
|
|
|
return response.json(104)
|
|
|
- users = user_qs.values('role__rid', 'role__roleName', 'userID', 'NickName', 'username', 'userEmail',
|
|
|
- 'phone', 'password', 'userIconPath')[0]
|
|
|
|
|
|
- check_flag = check_password(password, users['password'])
|
|
|
- if not check_flag:
|
|
|
- return response.json(111)
|
|
|
+ users = user_qs.values(
|
|
|
+ 'role__rid', 'role__roleName', 'userID', 'NickName',
|
|
|
+ 'username', 'userEmail', 'phone', 'password', 'userIconPath'
|
|
|
+ )[0]
|
|
|
|
|
|
- # 获取当前时间
|
|
|
- now = datetime.now(pytz.timezone('America/New_York')) # 你可以根据需要更改时区
|
|
|
+ if not check_password(password, users['password']):
|
|
|
+ return response.json(111)
|
|
|
|
|
|
- # 格式化时间戳
|
|
|
+ # 获取当前时间并格式化时间戳
|
|
|
+ now = datetime.now(pytz.timezone('America/New_York'))
|
|
|
timestamp = now.strftime('%Y-%m-%dT%H:%M:%S%z')
|
|
|
- # 添加冒号到时区部分
|
|
|
timestamp = timestamp[:-2] + ':' + timestamp[-2:]
|
|
|
|
|
|
customer_data = {
|
|
|
"email": email,
|
|
|
"created_at": timestamp,
|
|
|
}
|
|
|
- multipass_secret = SHOPIFY_CONFIG["eu_multipass_secret"] # multipass密钥
|
|
|
- token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
|
|
|
- # 构造重定向URL
|
|
|
- redirect_url = f"https://eu.zositech.com/account/login/multipass/{token}"
|
|
|
+ # 定义默认配置键
|
|
|
+ secret_key = "eu_multipass_secret"
|
|
|
+ store_name_key = "eu_store_name"
|
|
|
+
|
|
|
+ # 根据条件选择配置键
|
|
|
+ if shopify_country:
|
|
|
+ secret_key = f"{shopify_country}_multipass_secret"
|
|
|
+ store_name_key = f"{shopify_country}_store_name"
|
|
|
+ elif account_region == "us" and account_iso2 == "jp":
|
|
|
+ secret_key = "jp_multipass_secret"
|
|
|
+ store_name_key = "jp_store_name"
|
|
|
+ elif account_region == "us":
|
|
|
+ secret_key = "us_multipass_secret"
|
|
|
+ store_name_key = "us_store_name"
|
|
|
+ elif account_region == "eu" and account_iso2 == "de":
|
|
|
+ secret_key = "de_multipass_secret"
|
|
|
+ store_name_key = "de_store_name"
|
|
|
+ elif account_region == "eu" and account_iso2 == "uk":
|
|
|
+ secret_key = "uk_multipass_secret"
|
|
|
+ store_name_key = "uk_store_name"
|
|
|
+
|
|
|
+ # 获取配置并生成重定向URL
|
|
|
+ multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
|
+ store_name = SHOPIFY_CONFIG[store_name_key]
|
|
|
+ token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
|
|
|
+ redirect_url = f"https://{store_name}.zositech.com/account/login/multipass/{token}"
|
|
|
|
|
|
return response.json(0, redirect_url)
|
|
|
|
|
@@ -141,26 +165,17 @@ class ShopifyView(View):
|
|
|
password = request_dict.get("password", None)
|
|
|
authcode = request_dict.get("authCode", None)
|
|
|
|
|
|
- if not all([email, password]):
|
|
|
+ if not all([email, password, authcode]):
|
|
|
return response.json(444)
|
|
|
|
|
|
- if authcode is None:
|
|
|
- # 查询是否在shopify有账号
|
|
|
- access_token = SHOPIFY_CONFIG["eu_token"]
|
|
|
- customer_data = ShopifyMultipass.search_customer_by_email("0ef557-2", access_token, email)
|
|
|
- if not customer_data['customers']:
|
|
|
- return response.json(10077)
|
|
|
-
|
|
|
- # 邮箱验证
|
|
|
- else:
|
|
|
- reds = RedisObject()
|
|
|
- identifyingCode = reds.get_data(key=email + '_identifyingCode')
|
|
|
- # 判断验证码是否过期
|
|
|
- if identifyingCode is False:
|
|
|
- return response.json(120)
|
|
|
- # 验证码是否正确
|
|
|
- if authcode != identifyingCode:
|
|
|
- return response.json(121)
|
|
|
+ reds = RedisObject()
|
|
|
+ identifyingCode = reds.get_data(key=email + '_identifyingCode')
|
|
|
+ # 判断验证码是否过期
|
|
|
+ if identifyingCode is False:
|
|
|
+ return response.json(120)
|
|
|
+ # 验证码是否正确
|
|
|
+ if authcode != identifyingCode:
|
|
|
+ return response.json(121)
|
|
|
|
|
|
# 注册
|
|
|
if Device_User.objects.filter(Q(username=email) | Q(userEmail=email)).exists():
|
|
@@ -185,7 +200,7 @@ class ShopifyView(View):
|
|
|
def search_account(self, request_dict, response):
|
|
|
email = request_dict.get("email")
|
|
|
if not email:
|
|
|
- return None
|
|
|
+ return response.json(444)
|
|
|
|
|
|
store_configs = [
|
|
|
("us", SHOPIFY_CONFIG["us_store_name"], SHOPIFY_CONFIG["us_token"]),
|
|
@@ -198,31 +213,59 @@ class ShopifyView(View):
|
|
|
def search_customer(store_name, token):
|
|
|
return ShopifyMultipass.search_customer_by_email(store_name, token, email)
|
|
|
|
|
|
- shopify_results = {}
|
|
|
-
|
|
|
- with concurrent.futures.ThreadPoolExecutor() as executor:
|
|
|
- future_to_country = {executor.submit(search_customer, store_name, token): country for
|
|
|
- country, store_name, token in store_configs}
|
|
|
- for future in concurrent.futures.as_completed(future_to_country):
|
|
|
- country = future_to_country[future]
|
|
|
- shopify_results[country] = future.result()
|
|
|
-
|
|
|
- shopify_country = next((country for country, result in shopify_results.items() if result["customers"]), "")
|
|
|
-
|
|
|
- account_country = self.call_search_customer(email)
|
|
|
- servers_country = "us" if account_country["us"] else "eu" if account_country["eu"] else ""
|
|
|
-
|
|
|
- if servers_country and shopify_country:
|
|
|
- status = 4
|
|
|
- elif servers_country:
|
|
|
- status = 3
|
|
|
- elif shopify_country:
|
|
|
- status = 2
|
|
|
- else:
|
|
|
- status = 1
|
|
|
+ try:
|
|
|
+ shopify_results = {}
|
|
|
+
|
|
|
+ with concurrent.futures.ThreadPoolExecutor() as executor:
|
|
|
+ future_to_country = {executor.submit(search_customer, store_name, token): country for
|
|
|
+ country, store_name, token in store_configs}
|
|
|
+ for future in concurrent.futures.as_completed(future_to_country):
|
|
|
+ country = future_to_country[future]
|
|
|
+ shopify_results[country] = future.result()
|
|
|
+
|
|
|
+ shopify_country = next((country for country, result in shopify_results.items() if result["customers"]), "")
|
|
|
+
|
|
|
+ account_country = self.call_search_customer(email)
|
|
|
+ servers_continent = "us" if account_country["us"] else "eu" if account_country["eu"] else ""
|
|
|
+
|
|
|
+ if servers_continent:
|
|
|
+ account_region_list = []
|
|
|
+ if account_country.get("us"):
|
|
|
+ account_region_list.append({
|
|
|
+ "region": "us",
|
|
|
+ "url": "https://www.dvema.com/shopify/shopifyLogin",
|
|
|
+ "accountCountry": account_country["us"],
|
|
|
+ "shopifyCountry": shopify_country
|
|
|
+ })
|
|
|
+ if account_country.get("eu"):
|
|
|
+ account_region_list.append({
|
|
|
+ "region": "eu",
|
|
|
+ "url": "https://api.zositeche.com/shopify/shopifyLogin",
|
|
|
+ "accountCountry": account_country["eu"],
|
|
|
+ "shopifyCountry": shopify_country
|
|
|
+ })
|
|
|
+
|
|
|
+ return response.json(0, {"accountStatus": 3, "accountRegionList": account_region_list})
|
|
|
+ elif shopify_country:
|
|
|
+ if shopify_country == "eu":
|
|
|
+ url = "https://eu.zositech.com/account/login"
|
|
|
+ elif shopify_country == "jp":
|
|
|
+ url = "https://www.zosi.jp/account/login"
|
|
|
+ elif shopify_country == "de":
|
|
|
+ url = "https://www.zositech.de/account/login"
|
|
|
+ elif shopify_country == "uk":
|
|
|
+ url = "https://www.zositech.co.uk/account/login"
|
|
|
+ else:
|
|
|
+ url = "https://www.zositech.com/account/login"
|
|
|
+ return response.json(0, {"accountStatus": 2, "url": url})
|
|
|
+ else:
|
|
|
+ url = "注册链接"
|
|
|
+ return response.json(0, {"accountStatus": 1, "url": url})
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
- account_status = {"status": status, "shopifyCountry": shopify_country, "ServersCountry": servers_country}
|
|
|
- return response.json(0, account_status)
|
|
|
|
|
|
@staticmethod
|
|
|
def call_search_customer(email):
|