This commit is contained in:
Bob 2020-08-20 22:53:57 +08:00
parent 23d2d43d3d
commit 2e8820508a
2 changed files with 45 additions and 44 deletions

View File

@ -48,6 +48,7 @@ def user_login(request):
except CaptchaStore.DoesNotExist:
messages.error(request, '验证码错误')
return HttpResponseRedirect('/login/')
print(username,password)
if username is not None and password is not None:
try:
# user = authenticate(username=username, password=password)
@ -61,7 +62,7 @@ def user_login(request):
else:
messages.error(request, '账号或密码错误,请您确认账号和密码')
except:
messages.error(request, '账号或密码错误,请您确认账号和密码')
messages.error(request, '111')
return render(request,'dashboard/login.html',{'hash_key':hash_key,'image_url':image_url})
def user_logout(request):
logout(request)

View File

@ -1,43 +1,43 @@
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.contrib.auth import get_user_model
from django.views.decorators.csrf import csrf_exempt
# Create your views here.
def index(request):
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
def polls_login(request):
if request.method == 'POST':
phone = request.POST.get('phone')
password = request.POST.get('password')
UserModel = get_user_model()
user = UserModel.objects.filter(first_name=phone).first()
if not user:
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
u = authenticate(request, username=user.username, password=password)
if u is not None:
login(request, u)
print(u)
result = dict()
return JsonResponse(result)
else:
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
else:
return JsonResponse({})
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.contrib.auth import get_user_model, authenticate, login
from django.views.decorators.csrf import csrf_exempt
# Create your views here.
def index(request):
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
def polls_login(request):
if request.method == 'POST':
phone = request.POST.get('phone')
password = request.POST.get('password')
UserModel = get_user_model()
user = UserModel.objects.filter(first_name=phone).first()
if not user:
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
u = authenticate(request, username=user.username, password=password)
if u is not None:
login(request, u)
print(u)
result = dict()
return JsonResponse(result)
else:
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
else:
return JsonResponse({})