diff --git a/ModelGrader.sqlite3 b/ModelGrader.sqlite3 index 04be82e..6ff7887 100644 Binary files a/ModelGrader.sqlite3 and b/ModelGrader.sqlite3 differ diff --git a/api/sandbox/section10/testcases/.gitkeep b/api/sandbox/section10/testcases/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/api/sandbox/section4/testcases/.gitkeep b/api/sandbox/section4/testcases/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/api/sandbox/section5/testcases/.gitkeep b/api/sandbox/section5/testcases/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/api/sandbox/section6/testcases/.gitkeep b/api/sandbox/section6/testcases/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/api/sandbox/section7/testcases/.gitkeep b/api/sandbox/section7/testcases/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/api/sandbox/section8/testcases/.gitkeep b/api/sandbox/section8/testcases/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/api/sandbox/section9/testcases/.gitkeep b/api/sandbox/section9/testcases/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/api/urls.py b/api/urls.py index e5a2b4a..30373b7 100644 --- a/api/urls.py +++ b/api/urls.py @@ -10,6 +10,7 @@ path("accounts",account.create_account), path("accounts/",account.get_account), path("accounts//daily-submissions",account.get_daily_submission), + path("accounts//password",account.change_password), path('accounts//problems',problem.create_problem), path('problems',problem.all_problem), diff --git a/api/views/account.py b/api/views/account.py index 0c1d610..b69df3b 100644 --- a/api/views/account.py +++ b/api/views/account.py @@ -25,6 +25,14 @@ def get_account(request,account_id): except: return Response({'message':'Account not found!'},status=status.HTTP_404_NOT_FOUND) +@api_view([PUT]) +def change_password(request,account_id): + account = Account.objects.get(account_id=account_id) + account.password = passwordEncryption(request.data['password']) + account.save() + + return Response({'message':"Your password has been changed"}) + @api_view([GET]) def get_daily_submission(request,account_id:int): submissions = Submission.objects.filter(account_id=account_id) @@ -40,6 +48,4 @@ def get_daily_submission(request,account_id:int): else: submission_by_date[date] = {"count":1, "submissions": [ submission ]} - print(submission_by_date) - return Response({"submissions_by_date": submission_by_date}) \ No newline at end of file diff --git a/api/views/auth.py b/api/views/auth.py index 110c8dd..11df9d1 100644 --- a/api/views/auth.py +++ b/api/views/auth.py @@ -11,8 +11,7 @@ from time import time from decouple import config -TOKEN_LIFETIME_HOURS = int(config('TOKEN_LIFETIME_HOURS')) -TOKEN_LIFETIME = TOKEN_LIFETIME_HOURS * 60 * 60 # (Second) +TOKEN_LIFETIME = int(config('TOKEN_LIFETIME_SECOND')) # (Second) @api_view([POST]) def login(request): diff --git a/api/views/problem.py b/api/views/problem.py index 28d2fd9..8690787 100644 --- a/api/views/problem.py +++ b/api/views/problem.py @@ -18,7 +18,7 @@ def create_problem(request,account_id): checked = checker(1,request.data['solution'],request.data['testcases'],request.data.get('time_limit',1.5)) if checked['has_error'] or checked['has_timeout']: - return Response({'detail': 'Error during creating. Your code may has an error/timeout!'},status=status.HTTP_406_NOT_ACCEPTABLE) + return Response({'detail': 'Error during creating. Your code may has an error/timeout!','result': checked},status=status.HTTP_406_NOT_ACCEPTABLE) problem = Problem( language = request.data['language'], @@ -44,13 +44,27 @@ def create_problem(request,account_id): @api_view([GET,DELETE]) def all_problem(request): if request.method == GET: + problem = Problem.objects.all() + + get_private = int(request.query_params.get("private",0)) + get_deactive = int(request.query_params.get("deactive",0)) + account_id = int(request.query_params.get("account_id",0)) + + if not get_private: + problem = problem.filter(is_private=False) + if not get_deactive: + problem = problem.filter(is_active=True) + if account_id != 0: + problem = problem.filter(account_id=account_id) + + problem = problem.order_by('-problem_id') + result = [model_to_dict(i) for i in problem] for i in result: i['creator'] = model_to_dict(Account.objects.get(account_id=i['account_id'])) - result.reverse() return Response({'result':result},status=status.HTTP_200_OK) elif request.method == DELETE: target = request.data.get("problem",[]) diff --git a/api/views/submission.py b/api/views/submission.py index 6b6ea78..209a3c4 100644 --- a/api/views/submission.py +++ b/api/views/submission.py @@ -8,7 +8,7 @@ from ..sandbox import grader from time import sleep -QUEUE = [0,0,0] +QUEUE = [0,0,0,0,0,0,0,0,0,0] def avaliableQueue(): global QUEUE diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..19721a2 --- /dev/null +++ b/start.sh @@ -0,0 +1 @@ +python manage.py runserver 0.0.0.0:8000 \ No newline at end of file