Browse Source

调整银行编码判断

任翠亮 5 years ago
parent
commit
095f801253
2 changed files with 27 additions and 17 deletions
  1. 26 16
      awj/awj/utils/middleware.py
  2. 1 1
      awj/awj/utils/usr_data.py

+ 26 - 16
awj/awj/utils/middleware.py

@@ -2,23 +2,33 @@ import json
 
 from django import http
 
-
 def middleware(response):
     def inner(request):
-        print('执行之前代码')
-        # 获取参数
-        req_data = json.loads(request.body.decode())
-        user = req_data.get("user")  # 用户名
-        password = req_data.get("name")  # 用户名
-        user_ok='123'
-        password_ok='123'
-        if user!=user_ok or password!=password_ok:
-            print(2222)
-            return http.HttpResponseForbidden('账号密码不正确')
-        print(type(user))
-        print(password)
-        print(request.method)
-        res = response(request)
-        print('执行之后代码')
+        user_ok = '123'
+        password_ok = '123'
+        if request.method=='POST':
+            user = request.POST.get("user")
+            password = request.POST.get("password")
+            if user is None:
+                return http.HttpResponseForbidden('请输入用户名')
+            if password is None:
+                return http.HttpResponseForbidden('请输入密码')
+            if user!=user_ok or password!=password_ok:
+                return http.HttpResponseForbidden('账号密码不正确')
+            res = response(request)
+        else:
+            if len(request.body.decode())==0:
+                return http.HttpResponseForbidden('请传入用户名和密码')
+            req_data = json.loads(request.body.decode())
+            user = req_data.get("user")  # 用户名
+            password = req_data.get("password")  # 密码
+            if user is None:
+                return http.HttpResponseForbidden('请输入用户名')
+            if password is None:
+                return http.HttpResponseForbidden('请输入密码')
+            if user!=user_ok or password!=password_ok:
+                return http.HttpResponseForbidden('账号密码不正确')
+            # print(request.method)
+            res = response(request)
         return res
     return inner

+ 1 - 1
awj/awj/utils/usr_data.py

@@ -10,5 +10,5 @@ def usr_data(USR,USR_NAME,DATE):
     with connection.cursor() as cursor:
         row_usr = cursor.execute("SELECT COUNT(*) FROM SALM WHERE SAL_NO=%s", [USR]).fetchall()[0][0]
         if row_usr == 0:
-            cursor.execute("INSERT INTO SALM(SAL_NO,[NAME],USR,CHK_MAN,CLS_DATE,SYS_DATE)VALUES (%s,%s,'ADMIN','ADMIN',%s,%s)", [USR, USR_NAME,DATE,DATE])
+            cursor.execute("INSERT INTO SALM(SAL_NO,[NAME],USR,SYS_DATE)VALUES (%s,%s,%s,%s)", [USR, USR_NAME,USR_NAME,DATE])
     return "ok"