|
@@ -1,15 +1,16 @@
|
|
|
+import re
|
|
|
from datetime import datetime
|
|
|
import concurrent.futures
|
|
|
import pytz
|
|
|
import requests
|
|
|
-from django.db.models import Q
|
|
|
+from django.db.models import Q, F
|
|
|
from django.views import View
|
|
|
from Crypto.Cipher import AES
|
|
|
from Crypto.Util.Padding import pad
|
|
|
from django.contrib.auth.hashers import check_password, make_password
|
|
|
import concurrent.futures
|
|
|
from Controller.CheckUserData import DataValid
|
|
|
-from Model.models import Device_User, CountryModel
|
|
|
+from Model.models import Device_User, CountryModel, LanguageModel, CountryLanguageModel
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
import base64
|
|
@@ -17,7 +18,7 @@ import hmac
|
|
|
import hashlib
|
|
|
import os
|
|
|
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
|
|
|
|
|
@@ -90,10 +91,19 @@ class ShopifyView(View):
|
|
|
return self.shopify_login(request_dict, response)
|
|
|
elif operation == 'shopifyRegister':
|
|
|
return self.shopify_register(request_dict, response)
|
|
|
- elif operation == 'searchCustomer': # 查询APP注册账号情况
|
|
|
+ # 查询FAPP注册账号情况
|
|
|
+ elif operation == 'searchCustomer':
|
|
|
return self.search_customer(request_dict, response)
|
|
|
- elif operation == 'searchAccount': # 官网检测账号接口
|
|
|
+ # 官网检测账号接口
|
|
|
+ elif operation == 'searchAccount':
|
|
|
return self.search_account(request_dict, response)
|
|
|
+ elif operation == 'getCountryDomainList':
|
|
|
+ return self.get_country_domain_list(request_dict, response)
|
|
|
+ # 忘记密码
|
|
|
+ elif operation == 'shopifyChangePassword':
|
|
|
+ return self.shopify_change_password(request_dict, response)
|
|
|
+ elif operation == 'verifyAuthcode':
|
|
|
+ return self.verify_authcode(request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
@@ -101,11 +111,10 @@ 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", "")
|
|
|
+ account_iso2 = request_dict.get("accountCountry", None)
|
|
|
shopify_country = request_dict.get("shopifyCountry", "")
|
|
|
|
|
|
- if not all([email, password]):
|
|
|
+ if not all([email, password, account_iso2]):
|
|
|
return response.json(444)
|
|
|
|
|
|
user_qs = Device_User.objects.filter(Q(username=email) | Q(userEmail=email))
|
|
@@ -130,26 +139,30 @@ class ShopifyView(View):
|
|
|
"created_at": timestamp,
|
|
|
}
|
|
|
|
|
|
- # 定义默认配置键
|
|
|
- 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":
|
|
|
+ elif 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":
|
|
|
+ elif account_iso2 == "de":
|
|
|
secret_key = "de_multipass_secret"
|
|
|
store_name_key = "de_store_name"
|
|
|
- elif account_region == "eu" and account_iso2 == "uk":
|
|
|
+ elif account_iso2 == "uk":
|
|
|
secret_key = "uk_multipass_secret"
|
|
|
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
|
|
|
multipass_secret = SHOPIFY_CONFIG[secret_key]
|
|
@@ -167,6 +180,21 @@ class ShopifyView(View):
|
|
|
|
|
|
if not all([email, password, authcode]):
|
|
|
return response.json(444)
|
|
|
+ data_valid = DataValid()
|
|
|
+ if data_valid.email_validate(email) is not True:
|
|
|
+ return response.json(105)
|
|
|
+ re_flag = data_valid.password_validate(password)
|
|
|
+
|
|
|
+ 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)
|
|
|
|
|
|
reds = RedisObject()
|
|
|
identifyingCode = reds.get_data(key=email + '_identifyingCode')
|
|
@@ -176,11 +204,9 @@ class ShopifyView(View):
|
|
|
# 验证码是否正确
|
|
|
if authcode != identifyingCode:
|
|
|
return response.json(121)
|
|
|
-
|
|
|
# 注册
|
|
|
if Device_User.objects.filter(Q(username=email) | Q(userEmail=email)).exists():
|
|
|
return response.json(103)
|
|
|
-
|
|
|
# 创建用户
|
|
|
password = make_password(password)
|
|
|
new_userID = CommonService.getUserID(μs=False, setOTAID=True)
|
|
@@ -194,7 +220,7 @@ class ShopifyView(View):
|
|
|
"user_isValid": True,
|
|
|
}
|
|
|
Device_User.objects.create(**user_data)
|
|
|
-
|
|
|
+ reds.del_data(key=email + '_identifyingCode')
|
|
|
return response.json(0)
|
|
|
|
|
|
def search_account(self, request_dict, response):
|
|
@@ -232,19 +258,16 @@ class ShopifyView(View):
|
|
|
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"],
|
|
|
+ "accountCountry": account_country["us"].lower(),
|
|
|
"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"],
|
|
|
+ "accountCountry": account_country["eu"].lower(),
|
|
|
"shopifyCountry": shopify_country
|
|
|
})
|
|
|
-
|
|
|
return response.json(0, {"accountStatus": 3, "accountRegionList": account_region_list})
|
|
|
elif shopify_country:
|
|
|
if shopify_country == "eu":
|
|
@@ -266,7 +289,6 @@ class ShopifyView(View):
|
|
|
print(e)
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
-
|
|
|
@staticmethod
|
|
|
def call_search_customer(email):
|
|
|
urls = {
|
|
@@ -281,8 +303,10 @@ class ShopifyView(View):
|
|
|
try:
|
|
|
response = requests.get(url=url, params=params)
|
|
|
response.raise_for_status() # Raise an error for bad responses
|
|
|
- customer_country = response.json().get("data", None)
|
|
|
- return region, customer_country if customer_country else None
|
|
|
+ customer_country = response.json()["data"]
|
|
|
+ if customer_country == "":
|
|
|
+ return region, None
|
|
|
+ return region, customer_country
|
|
|
except requests.RequestException:
|
|
|
return region, None
|
|
|
|
|
@@ -306,3 +330,111 @@ class ShopifyView(View):
|
|
|
country_code = CountryModel.objects.filter(id=user_region_id).values_list("country_code", flat=True).first()
|
|
|
|
|
|
return response.json(0, country_code)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def get_country_domain_list(request_dict, response):
|
|
|
+ lang = request_dict.get('lang', 'en')
|
|
|
+ time_stamp = request_dict.get('time_stamp', None)
|
|
|
+ time_stamp_token = request_dict.get('time_stamp_token', None)
|
|
|
+
|
|
|
+ if not all([time_stamp, time_stamp_token]):
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ try:
|
|
|
+ # 时间戳token校验
|
|
|
+ if not CommonService.check_time_stamp_token(time_stamp_token, time_stamp):
|
|
|
+ return response.json(13)
|
|
|
+
|
|
|
+ lang_qs = LanguageModel.objects.filter(lang=lang)
|
|
|
+ language = lang_qs[0]
|
|
|
+ country_qs = CountryLanguageModel.objects.filter(language_id=language.id)
|
|
|
+ country_qs = country_qs.annotate(api=F('country__region__zosi_api'))
|
|
|
+ country_qs = country_qs.values('country_id', 'country_name', 'api').order_by('country_id')
|
|
|
+ country_list = []
|
|
|
+ for country in country_qs:
|
|
|
+ country['api'] = country['api'] + 'shopify/shopifyRegister'
|
|
|
+ country_list.append(country)
|
|
|
+ return response.json(0, country_list)
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def shopify_change_password(request_dict, response):
|
|
|
+ email = request_dict.get("email", None)
|
|
|
+ password = request_dict.get("password", None)
|
|
|
+ authcode = request_dict.get("authCode", None)
|
|
|
+ if not all([email, password, authcode]):
|
|
|
+ return response.json(444)
|
|
|
+ try:
|
|
|
+
|
|
|
+ data_valid = DataValid()
|
|
|
+ if data_valid.email_validate(email) is not True:
|
|
|
+ return response.json(105)
|
|
|
+ re_flag = data_valid.password_validate(password)
|
|
|
+
|
|
|
+ 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)
|
|
|
+
|
|
|
+ reds = RedisObject()
|
|
|
+ identifyingCode = reds.get_data(key=email + '_forgetPwdResetCode')
|
|
|
+ # 判断验证码是否过期
|
|
|
+ if identifyingCode is False:
|
|
|
+ return response.json(120)
|
|
|
+ # 验证码是否正确
|
|
|
+ if authcode != identifyingCode:
|
|
|
+ return response.json(121)
|
|
|
+
|
|
|
+ user_qs = Device_User.objects.filter(Q(username=email) | Q(userEmail=email))
|
|
|
+ if not user_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+
|
|
|
+ password = make_password(password)
|
|
|
+ user_qs.update(password=password)
|
|
|
+ reds.del_data(key=email + '_forgetPwdResetCode')
|
|
|
+ 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 verify_authcode(request_dict, response):
|
|
|
+ """
|
|
|
+ 验证验证码
|
|
|
+ """
|
|
|
+ email = request_dict.get("email", None)
|
|
|
+ authcode = request_dict.get("authCode", None)
|
|
|
+ code_type = request_dict.get("codeType", None)
|
|
|
+ if not all([email, authcode, code_type]):
|
|
|
+ return response.json(444)
|
|
|
+ try:
|
|
|
+ code_type = int(code_type)
|
|
|
+ if code_type == 1:
|
|
|
+ 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:
|
|
|
+ return response.json(444)
|
|
|
+ reds = RedisObject()
|
|
|
+ identifyingCode = reds.get_data(key=email + reds_key)
|
|
|
+ if identifyingCode is False:
|
|
|
+ return response.json(120)
|
|
|
+ # 验证码是否正确
|
|
|
+ if authcode != identifyingCode:
|
|
|
+ return response.json(121)
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|