#view
This commit is contained in:
parent
23d2d43d3d
commit
2e8820508a
|
@ -48,6 +48,7 @@ def user_login(request):
|
||||||
except CaptchaStore.DoesNotExist:
|
except CaptchaStore.DoesNotExist:
|
||||||
messages.error(request, '验证码错误')
|
messages.error(request, '验证码错误')
|
||||||
return HttpResponseRedirect('/login/')
|
return HttpResponseRedirect('/login/')
|
||||||
|
print(username,password)
|
||||||
if username is not None and password is not None:
|
if username is not None and password is not None:
|
||||||
try:
|
try:
|
||||||
# user = authenticate(username=username, password=password)
|
# user = authenticate(username=username, password=password)
|
||||||
|
@ -61,7 +62,7 @@ def user_login(request):
|
||||||
else:
|
else:
|
||||||
messages.error(request, '账号或密码错误,请您确认账号和密码')
|
messages.error(request, '账号或密码错误,请您确认账号和密码')
|
||||||
except:
|
except:
|
||||||
messages.error(request, '账号或密码错误,请您确认账号和密码')
|
messages.error(request, '111')
|
||||||
return render(request,'dashboard/login.html',{'hash_key':hash_key,'image_url':image_url})
|
return render(request,'dashboard/login.html',{'hash_key':hash_key,'image_url':image_url})
|
||||||
def user_logout(request):
|
def user_logout(request):
|
||||||
logout(request)
|
logout(request)
|
||||||
|
|
|
@ -1,43 +1,43 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponse, JsonResponse
|
from django.http import HttpResponse, JsonResponse
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model, authenticate, login
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
username = request.GET.get('username')
|
username = request.GET.get('username')
|
||||||
password = request.GET.get('password')
|
password = request.GET.get('password')
|
||||||
print(username, password)
|
print(username, password)
|
||||||
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
|
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
|
||||||
|
|
||||||
|
|
||||||
def status_500(request):
|
def status_500(request):
|
||||||
return HttpResponse(status=500)
|
return HttpResponse(status=500)
|
||||||
|
|
||||||
|
|
||||||
def status_401(request):
|
def status_401(request):
|
||||||
return HttpResponse(status=401)
|
return HttpResponse(status=401)
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def polls_login(request):
|
def polls_login(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
phone = request.POST.get('phone')
|
phone = request.POST.get('phone')
|
||||||
password = request.POST.get('password')
|
password = request.POST.get('password')
|
||||||
UserModel = get_user_model()
|
UserModel = get_user_model()
|
||||||
user = UserModel.objects.filter(first_name=phone).first()
|
user = UserModel.objects.filter(first_name=phone).first()
|
||||||
if not user:
|
if not user:
|
||||||
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
|
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
|
||||||
|
|
||||||
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)
|
||||||
print(u)
|
print(u)
|
||||||
result = dict()
|
result = dict()
|
||||||
return JsonResponse(result)
|
return JsonResponse(result)
|
||||||
else:
|
else:
|
||||||
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
|
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
|
||||||
else:
|
else:
|
||||||
return JsonResponse({})
|
return JsonResponse({})
|
||||||
|
|
Loading…
Reference in New Issue