Ejemplo n.º 1
0
def register_email(request):
    result = {"statu": "error","data":""}
    if request.method == "POST" and request.POST:
        username = request.POST.get("username")
        code = request.POST.get("code")
        userpass = request.POST.get("userpass")
        email = EmailValid.objects.filter(email_address = username).first()
        if email:
            if code == email.value:
                now = time.mktime(
                    datetime.datetime.now().timetuple()
                )
                db_now = time.mktime(email.times.timetuple())
                if now - db_now >= 86400:
                    result["data"] = "验证码过期"
                    email.delelt()
                else:
                    buyer = Buyer()
                    buyer.username = username
                    buyer.email = username
                    buyer.password = getPassword(userpass)
                    buyer.save()
                    result["statu"] = "success"
                    result["data"] = "恭喜!注册成功"
                    email.delete()
                    return HttpResponseRedirect("/login/")
            else:
                result["data"] = "验证码错误"
        else:
            result["data"] = "验证码不存在"
    return render(request, 'buyer/register_mail.html',locals())
Ejemplo n.º 2
0
def register(request):
    if request.method == "POST" and request.POST:
        username = request.POST.get("username")
        password = request.POST.get("userpass")
        buyer = Buyer()
        buyer.username = username
        buyer.password = getPassword(password)
        buyer.save()
        return HttpResponseRedirect("/login/")
    return render(request,'buyer/register.html')
Ejemplo n.º 3
0
def login(request):
    result = {"statue": "error","data": ""}
    if request.method == "POST" and request.POST:
        username = request.POST.get("username")
        user = Buyer.objects.filter(username = username).first()
        if user:
            password = getPassword(request.POST.get("userpass"))
            db_password = user.password
            if password == db_password:
                response = HttpResponseRedirect("/")
                response.set_cookie('user_id',user.id)
                response.set_cookie('user_name', user.username)
                request.session["username"] = user.username
                return response
            else:
                result["data"] = "密码错误"
        else:
            result["data"] = "用户名不存在"
    return render(request,'buyer/login.html',{"result":result})
Ejemplo n.º 4
0
def register(request):
    errmsg = ""
    if request.method == "POST":
        username = request.POST.get("user_name")
        pwd = request.POST.get("pwd")
        email = request.POST.get("email")
        db_email = LoginUser.objects.filter(email=email).first()
        db_username = LoginUser.objects.filter(username=username).first()
        if not db_email:
            if not db_username:
                user = LoginUser()
                user.username = username
                user.password = getPassword(pwd)
                user.email = email
                user.save()
                return HttpResponseRedirect("/Buyer/login/", locals())
            else:
                errmsg = "用户名已存在"
        else:
            errmsg = "邮箱已注册"
    return render(request, "buyer/register.html", {"errmsg": errmsg})
Ejemplo n.º 5
0
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())