Selaa lähdekoodia

新增后台获取验证码、修复无法访问roomumy路径

zhangdongming 1 kuukausi sitten
vanhempi
commit
52faebf60f
3 muutettua tiedostoa jossa 123 lisäystä ja 4 poistoa
  1. 3 0
      Ansjer/urls.py
  2. 73 0
      Controller/UserController.py
  3. 47 4
      Service/TemplateService.py

+ 3 - 0
Ansjer/urls.py

@@ -373,6 +373,7 @@ urlpatterns = [
     re_path(r'^api/algorithm/', include("Ansjer.server_urls.algorithm_shop_url")),
     # KVS模块
     url(r'^kvs/', include("Ansjer.server_urls.kvs_url")),
+    re_path(r'^roomumy/', include("Roomumy.server_urls.roomumy_url")),
     # 超级密码模块
     re_path('appAccout/(?P<operation>.*)', AppAccountManagement.AppAccoutView.as_view()),
 
@@ -394,6 +395,8 @@ urlpatterns = [
     re_path('APNConfig/(?P<operation>.*)', APNConfigController.APNConfigView.as_view()),
     re_path(r'^api/device/custom/(?P<operation>.*)$', DeviceCustomUIDController.DeviceCustomUIDView.as_view()),
     re_path(r'^productInformation/(?P<operation>.*)$', IncomeProductsController.IncomeProductsView.as_view()),
+    # 校验验证码
+    re_path(r'^api/open/authCode/(?P<operation>.*)$', UserController.VerifyCodeView.as_view()),
 
 
     # 后台界面接口 -----------------------------------------------------

+ 73 - 0
Controller/UserController.py

@@ -3423,6 +3423,9 @@ class SingleLoginView(TemplateView):
         elif code_type == '2':
             redis_key = '{}_{}_GetDevicePassword'.format(email, uid)
             email_type = 'get_device_password'
+        elif code_type == '3':
+            redis_key = '{}_GetBackendVerificationCode'.format(email)
+            email_type = 'get_backend_verification_code'
         else:
             return response.json(444)
 
@@ -3478,6 +3481,9 @@ class SingleLoginView(TemplateView):
         elif code_type == '2':
             redis_key = '{}_{}_GetDevicePassword'.format(phone, uid)
             temp_msg = 'SMS_479855154' if country_code == '86' else 'SMS_479785146'
+        elif code_type == '3':
+            redis_key = '{}_GetBackendVerificationCode'.format(phone)
+            temp_msg = 'SMS_151675022' if country_code == '86' else 'SMS_172165867'
         else:
             return response.json(444)
 
@@ -5180,3 +5186,70 @@ class ChangeAccountInfoView(View):
         else:
             ord_user_qs.update(phone=new_phone)
         return response.json(0)
+
+
+class VerifyCodeView(View):
+    def get(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        operation = kwargs.get('operation')
+        request_dict = request.GET
+        return self.validation(request_dict, request, operation)
+
+    def post(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        operation = kwargs.get('operation')
+        request_dict = request.POST
+        return self.validation(request_dict, request, operation)
+
+    def validation(self, request_dict, request, operation):
+        language = request_dict.get('lang', 'en')
+        response = ResponseObject(language)
+        if operation == 'verifyCode':
+            return self.verify_code(request_dict, response)
+        else:
+            return response.json(444)
+
+    @staticmethod
+    def verify_code(request_dict, response):
+        """
+        验证邮箱验证码
+        @param username: 账户名
+        @param code: 用户输入的验证码
+        @param response: 响应对象
+        @return: 验证结果
+        """
+        try:
+            username = request_dict.get('username')
+            code = request_dict.get('code')
+
+            # 基础参数验证
+            if not username or not code:
+                return response.json(444)
+
+            # 生成缓存Key
+            redis_key = f'{username}_GetBackendVerificationCode'
+            reds = RedisObject()
+
+            # 获取并验证验证码
+            cached_code = reds.get_data(key=redis_key)
+            if cached_code is False:
+                return response.json(92)
+
+            # 验证失败次数控制
+            if cached_code != code:
+                failure_key = f"{redis_key}_failures"
+                failures_raw = reds.get_data(key=failure_key)
+                failures = int(failures_raw or 0) + 1
+                reds.set_data(key=failure_key, val=failures, expire=60)
+
+                if failures >= 5:
+                    return response.json(5)
+
+                return response.json(121)
+
+            # 验证成功,清理缓存
+            reds.del_data(redis_key)
+            reds.del_data(f"{redis_key}_failures")
+            return response.json(0)
+        except Exception as e:
+            return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))

+ 47 - 4
Service/TemplateService.py

@@ -133,7 +133,7 @@ class TemplateService:
         elif type == 'get_device_password':
                 data = {
                     'cn': {
-                        'title': '查看设备密码',
+                        'title': '重置设备密码',
                         'body': """
                             <!DOCTYPE html>
         <html lang="en">
@@ -145,7 +145,7 @@ class TemplateService:
         <div class="content"
              style="overflow: hidden;padding:30px 10% 70px 10%;margin:0 10%;background-color: #fff;box-shadow:0 4px 20px rgba(0,0,0,0.1);word-break: break-all;">
             <h2 style="margin: 30px 0;">您好,{username}</h2>
-            <p style="margin-bottom: 40px;">请输入验证码查看设备密码,有效期5分钟:</p>
+            <p style="margin-bottom: 40px;">请输入验证码重置设备密码,有效期5分钟:</p>
             <span style="padding: 10px 20px; font-size: 24px;background-color: #EB6F5A;border-radius:4px;color:#fff;">{captcha}</span>
         </div>
         </body>
@@ -153,7 +153,7 @@ class TemplateService:
                             """,
                     },
                     'en': {
-                        'title': 'View Device Password',
+                        'title': 'Reset Device Password',
                         'body': """
                             <!DOCTYPE html>
         <html lang="en">
@@ -165,7 +165,50 @@ class TemplateService:
         <div class="content"
              style="overflow: hidden;padding:30px 10% 70px 10%;margin:0 10%;background-color: #fff;box-shadow:0 4px 20px rgba(0,0,0,0.1);word-break: break-all;">
             <h2 style="margin: 30px 0;">Hello, {username}</h2>
-            <p style="margin-bottom: 40px;">Please input code to view device password. only valid in 5 minutes!</p>
+            <p style="margin-bottom: 40px;">Please input code to reset device password. only valid in 5 minutes!</p>
+            <span style="padding: 10px 20px; font-size: 24px;background-color: #EB6F5A;border-radius:4px;color:#fff;">{captcha}</span>
+        </div>
+        </body>
+        </html>
+        """
+                    }
+                }
+        elif type == 'get_backend_verification_code':
+                data = {
+                    'cn': {
+                        'title': '获取后台验证码',
+                        'body': """
+                            <!DOCTYPE html>
+        <html lang="en">
+        <head>
+            <meta charset="UTF-8">
+            <title>Title</title>
+        </head>
+        <body>
+        <div class="content"
+             style="overflow: hidden;padding:30px 10% 70px 10%;margin:0 10%;background-color: #fff;box-shadow:0 4px 20px rgba(0,0,0,0.1);word-break: break-all;">
+            <h2 style="margin: 30px 0;">您好,{username}</h2>
+            <p style="margin-bottom: 40px;">请输入验证码获取后台验证码,有效期5分钟:</p>
+            <span style="padding: 10px 20px; font-size: 24px;background-color: #EB6F5A;border-radius:4px;color:#fff;">{captcha}</span>
+        </div>
+        </body>
+        </html>
+                            """,
+                    },
+                    'en': {
+                        'title': 'Get Backend Verification Code',
+                        'body': """
+                            <!DOCTYPE html>
+        <html lang="en">
+        <head>
+            <meta charset="UTF-8">
+            <title>Title</title>
+        </head>
+        <body>
+        <div class="content"
+             style="overflow: hidden;padding:30px 10% 70px 10%;margin:0 10%;background-color: #fff;box-shadow:0 4px 20px rgba(0,0,0,0.1);word-break: break-all;">
+            <h2 style="margin: 30px 0;">Hello, {username}</h2>
+            <p style="margin-bottom: 40px;">Please input code to get backend verification code. only valid in 5 minutes!</p>
             <span style="padding: 10px 20px; font-size: 24px;background-color: #EB6F5A;border-radius:4px;color:#fff;">{captcha}</span>
         </div>
         </body>