diff --git a/EduSystemServer/API/__pycache__/urls.cpython-37.pyc b/EduSystemServer/API/__pycache__/urls.cpython-37.pyc index d0e5e43..9e8ecab 100644 Binary files a/EduSystemServer/API/__pycache__/urls.cpython-37.pyc and b/EduSystemServer/API/__pycache__/urls.cpython-37.pyc differ diff --git a/EduSystemServer/API/__pycache__/views.cpython-37.pyc b/EduSystemServer/API/__pycache__/views.cpython-37.pyc index 67ffb3d..7e6277f 100644 Binary files a/EduSystemServer/API/__pycache__/views.cpython-37.pyc and b/EduSystemServer/API/__pycache__/views.cpython-37.pyc differ diff --git a/EduSystemServer/API/views.py b/EduSystemServer/API/views.py index e00b419..1ef3a82 100644 --- a/EduSystemServer/API/views.py +++ b/EduSystemServer/API/views.py @@ -1,8 +1,7 @@ import json from django.shortcuts import render -from django.http import JsonResponse - +from django.http import JsonResponse, HttpResponse # Create your views here. from django.views.decorators.csrf import csrf_exempt @@ -22,7 +21,7 @@ def login(request): if student: request.session["username"] = student.username request.session["type"] = "student" - result = {"code": 0, "message": "login success!"} + result = ResponseUtil.ok(student.to_dict(), "login success!") else: result = {"code": -1, "message": "username or password error!"} elif _type == "teacher": @@ -31,12 +30,13 @@ def login(request): if teacher: request.session["username"] = teacher.username request.session["type"] = "teacher" - result = {"code": 0, "message": "login success!"} + result = ResponseUtil.ok(teacher.to_dict(), "login success!") else: result = ResponseUtil.error("username or password error!") else: result = ResponseUtil.error("type error!") return JsonResponse(result) + @csrf_exempt def get_user_info(request): _type = request.GET.get("type") diff --git a/EduSystemServer/EduSystemServer/__pycache__/settings.cpython-37.pyc b/EduSystemServer/EduSystemServer/__pycache__/settings.cpython-37.pyc index b8e0d6c..026cc4f 100644 Binary files a/EduSystemServer/EduSystemServer/__pycache__/settings.cpython-37.pyc and b/EduSystemServer/EduSystemServer/__pycache__/settings.cpython-37.pyc differ diff --git a/EduSystemServer/EduSystemServer/__pycache__/urls.cpython-37.pyc b/EduSystemServer/EduSystemServer/__pycache__/urls.cpython-37.pyc index 657ef8d..7bf7f1a 100644 Binary files a/EduSystemServer/EduSystemServer/__pycache__/urls.cpython-37.pyc and b/EduSystemServer/EduSystemServer/__pycache__/urls.cpython-37.pyc differ diff --git a/EduSystemServer/EduSystemServer/__pycache__/utils.cpython-37.pyc b/EduSystemServer/EduSystemServer/__pycache__/utils.cpython-37.pyc index 284e6ad..34c17df 100644 Binary files a/EduSystemServer/EduSystemServer/__pycache__/utils.cpython-37.pyc and b/EduSystemServer/EduSystemServer/__pycache__/utils.cpython-37.pyc differ diff --git a/EduSystemServer/EduSystemServer/settings.py b/EduSystemServer/EduSystemServer/settings.py index 6bcb726..4d62834 100644 --- a/EduSystemServer/EduSystemServer/settings.py +++ b/EduSystemServer/EduSystemServer/settings.py @@ -12,13 +12,7 @@ https://docs.djangoproject.com/en/2.2/ref/settings/ import os -CORS_ALLOW_ORIGIN_WHITELIST = [ - "http://localhost:8080", # 允许访问的来源 - "http://localhost:8000", # 允许访问的来源 - # 可以继续添加其他允许的来源 -] -CORS_ALLOW_CREDENTIALS = True # 允许跨域请求携带凭据(例如Cookies) # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -61,9 +55,27 @@ MIDDLEWARE = [ 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'corsheaders.middleware.CorsMiddleware', + 'django.middleware.common.CommonMiddleware', # 'API.middle.AuthMiddleware', ] +CORS_ALLOW_CREDENTIALS = True +CORS_ORIGIN_ALLOW_ALL = True +CORS_ALLOW_HEADERS = ( + 'XMLHttpRequest', + 'X_FILENAME', + 'accept-encoding', + 'authorization', + 'content-type', + 'dnt', + 'origin', + 'user-agent', + 'x-csrftoken', + 'x-requested-with', + 'Pragma', +) + + ROOT_URLCONF = 'EduSystemServer.urls' diff --git a/EduSystemServer/Eduadmin/migrations/__pycache__/0001_initial.cpython-37.pyc b/EduSystemServer/Eduadmin/migrations/__pycache__/0001_initial.cpython-37.pyc index 11aa473..70799ff 100644 Binary files a/EduSystemServer/Eduadmin/migrations/__pycache__/0001_initial.cpython-37.pyc and b/EduSystemServer/Eduadmin/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/EduSystemServer/Student/__pycache__/models.cpython-37.pyc b/EduSystemServer/Student/__pycache__/models.cpython-37.pyc index ceec81f..a06cb52 100644 Binary files a/EduSystemServer/Student/__pycache__/models.cpython-37.pyc and b/EduSystemServer/Student/__pycache__/models.cpython-37.pyc differ diff --git a/EduSystemServer/Student/__pycache__/urls.cpython-37.pyc b/EduSystemServer/Student/__pycache__/urls.cpython-37.pyc index c4da221..bfa6066 100644 Binary files a/EduSystemServer/Student/__pycache__/urls.cpython-37.pyc and b/EduSystemServer/Student/__pycache__/urls.cpython-37.pyc differ diff --git a/EduSystemServer/Student/__pycache__/views.cpython-37.pyc b/EduSystemServer/Student/__pycache__/views.cpython-37.pyc index da4ae69..c3da84c 100644 Binary files a/EduSystemServer/Student/__pycache__/views.cpython-37.pyc and b/EduSystemServer/Student/__pycache__/views.cpython-37.pyc differ diff --git a/EduSystemServer/Student/migrations/__pycache__/0001_initial.cpython-37.pyc b/EduSystemServer/Student/migrations/__pycache__/0001_initial.cpython-37.pyc index 4493e78..266d761 100644 Binary files a/EduSystemServer/Student/migrations/__pycache__/0001_initial.cpython-37.pyc and b/EduSystemServer/Student/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/EduSystemServer/course/__pycache__/models.cpython-37.pyc b/EduSystemServer/course/__pycache__/models.cpython-37.pyc index a7d2704..2eb682e 100644 Binary files a/EduSystemServer/course/__pycache__/models.cpython-37.pyc and b/EduSystemServer/course/__pycache__/models.cpython-37.pyc differ diff --git a/EduSystemServer/course/__pycache__/urls.cpython-37.pyc b/EduSystemServer/course/__pycache__/urls.cpython-37.pyc new file mode 100644 index 0000000..ad26685 Binary files /dev/null and b/EduSystemServer/course/__pycache__/urls.cpython-37.pyc differ diff --git a/EduSystemServer/course/__pycache__/views.cpython-37.pyc b/EduSystemServer/course/__pycache__/views.cpython-37.pyc index 2244580..7d87c47 100644 Binary files a/EduSystemServer/course/__pycache__/views.cpython-37.pyc and b/EduSystemServer/course/__pycache__/views.cpython-37.pyc differ diff --git a/EduSystemServer/course/migrations/__pycache__/0001_initial.cpython-37.pyc b/EduSystemServer/course/migrations/__pycache__/0001_initial.cpython-37.pyc index 6504fc1..67c8a87 100644 Binary files a/EduSystemServer/course/migrations/__pycache__/0001_initial.cpython-37.pyc and b/EduSystemServer/course/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/EduSystemServer/course/models.py b/EduSystemServer/course/models.py index 4f56f8e..fc7381f 100644 --- a/EduSystemServer/course/models.py +++ b/EduSystemServer/course/models.py @@ -13,7 +13,7 @@ class Course(models.Model): tid = models.ForeignKey(Teacher, to_field="tid", on_delete=models.CASCADE, name="tid") def to_dict(self): - return {"cid": self.cid, "c_name": self.c_name, "type": self.type, "credit": self.credit, + return {"cid": self.cid, "c_name": self.name, "type": self.type, "credit": self.credit, "tid": self.tid} class Meta: diff --git a/EduSystemServer/teacher/__pycache__/models.cpython-37.pyc b/EduSystemServer/teacher/__pycache__/models.cpython-37.pyc index 0544e4d..a6bd9eb 100644 Binary files a/EduSystemServer/teacher/__pycache__/models.cpython-37.pyc and b/EduSystemServer/teacher/__pycache__/models.cpython-37.pyc differ diff --git a/EduSystemServer/teacher/migrations/__pycache__/0001_initial.cpython-37.pyc b/EduSystemServer/teacher/migrations/__pycache__/0001_initial.cpython-37.pyc index de517af..d917461 100644 Binary files a/EduSystemServer/teacher/migrations/__pycache__/0001_initial.cpython-37.pyc and b/EduSystemServer/teacher/migrations/__pycache__/0001_initial.cpython-37.pyc differ