更新最新代码
This commit is contained in:
+46
-2
@@ -8,6 +8,7 @@ from rest_framework.views import APIView
|
||||
|
||||
from server.util.constant_util import *
|
||||
from server.util.mix_util import build_response
|
||||
from django.shortcuts import render
|
||||
|
||||
|
||||
class AuthBackend(ModelBackend):
|
||||
@@ -46,10 +47,33 @@ class LoginView(APIView):
|
||||
user = authenticate(username=username, password=password)
|
||||
|
||||
if user is not None:
|
||||
if user.is_active:
|
||||
if user.is_active and user.type_t_or_s == 2:
|
||||
# 记住登录状态
|
||||
login(request, user)
|
||||
return build_response(msg='登录成功')
|
||||
return build_response(msg='学生端登录成功')
|
||||
else:
|
||||
return build_response(code=CODE_FAILED, msg='登录失败')
|
||||
else:
|
||||
return build_response(code=CODE_FAILED, msg='登录失败')
|
||||
|
||||
class LoginView_teacher(APIView):
|
||||
"""
|
||||
|
||||
"""
|
||||
|
||||
def post(self, request):
|
||||
username = request.POST.get('username')
|
||||
password = request.POST.get('password')
|
||||
|
||||
# django内置认证来校验登录用户
|
||||
|
||||
user = authenticate(username=username, password=password)
|
||||
|
||||
if user is not None:
|
||||
if user.is_active and user.type_t_or_s == 1:
|
||||
# 记住登录状态
|
||||
login(request, user)
|
||||
return build_response(msg='老师端登录成功')
|
||||
else:
|
||||
return build_response(code=CODE_FAILED, msg='登录失败')
|
||||
else:
|
||||
@@ -70,6 +94,8 @@ class LogoutView(APIView):
|
||||
return build_response(msg='注销成功')
|
||||
|
||||
|
||||
|
||||
|
||||
class LoginRequiredJSONMixin(LoginRequiredMixin):
|
||||
"""自定义LoginRequiredMixin
|
||||
如果用户未登录,响应JSON,且状态码为400
|
||||
@@ -78,3 +104,21 @@ class LoginRequiredJSONMixin(LoginRequiredMixin):
|
||||
def handle_no_permission(self):
|
||||
# return build_response(code=CODE_FAILED, msg='用户未登录!')
|
||||
return http.JsonResponse({'code': CODE_FAILED, 'msg': '用户未登录'})
|
||||
|
||||
class TeacherView(LoginRequiredJSONMixin,APIView):
|
||||
"""
|
||||
教师端信息展示
|
||||
"""
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
"""
|
||||
通过链接即uuid、hash获得分享的导图详情
|
||||
"""
|
||||
user = request.user
|
||||
print(user.type_t_or_s)
|
||||
if user.type_t_or_s == 2 :
|
||||
print("用户未登录或对当前页无权限")
|
||||
return build_response(code=CODE_FAILED, msg="用户未登录或对当前页无权限")
|
||||
else:
|
||||
print("用户已登录")
|
||||
return render(request, "html/jiaoshi1.html")
|
||||
Reference in New Issue
Block a user