add polls
This commit is contained in:
parent
3659ffeff7
commit
b031dab5c5
|
@ -3,4 +3,5 @@
|
||||||
.media/
|
.media/
|
||||||
*/__pycache__/
|
*/__pycache__/
|
||||||
*/*.pyc
|
*/*.pyc
|
||||||
|
*/migrations
|
||||||
NewMediaMonitoring/local_settings.py
|
NewMediaMonitoring/local_settings.py
|
|
@ -4,5 +4,7 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
path('', views.index, name='index'),
|
||||||
|
path('status_500', views.status_500, name='status_500'),
|
||||||
|
path('status_401', views.status_401, name='status_401'),
|
||||||
path('login', views.polls_login, name='polls_login'),
|
path('login', views.polls_login, name='polls_login'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,14 +1,24 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse, JsonResponse
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django_token.models import Token
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
return HttpResponse("Hello, world. You're at the polls index.")
|
username = request.GET.get('username')
|
||||||
|
password = request.GET.get('password')
|
||||||
|
print(username, password)
|
||||||
|
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
|
||||||
|
|
||||||
|
|
||||||
|
def status_500(request):
|
||||||
|
return HttpResponse(status=500)
|
||||||
|
|
||||||
|
|
||||||
|
def status_401(request):
|
||||||
|
return HttpResponse(status=401)
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
@ -24,22 +34,8 @@ def polls_login(request):
|
||||||
u = authenticate(request, username=user.username, password=password)
|
u = authenticate(request, username=user.username, password=password)
|
||||||
if u is not None:
|
if u is not None:
|
||||||
login(request, u)
|
login(request, u)
|
||||||
token = Token.objects.create(user=myuser)
|
print(u)
|
||||||
|
|
||||||
result = dict()
|
result = dict()
|
||||||
result['id'] = user.id
|
|
||||||
result['username'] = user.username
|
|
||||||
result['email'] = user.email
|
|
||||||
result['role'] = ','.join(roles)
|
|
||||||
if teacher:
|
|
||||||
school = teacher.school.title
|
|
||||||
r = get_region(school)
|
|
||||||
if r:
|
|
||||||
result['regionId'] = r[0]
|
|
||||||
result['regionName'] = r[1]
|
|
||||||
result['unitId'] = r[2]
|
|
||||||
result['unitName'] = r[3]
|
|
||||||
result['teacher'] = {'name': teacher.name, 'school': school}
|
|
||||||
return JsonResponse(result)
|
return JsonResponse(result)
|
||||||
else:
|
else:
|
||||||
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
|
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
|
||||||
|
|
Loading…
Reference in New Issue