Skip to content

Commit

Permalink
merge from develop
Browse files Browse the repository at this point in the history
  • Loading branch information
lightless233 committed Dec 2, 2018
2 parents e1282e8 + 3070d93 commit 2fcfcf6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions geye/config/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
# CSRF_COOKIE_DOMAIN = "localhost:8080"
# CSRF_USE_SESSIONS = True
CSRF_COOKIE_SAMESITE = None
ALLOWED_CORS = [
"localhost",
"127.0.0.1"
]

##########
# Queue settings
Expand Down
4 changes: 3 additions & 1 deletion geye/database/models/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def update_token(self, params):
return None
else:
obj.token_name = params["tokenName"]
obj.token = params["tokenContent"]
# 如果传递过来的token中有星号,那么不对token字段进行更新
if "*" not in params["tokenContent"]:
obj.token = params["tokenContent"]
# obj.remain_limit = params["remainLimit"]
obj.status = params["status"]
obj.save()
Expand Down
6 changes: 2 additions & 4 deletions geye/system/middleware/cors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from urllib.parse import urlparse

from django.conf import settings
from django.http import HttpResponseForbidden

from geye.utils.log import logger
Expand All @@ -26,10 +27,7 @@ def __init__(self, get_response):
super(CORSMiddleware, self).__init__()
self.get_response = get_response

self.allowed_origins = [
"localhost",
"127.0.0.1",
]
self.allowed_origins = settings.ALLOWED_CORS

def __call__(self, request):
response = self.get_response(request)
Expand Down
9 changes: 7 additions & 2 deletions geye/web/controller/token/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
from geye.utils.validator import RequestValidator


def mask_token(token):
return token[:8] + "*" * 24


class TokensView(View):
"""
获取所有token信息
Expand All @@ -35,7 +39,7 @@ def get(request):
data.append({
"id": row.id,
"tokenName": row.token_name,
"tokenContent": row.token,
"tokenContent": mask_token(row.token),
"status": row.status,
"remainLimit": row.remain_limit
})
Expand Down Expand Up @@ -123,7 +127,7 @@ def post(request):
return JsonResponse({"code": 1001, "message": "更新成功!", "data": {
"id": obj.id,
"tokenName": obj.token_name,
"tokenContent": obj.token,
"tokenContent": mask_token(obj.token),
"status": obj.status,
"remainLimit": obj.remain_limit,
}})
Expand Down Expand Up @@ -160,6 +164,7 @@ def get(request):

obj = GeyeTokenModel.instance.get_details(token_id)
if obj:
obj["tokenContent"] = mask_token(obj["tokenContent"])
return JsonResponse({"code": 1001, "message": "获取成功!", "data": obj})
else:
return JsonResponse({"code": 1002, "message": "获取失败!"})

0 comments on commit 2fcfcf6

Please sign in to comment.