From 05228943b4912c1fed5906ed6ea814347e144db4 Mon Sep 17 00:00:00 2001 From: bettleChen <2207153529@qq.com> Date: Fri, 8 Sep 2023 10:08:53 +0800 Subject: [PATCH] update code --- EduSystemServer/.idea/EduSystemServer.iml | 10 +++++ EduSystemServer/.idea/misc.xml | 10 +++++ EduSystemServer/API/utils.py | 16 +++++++ EduSystemServer/API/views.py | 11 +++++ EduSystemServer/EduSystemServer/settings.py | 16 +++++++ EduSystemServer/EduSystemServer/urls.py | 11 +++++ EduSystemServer/Student/models.py | 20 +++++++++ EduSystemServer/Student/views.py | 42 ++++++++++++++++++ .../0002_auto_20230908_0939.cpython-37.pyc | Bin 0 -> 712 bytes EduSystemServer/teacher/models.py | 25 +++++++++++ 10 files changed, 161 insertions(+) create mode 100644 EduSystemServer/API/utils.py create mode 100644 EduSystemServer/teacher/migrations/__pycache__/0002_auto_20230908_0939.cpython-37.pyc diff --git a/EduSystemServer/.idea/EduSystemServer.iml b/EduSystemServer/.idea/EduSystemServer.iml index 892ceb8..d4543f0 100644 --- a/EduSystemServer/.idea/EduSystemServer.iml +++ b/EduSystemServer/.idea/EduSystemServer.iml @@ -14,11 +14,21 @@ +<<<<<<< Updated upstream +======= +<<<<<<< Updated upstream +>>>>>>> Stashed changes <<<<<<< HEAD ======= >>>>>>> 7b09141c358f80dd8877b8665d0d55b629db72aa +<<<<<<< Updated upstream +======= +======= + +>>>>>>> Stashed changes +>>>>>>> Stashed changes diff --git a/EduSystemServer/.idea/misc.xml b/EduSystemServer/.idea/misc.xml index 0d04900..37f93ff 100644 --- a/EduSystemServer/.idea/misc.xml +++ b/EduSystemServer/.idea/misc.xml @@ -1,8 +1,18 @@ +<<<<<<< Updated upstream +======= +<<<<<<< Updated upstream +>>>>>>> Stashed changes <<<<<<< HEAD ======= >>>>>>> 7b09141c358f80dd8877b8665d0d55b629db72aa +<<<<<<< Updated upstream +======= +======= + +>>>>>>> Stashed changes +>>>>>>> Stashed changes \ No newline at end of file diff --git a/EduSystemServer/API/utils.py b/EduSystemServer/API/utils.py new file mode 100644 index 0000000..2f6a929 --- /dev/null +++ b/EduSystemServer/API/utils.py @@ -0,0 +1,16 @@ + + +def jwt_response_payload_handler(token, user=None, request=None, role=None): + + if user.username: + name = user.username + else: + name = user.username + return { + "authenticated": True, + 'id': user.id, + "role": role, + 'name': name, + 'username': user.username, + 'token': token, + } \ No newline at end of file diff --git a/EduSystemServer/API/views.py b/EduSystemServer/API/views.py index 1ef3a82..156180f 100644 --- a/EduSystemServer/API/views.py +++ b/EduSystemServer/API/views.py @@ -21,7 +21,11 @@ def login(request): if student: request.session["username"] = student.username request.session["type"] = "student" +<<<<<<< Updated upstream result = ResponseUtil.ok(student.to_dict(), "login success!") +======= + result = {"code": 0, "message": "login success!"} +>>>>>>> Stashed changes else: result = {"code": -1, "message": "username or password error!"} elif _type == "teacher": @@ -30,13 +34,20 @@ def login(request): if teacher: request.session["username"] = teacher.username request.session["type"] = "teacher" +<<<<<<< Updated upstream result = ResponseUtil.ok(teacher.to_dict(), "login success!") +======= + result = {"code": 0, "message": "login success!"} +>>>>>>> Stashed changes else: result = ResponseUtil.error("username or password error!") else: result = ResponseUtil.error("type error!") return JsonResponse(result) +<<<<<<< Updated upstream +======= +>>>>>>> Stashed changes @csrf_exempt def get_user_info(request): _type = request.GET.get("type") diff --git a/EduSystemServer/EduSystemServer/settings.py b/EduSystemServer/EduSystemServer/settings.py index 4d62834..b34a3d0 100644 --- a/EduSystemServer/EduSystemServer/settings.py +++ b/EduSystemServer/EduSystemServer/settings.py @@ -12,7 +12,17 @@ https://docs.djangoproject.com/en/2.2/ref/settings/ import os +<<<<<<< Updated upstream +======= +CORS_ALLOW_ORIGIN_WHITELIST = [ + "http://localhost:8080", # 允许访问的来源 + "http://localhost:8000", # 允许访问的来源 + # 可以继续添加其他允许的来源 +] + +CORS_ALLOW_CREDENTIALS = True # 允许跨域请求携带凭据(例如Cookies) +>>>>>>> Stashed changes # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -55,6 +65,7 @@ MIDDLEWARE = [ 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'corsheaders.middleware.CorsMiddleware', +<<<<<<< Updated upstream 'django.middleware.common.CommonMiddleware', # 'API.middle.AuthMiddleware', ] @@ -76,6 +87,11 @@ CORS_ALLOW_HEADERS = ( ) +======= + # 'API.middle.AuthMiddleware', +] + +>>>>>>> Stashed changes ROOT_URLCONF = 'EduSystemServer.urls' diff --git a/EduSystemServer/EduSystemServer/urls.py b/EduSystemServer/EduSystemServer/urls.py index 51e7063..7cfa7f1 100644 --- a/EduSystemServer/EduSystemServer/urls.py +++ b/EduSystemServer/EduSystemServer/urls.py @@ -16,15 +16,26 @@ Including another URLconf from django.contrib import admin from django.urls import path, include from API.views import login, get_user_info +<<<<<<< Updated upstream + +======= +>>>>>>> Stashed changes urlpatterns = [ path('Eduadmin/', admin.site.urls), path('api/', include(("API.urls", "api"), namespace="api")), +<<<<<<< Updated upstream +======= +<<<<<<< Updated upstream +>>>>>>> Stashed changes path('teacher/', include(("teacher.urls", "teacher"), namespace="teacher")), path('student/', include(("Student.urls", "student"), namespace="student")), path('course/', include(("course.urls", "course"), namespace="course")), +======= + path('student/', include(("Student.urls", "studnet"), namespace="student")), +>>>>>>> Stashed changes path('login', login), path('userinfo', get_user_info), ] diff --git a/EduSystemServer/Student/models.py b/EduSystemServer/Student/models.py index 7a60250..e0c0548 100644 --- a/EduSystemServer/Student/models.py +++ b/EduSystemServer/Student/models.py @@ -4,6 +4,10 @@ from django.db import models # Create your models here. class Student(models.Model): sid = models.AutoField(primary_key=True, verbose_name="学生编号", name="sid") +<<<<<<< Updated upstream +======= +<<<<<<< Updated upstream +>>>>>>> Stashed changes <<<<<<< HEAD s_username = models.CharField(max_length=30, verbose_name="用户名称", name="s_username", blank=True) s_password = models.CharField(max_length=100, verbose_name="密码", name="s_password", blank=True) @@ -29,6 +33,22 @@ class Student(models.Model): return {"sid": self.sid, "name": self.name, "username": self.username, "password": self.password, "sex": self.sex, "grade": self.grade, "class_name": self.class_name, "major": self.major} >>>>>>> 7b09141c358f80dd8877b8665d0d55b629db72aa +<<<<<<< Updated upstream +======= +======= + username = models.CharField(max_length=30, verbose_name="用户名称", name="username", blank=True) + password = models.CharField(max_length=100, verbose_name="密码", name="password", blank=True) + name = models.CharField(max_length=100, verbose_name="姓名", name="name", blank=True) + sex = models.CharField(max_length=4, verbose_name="性别", name="sex", blank=True) + grade = models.CharField(max_length=20, verbose_name="年级", name="grade", blank=True) + class_name = models.CharField(max_length=50, verbose_name="班级", name="class_name", blank=True) + major = models.CharField(max_length=50, verbose_name="专业名称", name="major", blank=True) + + def to_dict(self): + return {"sid": self.sid, "name": self.name, "username": self.username, "password": self.password, + "sex": self.sex, "grade": self.grade, "class_name": self.class_name, "major": self.major} +>>>>>>> Stashed changes +>>>>>>> Stashed changes class Meta: db_table = "student" diff --git a/EduSystemServer/Student/views.py b/EduSystemServer/Student/views.py index 1b6ac00..2853a0e 100644 --- a/EduSystemServer/Student/views.py +++ b/EduSystemServer/Student/views.py @@ -2,7 +2,17 @@ from django.shortcuts import render # Create your views here. from django.http import JsonResponse +<<<<<<< Updated upstream from .models import Student +======= +<<<<<<< HEAD + +from EduSystemServer.utils import ResponseUtil +from Student.models import Student +======= +from .models import Student +>>>>>>> 1e084d20f30e0b66d5e309a483f87ce5cfe06c39 +>>>>>>> Stashed changes from django.views.decorators.csrf import csrf_exempt from django.http import QueryDict from io import BytesIO @@ -12,6 +22,27 @@ from django.http.multipartparser import MultiPartParser @csrf_exempt def studnets(request): if request.method == "POST": +<<<<<<< Updated upstream +======= +<<<<<<< HEAD + try: + request_data = json.loads(request.body) + print(request_data) + student = Student.objects.filter(sid=request_data.get("sid")).first() + student.username = request_data.get("username") + student.password = request_data.get("password") + student.name = request_data.get("name") + student.sex = request_data.get("sex") + student.grade = request_data.get("grade") + student.class_name = request_data.get("class_name") + student.major = request_data.get("major") + student.save() + response = ResponseUtil.ok(student.to_dict(), "更新成功!") + return JsonResponse(response) + except Exception as E: + return JsonResponse(ResponseUtil.error(E)) +======= +>>>>>>> Stashed changes student = Student() student.s_username = request.POST.get("s_username") student.s_password = request.POST.get("s_password") @@ -40,6 +71,10 @@ def studnets(request): student.save() response = {"code": 200, "message": "添加成功!", "data": student.to_dict()} return JsonResponse(response) +<<<<<<< Updated upstream +======= +>>>>>>> 1e084d20f30e0b66d5e309a483f87ce5cfe06c39 +>>>>>>> Stashed changes elif request.method == "GET": sid = request.GET.get('sid') s_name = request.GET.get('s_name') @@ -120,6 +155,13 @@ def studnets(request): xx = str(value).split('-')[0] print(xx.split('\r\n')) return JsonResponse({'code': 200, 'msg': 'success'}, safe=False) +<<<<<<< Updated upstream +======= + +<<<<<<< Updated upstream +======= +>>>>>>> Stashed changes +>>>>>>> Stashed changes def get_select_course_by_id(request): pass diff --git a/EduSystemServer/teacher/migrations/__pycache__/0002_auto_20230908_0939.cpython-37.pyc b/EduSystemServer/teacher/migrations/__pycache__/0002_auto_20230908_0939.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fe29714a792060630c5ccb593350d58dda0bf54c GIT binary patch literal 712 zcmYLHON-P%5biuD$|dC|R$rx0i|Q|(N~JZ8HSb@AehMTCI` z_25Yt6!fA81rPgA`YN+we}ETHR%dpc3SFtMzox3cs=n6gcm(a@lfUp>C*-#ROEWRp z!X?h50|Ht~GA-0HJ=8UFn}80+O9BSdCdLaRG{Ec=-#Wpw#Mh;lB_ke}Ns$X_X9ciS z3>CFBRdx%PxPy+7Py-U`ppCT9VCKY9$(cQAfe9Aa(3%t!h|Gr;;eC8X{ z8l-Xl0ENVlY0C0ZIhO5*j1LOIXdY(_k9du+21!%xN$Y;XQjkt17*`vWiz(~3Uyfh> znjg%3lPk=XcxhL8vRg5}hG55cr9+!UluD0MOkAZ5<2I$cRh+6^3IUt499TX~nBX`t z)UXY3OBLmYg6{Qk%o{AdV#-cO@Rjhh$Tsc|V07bhH2?H-{^oOZ{O0DVf=c>{xR1eM={{VH- B$!Y)q literal 0 HcmV?d00001 diff --git a/EduSystemServer/teacher/models.py b/EduSystemServer/teacher/models.py index 1d6056c..562b846 100644 --- a/EduSystemServer/teacher/models.py +++ b/EduSystemServer/teacher/models.py @@ -4,12 +4,37 @@ from django.db import models # Create your models here. class Teacher(models.Model): tid = models.AutoField(primary_key=True, verbose_name="教师编号", name="tid") +<<<<<<< Updated upstream +======= +<<<<<<< Updated upstream + username = models.CharField(max_length=128, verbose_name="用户名", name="username", blank=True, unique=True) + password = models.CharField(max_length=128, verbose_name="密码", name="password", blank=True) +======= +>>>>>>> Stashed changes +>>>>>>> Stashed changes name = models.CharField(max_length=255, verbose_name="教师名称", name="name", blank=True) sex = models.CharField(max_length=128, verbose_name="教师性别", name="sex", blank=True) title = models.CharField(max_length=128, verbose_name="教师职称", name="title", blank=True) education = models.CharField(max_length=128, verbose_name="教师学历", name="education", blank=True) dept = models.CharField(max_length=128, verbose_name="教师所属院系", name="dept", blank=True) +<<<<<<< Updated upstream +======= +<<<<<<< Updated upstream +======= + def to_dict(self): + return {"tid": self.tid, "name": self.name, "sex": self.sex, + "title": self.title, "education": self.education, "dept": self.dept} +>>>>>>> Stashed changes + +<<<<<<< HEAD + def to_dict(self): + return {"tid": self.tid, "name": self.name, "sex": self.sex, + "title": self.title, "education": self.education, + "dept": self.dept, "username": self.username, "password": self.password} +======= +>>>>>>> 1e084d20f30e0b66d5e309a483f87ce5cfe06c39 +>>>>>>> Stashed changes def to_dict(self): return {"tid": self.tid, "name": self.name, "sex": self.sex, "title": self.title,