Przeglądaj źródła

shopify 登陆优化

linhaohong 5 miesięcy temu
rodzic
commit
3600a19cd1
1 zmienionych plików z 63 dodań i 55 usunięć
  1. 63 55
      Controller/ShopifyController.py

+ 63 - 55
Controller/ShopifyController.py

@@ -159,60 +159,62 @@ class ShopifyView(View):
         country_code = request_dict.get("countryCode", None)
         password = request_dict.get("password", None)
         authcode = request_dict.get("authCode", None)
+        try:
+            if not all([email, password, authcode, country_code]):
+                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)
 
-        if not all([email, password, authcode, country_code]):
-            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 or categories < 2:
-            return response.json(109)
-
-        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():
-            return response.json(103)
-        # 创建用户
-        password = make_password(password)
-        new_userID = CommonService.getUserID(μs=False, setOTAID=True)
-        country_code = country_code.upper()
-        countr_qs = CountryModel.objects.filter(country_code=country_code).values("id")
-        if countr_qs.exists():
-            region_country = countr_qs[0]['id']
-        else:
-            return response.json(173)
-        user_data = {
-            "username": email,
-            "NickName": email,
-            "userEmail": email,
-            "password": password,
-            "userID": new_userID,
-            "is_active": True,
-            "user_isValid": True,
-            "region_country": region_country,
-            "region_status": 1
-        }
-        Device_User.objects.create(**user_data)
-        reds.del_data(key=email + '_identifyingCode')
-        redirect_url = self.shopify_login_url("", country_code, email)
-        return response.json(0, redirect_url)
+            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 or categories < 2:
+                return response.json(109)
+
+            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():
+                return response.json(103)
+            # 创建用户
+            password = make_password(password)
+            new_userID = CommonService.getUserID(μs=False, setOTAID=True)
+            country_code = country_code.upper()
+            countr_qs = CountryModel.objects.filter(country_code=country_code).values("id")
+            if countr_qs.exists():
+                region_country = countr_qs[0]['id']
+            else:
+                return response.json(173)
+            user_data = {
+                "username": email,
+                "NickName": email,
+                "userEmail": email,
+                "password": password,
+                "userID": new_userID,
+                "is_active": True,
+                "user_isValid": True,
+                "region_country": region_country,
+                "region_status": 1
+            }
+            Device_User.objects.create(**user_data)
+            reds.del_data(key=email + '_identifyingCode')
+            redirect_url = self.shopify_login_url("", country_code, email)
+            return response.json(0, redirect_url)
+        except Exception as e:
+            return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
     def search_account(self, request_dict, response):
         email = request_dict.get("email")
@@ -439,29 +441,35 @@ class ShopifyView(View):
         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,
             "tag_string": "webLogin",
         }
         if iso2 in ["de", "jp"]:
             secret_key = f"{iso2}_multipass_secret"
             multipass_secret = SHOPIFY_CONFIG[secret_key]
+            timestamp = ShopifyMultipass.get_timezone_by_country(shopify_country_to_use)
+            customer_data["created_at"] = timestamp
             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]
+            timestamp = ShopifyMultipass.get_timezone_by_country(shopify_country_to_use)
+            customer_data["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 CONFIG_INFO == CONFIG_EUR:
             secret_key = "eu_multipass_secret"
+            timestamp = ShopifyMultipass.get_timezone_by_country('eu')
+            customer_data["created_at"] = timestamp
             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"
+            timestamp = ShopifyMultipass.get_timezone_by_country('uk')
+            customer_data["created_at"] = timestamp
             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}"