Beispiel #1
0
def register(request):
    """注册接口"""
    cookie = request.COOKIES
    print(cookie)
    if request.method == "POST":
        # 忽略参数为空的情况
        username = request.POST.get("username", "")
        if not username:
            return JsonResponse({"error": "请输入用户名"})
        password = request.POST.get("password", "")
        phone = request.POST.get("phone", "")
        address = request.POST.get("address", "")
        email = request.POST.get("email", "")

        # 新建用户
        user = UserModel()
        user.username = username
        # 密码加密后存储
        user.password = make_password(password)
        user.phone = phone
        user.address = address
        user.email = email
        user.save()

        return JsonResponse({"user": "******"})

    return render(request, "user/register.html")
Beispiel #2
0
def regist(request):
    """注册接口"""
    cookie = request.COOKIES
    print(cookie)

    if request.method == 'POST':
        # 格式验证在前端
        username = request.POST.get('username','')
        password = request.POST.get('password','')
        phone = request.POST.get('phone','')
        address = request.POST.get('address','')
        email = request.POST.get('email','')

        # 保存到数据库
        user = UserModel()
        user.username = username
        # 密码加密后存储
        user.password = make_password(password)
        user.phone = phone
        user.address = address
        user.email = email
        user.save()
        return JsonResponse({'user':'******'})

    return render(request,'user/regist.html')
Beispiel #3
0
def register(request):
    """注册接口"""
    if request.method == 'POST':
        # 忽略参数为空
        username = request.POST.get('username', '')
        if not username:
            return JsonResponse({'error': '请输入用户名'})
        password = request.POST.get('password', '')
        phone = request.POST.get('phone', '')
        address = request.POST.get('address', '')
        email = request.POST.get('email', '')

        # 新建用户
        user = UserModel()
        user.username = username
        # 密码加密后存储
        user.password = make_password(password)
        user.phone = phone
        user.address = address
        user.email = email
        user.save()
        return HttpResponseRedirect('/account/login')
    return render(request, 'user/register.html')