|
@@ -9,6 +9,8 @@ import datetime
|
|
|
import hashlib
|
|
|
from utils.aestool import aescbc
|
|
|
|
|
|
+import decimal
|
|
|
+import uuid
|
|
|
from django import http
|
|
|
from django.contrib.sessions.backends.cache import SessionStore
|
|
|
from django.core.cache import cache
|
|
@@ -51,10 +53,6 @@ class CusDjangoJSONEncoder(json.JSONEncoder):
|
|
|
return str(o)
|
|
|
elif isinstance(o, uuid.UUID):
|
|
|
return str(o)
|
|
|
- elif isinstance(o, Promise):
|
|
|
- return six.text_type(o)
|
|
|
- elif isinstance(o, CallableBool):
|
|
|
- return bool(o)
|
|
|
else:
|
|
|
return super(DjangoJSONEncoder, self).default(o)
|
|
|
|
|
@@ -86,20 +84,6 @@ class AdminView(View):
|
|
|
handler = self.http_method_not_allowed
|
|
|
return admin_handler(handler, request, True, *args, **kwargs)
|
|
|
|
|
|
-class YRXView(View):
|
|
|
-
|
|
|
- @method_decorator(csrf_exempt)
|
|
|
- def dispatch(self, request, *args, **kwargs):
|
|
|
- """
|
|
|
- @attention: as_view()方法使用该方法来分发不同http method,添加异常处理及登陆校验
|
|
|
- """
|
|
|
- self.http_method_names.append("options")
|
|
|
- if request.method.lower() in self.http_method_names:
|
|
|
- handler = getattr(self, request.method.lower(), self.http_method_not_allowed)
|
|
|
- else:
|
|
|
- handler = self.http_method_not_allowed
|
|
|
- return yrx_handler(handler, request, True, *args, **kwargs)
|
|
|
-
|
|
|
|
|
|
class BaseView(View):
|
|
|
|
|
@@ -116,48 +100,6 @@ class BaseView(View):
|
|
|
return api_wapper(handler, request, False, *args, **kwargs)
|
|
|
|
|
|
|
|
|
-class UploadView(View):
|
|
|
-
|
|
|
- @method_decorator(csrf_exempt)
|
|
|
- def dispatch(self, request, *args, **kwargs):
|
|
|
- """
|
|
|
- @attention: as_view()方法使用该方法来分发不同http method,添加异常处理及登陆校验
|
|
|
- """
|
|
|
- if request.method.lower() in self.http_method_names:
|
|
|
- handler = getattr(self, request.method.lower(), self.http_method_not_allowed)
|
|
|
- else:
|
|
|
- handler = self.http_method_not_allowed
|
|
|
-
|
|
|
- return upload_wapper(handler,request,True, *args, **kwargs)
|
|
|
-
|
|
|
-
|
|
|
-class InnerView(View):
|
|
|
-
|
|
|
- @method_decorator(csrf_exempt)
|
|
|
- def dispatch(self, request, *args, **kwargs):
|
|
|
- """
|
|
|
- @attention: as_view()方法使用该方法来分发不同http method,添加异常处理及登陆校验
|
|
|
- """
|
|
|
- if request.method.lower() in self.http_method_names:
|
|
|
- handler = getattr(self, request.method.lower(), self.http_method_not_allowed)
|
|
|
- if request.META.get("HTTP_TOKEN") != "7dpHIhpweckghdoSvrXwMftcjZRIzKwJ":
|
|
|
- handler = self.http_method_not_allowed
|
|
|
- else:
|
|
|
- handler = self.http_method_not_allowed
|
|
|
-
|
|
|
- return api_wapper(handler, request, False, *args, **kwargs)
|
|
|
-
|
|
|
-
|
|
|
-def show_history(request):
|
|
|
- logined_history = cache.get("logined_history", {})
|
|
|
- for k, v in logined_history.iteritems():
|
|
|
- logger.info("k: %s, v: %s", str(k), str(v))
|
|
|
- logger.info("current session: %s", str(request.session.session_key))
|
|
|
- ss = SessionStore(request.session.session_key)
|
|
|
- for k, v in ss.iteritems():
|
|
|
- logger.info("k: %s, v: %s", str(k), str(v))
|
|
|
-
|
|
|
-
|
|
|
def api_wapper(handler, request, is_vauth, *args, **kwargs):
|
|
|
"""
|
|
|
@attention: 调试API时使用的装饰器
|
|
@@ -219,77 +161,8 @@ def admin_handler(handler, request, is_vauth, *args, **kwargs):
|
|
|
req_path = request.META["PATH_INFO"]
|
|
|
ip = request.META.get("HTTP_X_REAL_IP","")
|
|
|
token = request.META.get("HTTP_AUTHORIZATION")
|
|
|
- if is_vauth and token:
|
|
|
- dectoken = aescbc.decrypt(token)
|
|
|
- name = dectoken.split("_")[0]
|
|
|
- utype = dectoken.split("_")[1]
|
|
|
- if str(utype) == "0":
|
|
|
- user = UserInfo.objects.filter(id=name).first()
|
|
|
- elif str(utype) == "1":
|
|
|
- user = cm.Goverment.objects.filter(id=name).first()
|
|
|
- else:
|
|
|
- user = cm.EnterPrise.objects.filter(id=name).first()
|
|
|
- if not user and False:
|
|
|
- #return JsonResponse({"code":403,"data":{}})
|
|
|
- return HttpResponse(status=403)
|
|
|
-
|
|
|
- setattr(request, "ip", get_ip(request))
|
|
|
- setattr(request, "user", user)
|
|
|
- setattr(request, "utype", utype)
|
|
|
- if request.method == "OPTIONS":
|
|
|
- return JsonResponse({})
|
|
|
-
|
|
|
- body = request.body if hasattr(request, "body") else ""
|
|
|
- if "x-www-form-urlencoded" in request.content_type:
|
|
|
- info = http.QueryDict(body).dict()
|
|
|
- if not info:
|
|
|
- info = request.GET.dict()
|
|
|
- elif "application/json" in request.content_type:
|
|
|
- info = json.loads(body) if body else {}
|
|
|
- if not info:
|
|
|
- info = request.GET.dict()
|
|
|
- else:
|
|
|
- try:
|
|
|
- info = json.loads(body) if body else {}
|
|
|
- if not info:
|
|
|
- info = request.GET.dict()
|
|
|
- except:
|
|
|
- info = {}
|
|
|
-
|
|
|
- setattr(request, "json", info)
|
|
|
-
|
|
|
- try:
|
|
|
- ret = handler(request, *args, **kwargs)
|
|
|
- return ret
|
|
|
- except Exception as e:
|
|
|
- return to_fail(e)
|
|
|
-
|
|
|
-def yrx_handler(handler, request, is_vauth, *args, **kwargs):
|
|
|
- """
|
|
|
- 登录session校验
|
|
|
- """
|
|
|
- req_path = request.META["PATH_INFO"]
|
|
|
- ip = request.META.get("HTTP_X_REAL_IP","")
|
|
|
- token = request.META.get("HTTP_AUTHORIZATION")
|
|
|
- if is_vauth and token:
|
|
|
- dectoken = aescbc.decrypt(token)
|
|
|
- name = dectoken.split("_")[0]
|
|
|
- utype = dectoken.split("_")[1]
|
|
|
- if str(utype) == "0":
|
|
|
- user = cm.YRXUser.objects.filter(id=name).first()
|
|
|
- elif str(utype) == "1":
|
|
|
- user = cm.YRXUser.objects.filter(id=name).first()
|
|
|
- else:
|
|
|
- user = cm.YRXUser.objects.filter(id=name).first()
|
|
|
- if not user and False:
|
|
|
- #return JsonResponse({"code":403,"data":{}})
|
|
|
- return HttpResponse(status=403)
|
|
|
-
|
|
|
- setattr(request, "ip", get_ip(request))
|
|
|
- setattr(request, "user", user)
|
|
|
- setattr(request, "utype", utype)
|
|
|
- if request.method == "OPTIONS":
|
|
|
- return JsonResponse({})
|
|
|
+ if is_vauth and not request.user.is_authenticated():
|
|
|
+ return HttpResponse(status=403)
|
|
|
|
|
|
body = request.body if hasattr(request, "body") else ""
|
|
|
if "x-www-form-urlencoded" in request.content_type:
|
|
@@ -309,7 +182,7 @@ def yrx_handler(handler, request, is_vauth, *args, **kwargs):
|
|
|
info = {}
|
|
|
|
|
|
setattr(request, "json", info)
|
|
|
-
|
|
|
+ setattr(request, "ip", get_ip(request))
|
|
|
try:
|
|
|
ret = handler(request, *args, **kwargs)
|
|
|
return ret
|