CMS_Django_Backend/apps/api/views.py
jayhgq 4d5846f81e 1.增加config配置文件,自定义是否是用加密
2.增加区分加密数据库和非加密数据库
3.重构现有接口,区分是否加密和是用的加密方式,目前支持caesar和base64两种加密方式,仅在数据库存储时加密
2024-09-17 00:00:45 +08:00

39 lines
1.5 KiB
Python

from django.shortcuts import HttpResponse
from apps.api import models as m_api
from django.views.decorators.http import require_http_methods, require_POST, require_GET
from apps.api.common import CaesarCypherClass, Base64CypherClass
from apps.api.config import Config
config = Config()
# Create your views here.
@require_POST
def get_config(request):
try:
identity = request.POST.get("param")
if config.getconfig("isCypher"):
if config.getconfig("CypherMethod") == "base64":
param_base64 = m_api.SysConfig.objects.using("cypher").filter(identity=identity).first().param
param = Base64CypherClass().base64_decode_str(Base64CypherClass(), param_base64)
return HttpResponse(param)
if config.getconfig("CypherMethod") == "caesar":
param_base64 = m_api.SysConfig.objects.using("cypher").filter(identity=identity).first().param
param = CaesarCypherClass.caesar_decode(param_base64)
return HttpResponse(param)
else:
param = m_api.SysConfig.objects.using("default").filter(identity=identity).first().param
return HttpResponse(param)
except Exception as e:
print(f"报错了:{e}")
return HttpResponse(f"报错了:{e}")
@require_POST
def add_config(request):
try:
pass
except Exception as e:
print(f"报错了:{e}")
return HttpResponse(f"报错了:{e}")