update code

scl-branch
bettleChen 1 year ago
parent 1e084d20f3
commit 05228943b4

@ -14,11 +14,21 @@
</component> </component>
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$" />
<<<<<<< Updated upstream
=======
<<<<<<< Updated upstream
>>>>>>> Stashed changes
<<<<<<< HEAD <<<<<<< HEAD
<orderEntry type="jdk" jdkName="Python 3.8 (2)" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Python 3.8 (2)" jdkType="Python SDK" />
======= =======
<orderEntry type="jdk" jdkName="Python 3.7 (EduSystemServer)" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Python 3.7 (EduSystemServer)" jdkType="Python SDK" />
>>>>>>> 7b09141c358f80dd8877b8665d0d55b629db72aa >>>>>>> 7b09141c358f80dd8877b8665d0d55b629db72aa
<<<<<<< Updated upstream
=======
=======
<orderEntry type="jdk" jdkName="Python 3.7 (EduSystemServer)" jdkType="Python SDK" />
>>>>>>> Stashed changes
>>>>>>> Stashed changes
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
<component name="TemplatesService"> <component name="TemplatesService">

@ -1,8 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<<<<<<< Updated upstream
=======
<<<<<<< Updated upstream
>>>>>>> Stashed changes
<<<<<<< HEAD <<<<<<< HEAD
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (2)" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (2)" project-jdk-type="Python SDK" />
======= =======
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (EduSystemServer)" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (EduSystemServer)" project-jdk-type="Python SDK" />
>>>>>>> 7b09141c358f80dd8877b8665d0d55b629db72aa >>>>>>> 7b09141c358f80dd8877b8665d0d55b629db72aa
<<<<<<< Updated upstream
=======
=======
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (EduSystemServer)" project-jdk-type="Python SDK" />
>>>>>>> Stashed changes
>>>>>>> Stashed changes
</project> </project>

@ -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,
}

@ -21,7 +21,11 @@ def login(request):
if student: if student:
request.session["username"] = student.username request.session["username"] = student.username
request.session["type"] = "student" request.session["type"] = "student"
<<<<<<< Updated upstream
result = ResponseUtil.ok(student.to_dict(), "login success!") result = ResponseUtil.ok(student.to_dict(), "login success!")
=======
result = {"code": 0, "message": "login success!"}
>>>>>>> Stashed changes
else: else:
result = {"code": -1, "message": "username or password error!"} result = {"code": -1, "message": "username or password error!"}
elif _type == "teacher": elif _type == "teacher":
@ -30,13 +34,20 @@ def login(request):
if teacher: if teacher:
request.session["username"] = teacher.username request.session["username"] = teacher.username
request.session["type"] = "teacher" request.session["type"] = "teacher"
<<<<<<< Updated upstream
result = ResponseUtil.ok(teacher.to_dict(), "login success!") result = ResponseUtil.ok(teacher.to_dict(), "login success!")
=======
result = {"code": 0, "message": "login success!"}
>>>>>>> Stashed changes
else: else:
result = ResponseUtil.error("username or password error!") result = ResponseUtil.error("username or password error!")
else: else:
result = ResponseUtil.error("type error!") result = ResponseUtil.error("type error!")
return JsonResponse(result) return JsonResponse(result)
<<<<<<< Updated upstream
=======
>>>>>>> Stashed changes
@csrf_exempt @csrf_exempt
def get_user_info(request): def get_user_info(request):
_type = request.GET.get("type") _type = request.GET.get("type")

@ -12,7 +12,17 @@ https://docs.djangoproject.com/en/2.2/ref/settings/
import os 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, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -55,6 +65,7 @@ MIDDLEWARE = [
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware', 'corsheaders.middleware.CorsMiddleware',
<<<<<<< Updated upstream
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
# 'API.middle.AuthMiddleware', # 'API.middle.AuthMiddleware',
] ]
@ -76,6 +87,11 @@ CORS_ALLOW_HEADERS = (
) )
=======
# 'API.middle.AuthMiddleware',
]
>>>>>>> Stashed changes
ROOT_URLCONF = 'EduSystemServer.urls' ROOT_URLCONF = 'EduSystemServer.urls'

@ -16,15 +16,26 @@ Including another URLconf
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
from API.views import login, get_user_info from API.views import login, get_user_info
<<<<<<< Updated upstream
=======
>>>>>>> Stashed changes
urlpatterns = [ urlpatterns = [
path('Eduadmin/', admin.site.urls), path('Eduadmin/', admin.site.urls),
path('api/', include(("API.urls", "api"), namespace="api")), path('api/', include(("API.urls", "api"), namespace="api")),
<<<<<<< Updated upstream
=======
<<<<<<< Updated upstream
>>>>>>> Stashed changes
path('teacher/', include(("teacher.urls", "teacher"), namespace="teacher")), path('teacher/', include(("teacher.urls", "teacher"), namespace="teacher")),
path('student/', include(("Student.urls", "student"), namespace="student")), path('student/', include(("Student.urls", "student"), namespace="student")),
path('course/', include(("course.urls", "course"), namespace="course")), path('course/', include(("course.urls", "course"), namespace="course")),
=======
path('student/', include(("Student.urls", "studnet"), namespace="student")),
>>>>>>> Stashed changes
path('login', login), path('login', login),
path('userinfo', get_user_info), path('userinfo', get_user_info),
] ]

@ -4,6 +4,10 @@ from django.db import models
# Create your models here. # Create your models here.
class Student(models.Model): class Student(models.Model):
sid = models.AutoField(primary_key=True, verbose_name="学生编号", name="sid") sid = models.AutoField(primary_key=True, verbose_name="学生编号", name="sid")
<<<<<<< Updated upstream
=======
<<<<<<< Updated upstream
>>>>>>> Stashed changes
<<<<<<< HEAD <<<<<<< HEAD
s_username = models.CharField(max_length=30, verbose_name="用户名称", name="s_username", blank=True) 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) 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, 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} "sex": self.sex, "grade": self.grade, "class_name": self.class_name, "major": self.major}
>>>>>>> 7b09141c358f80dd8877b8665d0d55b629db72aa >>>>>>> 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: class Meta:
db_table = "student" db_table = "student"

@ -2,7 +2,17 @@ from django.shortcuts import render
# Create your views here. # Create your views here.
from django.http import JsonResponse from django.http import JsonResponse
<<<<<<< Updated upstream
from .models import Student 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.views.decorators.csrf import csrf_exempt
from django.http import QueryDict from django.http import QueryDict
from io import BytesIO from io import BytesIO
@ -12,6 +22,27 @@ from django.http.multipartparser import MultiPartParser
@csrf_exempt @csrf_exempt
def studnets(request): def studnets(request):
if request.method == "POST": 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 = Student()
student.s_username = request.POST.get("s_username") student.s_username = request.POST.get("s_username")
student.s_password = request.POST.get("s_password") student.s_password = request.POST.get("s_password")
@ -40,6 +71,10 @@ def studnets(request):
student.save() student.save()
response = {"code": 200, "message": "添加成功!", "data": student.to_dict()} response = {"code": 200, "message": "添加成功!", "data": student.to_dict()}
return JsonResponse(response) return JsonResponse(response)
<<<<<<< Updated upstream
=======
>>>>>>> 1e084d20f30e0b66d5e309a483f87ce5cfe06c39
>>>>>>> Stashed changes
elif request.method == "GET": elif request.method == "GET":
sid = request.GET.get('sid') sid = request.GET.get('sid')
s_name = request.GET.get('s_name') s_name = request.GET.get('s_name')
@ -120,6 +155,13 @@ def studnets(request):
xx = str(value).split('-')[0] xx = str(value).split('-')[0]
print(xx.split('\r\n')) print(xx.split('\r\n'))
return JsonResponse({'code': 200, 'msg': 'success'}, safe=False) return JsonResponse({'code': 200, 'msg': 'success'}, safe=False)
<<<<<<< Updated upstream
=======
<<<<<<< Updated upstream
=======
>>>>>>> Stashed changes
>>>>>>> Stashed changes
def get_select_course_by_id(request): def get_select_course_by_id(request):
pass pass

@ -4,12 +4,37 @@ from django.db import models
# Create your models here. # Create your models here.
class Teacher(models.Model): class Teacher(models.Model):
tid = models.AutoField(primary_key=True, verbose_name="教师编号", name="tid") 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) name = models.CharField(max_length=255, verbose_name="教师名称", name="name", blank=True)
sex = models.CharField(max_length=128, verbose_name="教师性别", name="sex", 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) title = models.CharField(max_length=128, verbose_name="教师职称", name="title", blank=True)
education = models.CharField(max_length=128, verbose_name="教师学历", name="education", 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) 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): def to_dict(self):
return {"tid": self.tid, "name": self.name, "sex": self.sex, "title": self.title, return {"tid": self.tid, "name": self.name, "sex": self.sex, "title": self.title,

Loading…
Cancel
Save