from django.http import HttpResponse
from django.shortcuts import render

from apps.account.models import Account


# Create your views here.
def login(request):
    #
    return render(request, "login1.html")


def submit(request):
    if request.method == 'POST':
        # 从前端数据中拿去表中字段
        user_name = request.POST.get('email')
        user_password = request.POST.get('password')
        # user_password_confirm = request.POST.get('user_password_confirm')
        # 根据用户名查询数据库，并获得用户
        user_obj = Account.objects.filter(user_name=user_name).first()
        if user_obj.user_name == user_name and user_obj.user_password == user_password and user_obj.user_password_confirm == user_password_confirm:
            return HttpResponse("登录成功")
        else:
            return HttpResponse("登录失败")
    else:
        return HttpResponse("登录失败")
