예제 #1
0
def register(request):
    if request.method == "POST":
        username = request.POST.get("user_name")
        password = request.POST.get("pwd")
        email = request.POST.get("email")

        buyer = Buyer()
        buyer.username = username
        buyer.password = set_password(password)
        buyer.email = email
        buyer.save()

        return HttpResponseRedirect("/Buyer/login/")
    return render(request, "buyer/register.html")
예제 #2
0
def login(request):
    if request.method == "POST":
        username = request.POST.get("username")
        password = request.POST.get("pwd")
        if username and password:
            user = Buyer.objects.filter(username=username).first()
            if user:
                web_password = set_password(password)
                if user.password == web_password:
                    response = HttpResponseRedirect("/Buyer/index/")
                    response.set_cookie("username", user.username)
                    request.session["username"] = user.username
                    response.set_cookie("user_id", user.id)
                    return response
    return render(request, "buyer/login.html")