def login(request):
    if (request.method == 'POST'):
        erremail = ''
        email = request.POST.get('email')
        pwd = request.POST.get('pwd')
        user = LoginUser.objects.filter(email=email).first()
        if user:
            db_password = user.password
            pwd = getPassword(pwd)
            if (db_password == pwd):
                response = HttpResponseRedirect('/Buyer/index/', locals())
                response.set_cookie('user', user.email)
                response.set_cookie('user_id', user.id)
                response.set_cookie('username', urlquote(user.username))
                request.session['user'] = user.email
                return response
            else:
                errpwd = '密码不匹配'
        else:
            erremail = '该邮箱未注册'
    return render(request, 'buyer/login.html', locals())
def login(request):
    if (request.method == 'POST'):
        erremail = 
        email = request.POST.get('email')
        pwd = request.POST.get('pwd')
        user = LoginUser.objects.filter(email=email).first()
        if user:
            db_password = user.password
            pwd = getPassword(pwd)
            if (db_password == pwd):
                response = HttpResponseRedirect('/Buyer/index/', locals())
                response.set_cookie('user', user.email)
                response.set_cookie('user_id', user.id)
                response.set_cookie('username', urlquote(user.username))
                request.session['user'] = user.email
                return response
            else:
                errpwd = '密码不匹配'
        else:
            erremail = '该邮箱未注册'
    return render(request, 'buyer/login.html', locals())