|
@@ -1,3 +1,4 @@
|
|
|
|
+import re
|
|
from datetime import datetime
|
|
from datetime import datetime
|
|
import concurrent.futures
|
|
import concurrent.futures
|
|
import pytz
|
|
import pytz
|
|
@@ -17,7 +18,7 @@ import hmac
|
|
import hashlib
|
|
import hashlib
|
|
import os
|
|
import os
|
|
import json
|
|
import json
|
|
-from Ansjer.config import SHOPIFY_CONFIG
|
|
|
|
|
|
+from Ansjer.config import SHOPIFY_CONFIG, CONFIG_INFO, CONFIG_EUR, CONFIG_US
|
|
|
|
|
|
from Service.CommonService import CommonService
|
|
from Service.CommonService import CommonService
|
|
|
|
|
|
@@ -110,11 +111,10 @@ class ShopifyView(View):
|
|
def shopify_login(request_dict, response):
|
|
def shopify_login(request_dict, response):
|
|
email = request_dict.get("email", None)
|
|
email = request_dict.get("email", None)
|
|
password = request_dict.get("password", None)
|
|
password = request_dict.get("password", None)
|
|
- account_region = request_dict.get("accountRegion", "")
|
|
|
|
- account_iso2 = request_dict.get("accountIso2", "")
|
|
|
|
|
|
+ account_iso2 = request_dict.get("accountCountry", None)
|
|
shopify_country = request_dict.get("shopifyCountry", "")
|
|
shopify_country = request_dict.get("shopifyCountry", "")
|
|
|
|
|
|
- if not all([email, password]):
|
|
|
|
|
|
+ if not all([email, password, account_iso2]):
|
|
return response.json(444)
|
|
return response.json(444)
|
|
|
|
|
|
user_qs = Device_User.objects.filter(Q(username=email) | Q(userEmail=email))
|
|
user_qs = Device_User.objects.filter(Q(username=email) | Q(userEmail=email))
|
|
@@ -139,26 +139,30 @@ class ShopifyView(View):
|
|
"created_at": timestamp,
|
|
"created_at": timestamp,
|
|
}
|
|
}
|
|
|
|
|
|
- # 定义默认配置键
|
|
|
|
- secret_key = "eu_multipass_secret"
|
|
|
|
- store_name_key = "eu_store_name"
|
|
|
|
-
|
|
|
|
# 根据条件选择配置键
|
|
# 根据条件选择配置键
|
|
if shopify_country:
|
|
if shopify_country:
|
|
secret_key = f"{shopify_country}_multipass_secret"
|
|
secret_key = f"{shopify_country}_multipass_secret"
|
|
store_name_key = f"{shopify_country}_store_name"
|
|
store_name_key = f"{shopify_country}_store_name"
|
|
- elif account_region == "us" and account_iso2 == "jp":
|
|
|
|
|
|
+ elif account_iso2 == "jp":
|
|
secret_key = "jp_multipass_secret"
|
|
secret_key = "jp_multipass_secret"
|
|
store_name_key = "jp_store_name"
|
|
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":
|
|
|
|
|
|
+ elif account_iso2 == "de":
|
|
secret_key = "de_multipass_secret"
|
|
secret_key = "de_multipass_secret"
|
|
store_name_key = "de_store_name"
|
|
store_name_key = "de_store_name"
|
|
- elif account_region == "eu" and account_iso2 == "uk":
|
|
|
|
|
|
+ elif account_iso2 == "uk":
|
|
secret_key = "uk_multipass_secret"
|
|
secret_key = "uk_multipass_secret"
|
|
store_name_key = "uk_store_name"
|
|
store_name_key = "uk_store_name"
|
|
|
|
+ elif CONFIG_INFO == CONFIG_EUR:
|
|
|
|
+ secret_key = "eu_multipass_secret"
|
|
|
|
+ store_name_key = "eu_store_name"
|
|
|
|
+ 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}"
|
|
|
|
+ return response.json(0, redirect_url)
|
|
|
|
+ else:
|
|
|
|
+ return response.json(444)
|
|
|
|
|
|
# 获取配置并生成重定向URL
|
|
# 获取配置并生成重定向URL
|
|
multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
@@ -177,8 +181,19 @@ class ShopifyView(View):
|
|
if not all([email, password, authcode]):
|
|
if not all([email, password, authcode]):
|
|
return response.json(444)
|
|
return response.json(444)
|
|
data_valid = DataValid()
|
|
data_valid = DataValid()
|
|
|
|
+ if data_valid.email_validate(email) is not True:
|
|
|
|
+ return response.json(105)
|
|
re_flag = data_valid.password_validate(password)
|
|
re_flag = data_valid.password_validate(password)
|
|
- if re_flag is not True:
|
|
|
|
|
|
+
|
|
|
|
+ has_upper = bool(re.search(r"[A-Z]", password)) # 大写字母
|
|
|
|
+ has_lower = bool(re.search(r"[a-z]", password)) # 小写字母
|
|
|
|
+ has_digit = bool(re.search(r"[0-9]", password)) # 数字
|
|
|
|
+ has_special = bool(re.search(r"[!@#$%^&*()_+\-=\[\]{}|;:'\",.<>?/]", password)) # 特殊字符
|
|
|
|
+
|
|
|
|
+ # 至少包含任意两类字符
|
|
|
|
+ categories = sum([has_upper, has_lower, has_digit, has_special])
|
|
|
|
+
|
|
|
|
+ if re_flag is not True and categories > 2:
|
|
return response.json(109)
|
|
return response.json(109)
|
|
|
|
|
|
reds = RedisObject()
|
|
reds = RedisObject()
|
|
@@ -243,16 +258,14 @@ class ShopifyView(View):
|
|
account_region_list = []
|
|
account_region_list = []
|
|
if account_country.get("us"):
|
|
if account_country.get("us"):
|
|
account_region_list.append({
|
|
account_region_list.append({
|
|
- "region": "us",
|
|
|
|
"url": "https://www.dvema.com/shopify/shopifyLogin",
|
|
"url": "https://www.dvema.com/shopify/shopifyLogin",
|
|
- "accountCountry": account_country["us"],
|
|
|
|
|
|
+ "accountCountry": account_country["us"].lower(),
|
|
"shopifyCountry": shopify_country
|
|
"shopifyCountry": shopify_country
|
|
})
|
|
})
|
|
if account_country.get("eu"):
|
|
if account_country.get("eu"):
|
|
account_region_list.append({
|
|
account_region_list.append({
|
|
- "region": "eu",
|
|
|
|
"url": "https://api.zositeche.com/shopify/shopifyLogin",
|
|
"url": "https://api.zositeche.com/shopify/shopifyLogin",
|
|
- "accountCountry": account_country["eu"],
|
|
|
|
|
|
+ "accountCountry": account_country["eu"].lower(),
|
|
"shopifyCountry": shopify_country
|
|
"shopifyCountry": shopify_country
|
|
})
|
|
})
|
|
return response.json(0, {"accountStatus": 3, "accountRegionList": account_region_list})
|
|
return response.json(0, {"accountStatus": 3, "accountRegionList": account_region_list})
|
|
@@ -290,8 +303,10 @@ class ShopifyView(View):
|
|
try:
|
|
try:
|
|
response = requests.get(url=url, params=params)
|
|
response = requests.get(url=url, params=params)
|
|
response.raise_for_status() # Raise an error for bad responses
|
|
response.raise_for_status() # Raise an error for bad responses
|
|
- customer_country = response.json().get("result", None)
|
|
|
|
- return region, customer_country if not all(customer_country) else None
|
|
|
|
|
|
+ customer_country = response.json()["data"]
|
|
|
|
+ if customer_country == "":
|
|
|
|
+ return region, None
|
|
|
|
+ return region, customer_country
|
|
except requests.RequestException:
|
|
except requests.RequestException:
|
|
return region, None
|
|
return region, None
|
|
|
|
|
|
@@ -378,15 +393,21 @@ class ShopifyView(View):
|
|
"""
|
|
"""
|
|
email = request_dict.get("email", None)
|
|
email = request_dict.get("email", None)
|
|
authcode = request_dict.get("authCode", None)
|
|
authcode = request_dict.get("authCode", None)
|
|
- code_type = request_dict.get("code_type", None)
|
|
|
|
|
|
+ code_type = request_dict.get("codeType", None)
|
|
if not all([email, authcode, code_type]):
|
|
if not all([email, authcode, code_type]):
|
|
return response.json(444)
|
|
return response.json(444)
|
|
try:
|
|
try:
|
|
code_type = int(code_type)
|
|
code_type = int(code_type)
|
|
if code_type == 1:
|
|
if code_type == 1:
|
|
- reds_key = "_forgetPwdResetCode"
|
|
|
|
- elif code_type == 2:
|
|
|
|
reds_key = "_identifyingCode"
|
|
reds_key = "_identifyingCode"
|
|
|
|
+ user_qs = Device_User.objects.filter(Q(username=email) | Q(userEmail=email))
|
|
|
|
+ if user_qs.exists():
|
|
|
|
+ return response.json(174)
|
|
|
|
+ elif code_type == 2:
|
|
|
|
+ reds_key = "_forgetPwdResetCode"
|
|
|
|
+ user_qs = Device_User.objects.filter(Q(username=email) | Q(userEmail=email))
|
|
|
|
+ if not user_qs.exists():
|
|
|
|
+ return response.json(173)
|
|
else:
|
|
else:
|
|
return response.json(444)
|
|
return response.json(444)
|
|
reds = RedisObject()
|
|
reds = RedisObject()
|
|
@@ -396,9 +417,6 @@ class ShopifyView(View):
|
|
# 验证码是否正确
|
|
# 验证码是否正确
|
|
if authcode != identifyingCode:
|
|
if authcode != identifyingCode:
|
|
return response.json(121)
|
|
return response.json(121)
|
|
- user_qs = Device_User.objects.filter(Q(username=email) | Q(userEmail=email))
|
|
|
|
- if not user_qs.exists():
|
|
|
|
- return response.json(174)
|
|
|
|
return response.json(0)
|
|
return response.json(0)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|