mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-01-16 01:13:47 +00:00
auto generate client token
This commit is contained in:
parent
27b2c92d8d
commit
16616ed217
@ -96,11 +96,13 @@ class JudgeServerHeartbeatAPI(CSRFExemptAPIView):
|
|||||||
def post(self, request):
|
def post(self, request):
|
||||||
judge_server_token = JudgeServerToken.objects.first()
|
judge_server_token = JudgeServerToken.objects.first()
|
||||||
if not judge_server_token:
|
if not judge_server_token:
|
||||||
return self.error("Web server token not set")
|
token = rand_str(12)
|
||||||
token = judge_server_token.token
|
JudgeServerToken.objects.create(token=token)
|
||||||
|
else:
|
||||||
|
token = judge_server_token.token
|
||||||
data = request.data
|
data = request.data
|
||||||
judge_server_token = request.META.get("HTTP_X_JUDGE_SERVER_TOKEN")
|
client_token = request.META.get("HTTP_X_JUDGE_SERVER_TOKEN")
|
||||||
if hashlib.sha256(token.encode("utf-8")).hexdigest() != judge_server_token:
|
if hashlib.sha256(token.encode("utf-8")).hexdigest() != client_token:
|
||||||
return self.error("Invalid token")
|
return self.error("Invalid token")
|
||||||
service_url = data.get("service_url")
|
service_url = data.get("service_url")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user