Exemplo n.º 1
0
def register(request):
    """ 注册 """
    if request.method == 'GET':
        form = RegisterModelForm()
        return render(request, 'register.html', {'form': form})

    form = RegisterModelForm(data=request.POST)
    if form.is_valid():
        # 验证通过,写入数据库(密码要是密文)
        # instance = form.save,在数据库中新增一条数据,并将新增的这条数据赋值给instance
        form.save()

        # 用户表中新建一条数据(注册)
        instance = form.save()

        # 创建交易记录
        policy_object = models.PricePolicy.objects.filter(
            category=1, title="个人免费版").first()
        models.Transaction.objects.create(
            status=2,
            order=str(uuid.uuid4()),
            user=instance,
            price_policy=policy_object,
            count=0,
            price=0,
            start_datetime=datetime.datetime.now())

        return JsonResponse({'status': True, 'data': '/login/'})

    return JsonResponse({'status': False, 'error': form.errors})
Exemplo n.º 2
0
 def post(self, request, *args, **kwargs):
     form = RegisterModelForm(data=request.POST)
     if form.is_valid():
         #验证通过,写入数据库,(密码应该是密文)
         instance = form.save()
         """  在交易记录表生成对应的交易信息  """
         price_object = models.PricePoliy.objects.filter(
             category=1, title='个人免费版').first()
         models.Transaction.objects.create(
             status=2,
             order=uuid.uuid4(),  #根据当前时间和当前计算机的网卡计算的随机字符串
             user=instance,
             price_poliy=price_object,
             count=0,
             price=0,
             start_datetime=datetime.datetime.now(),
         )
         return JsonResponse({'status': True, 'url': '/login/'})
     else:
         return JsonResponse({'status': False, 'error': form.errors})
Exemplo n.º 3
0
def register(request):
    """注册"""
    if request.method == 'GET':
        print(123)
        form = RegisterModelForm()
        return render(request, 'web/register.html', {'form': form})
    if request.method == 'POST':
        # 实例化modelform表单,对每个注册字段进行校验
        form = RegisterModelForm(data=request.POST)
        if form.is_valid():
            # 验证通过,写入数据库,通过form.save(),将model模型中定义的字段写入数据库,modelform中其他的字段丢弃,如code等
            # 密码必须是加密的
            instance = form.save()
            price_policy_obj = models.PricePolicy.objects.filter(
                category=1, title='个人免费版').first()
            # 创建一条交易记录
            models.Transaction.objects.create(
                status=2,
                order=str(uuid.uuid4()),
                user=instance,
                price_policy=price_policy_obj,
                count=0,
                price=0,
                start_datetime=datetime.datetime.now())
            return JsonResponse({'status': True, 'data': '/login/'})
        else:
            return JsonResponse({'status': False, 'error': form.errors})
Exemplo n.º 4
0
def register(request):
    if request.method == "GET":
        form = RegisterModelForm()
        return render(request, "register.html", {"form": form})

    form = RegisterModelForm(request.POST)
    if form.is_valid():
        # print(form.cleaned_data)
        # 通过验证,数据写入(用户表中插入一条数据)
        instance = form.save()
        # 创建免费的交易记录
        policy_obj = models.PricePolicy.objects.filter(category=1,
                                                       title="个人免费版").first()
        models.Transaction.objects.create(
            status=2,
            order=str(uuid.uuid4()),
            user=instance,
            count=0,
            price=0,
            price_policy=policy_obj,
            start_datetime=arrow.now().format(),
        )
        return JsonResponse({"status": True, "data": "/login/"})

    return JsonResponse({"status": False, "error": form.errors})
Exemplo n.º 5
0
def register(request):
    """注册"""
    if request.method == "GET":
        form = RegisterModelForm()
        return render(request, 'register.html', {'form': form})
    form = RegisterModelForm(data=request.POST)
    if form.is_valid():
        # 验证通过,写入数据库(数据库密码要是密文)
        # 通过form.save()来保存,会自动把数据库中没有的字段去除,create会将所有的字段都提交到数据库,会报错。
        # form.save()  # 用户表新建一条数据(注册)
        instance = form.save(
        )  # 相当于instance=models.UserInfo.objects.create(**form.cleaned_data)
        # 创建交易记录
        # 方式1:免费额度存储在交易记录中
        # 对应中间件auth.py 方式1
        policy_object = models.PricePolicy.objects.filter(
            category=1, title="个人免费版").first()
        models.Transaction.objects.create(
            status=2,
            order=str(uuid.uuid4()),
            user=instance,
            price_policy=policy_object,
            count=0,
            price=0,
            start_datetime=datetime.datetime.now(),
        )

        # 方式二 对应auth.py 方式2 ,方式2在这里什么都不写,把方式1全部注释即可.

        return JsonResponse({'status': True, 'data': '/login/'})
    return JsonResponse({'status': False, 'error': form.errors})
Exemplo n.º 6
0
def register(request):
    if request.method == 'GET':
        form = RegisterModelForm()
        return render(request, 'register.html', {'form': form})

    form = RegisterModelForm(data=request.POST)
    if form.is_valid():
        # write into DB (password should be encrypted)
        form.save()
        return JsonResponse({'status': True, 'data': '/login/'})
    return JsonResponse({'status': False, 'error': form.errors})
Exemplo n.º 7
0
def register(request):
    """注册"""
    if request.method == 'GET':
        form = RegisterModelForm()
        return render(request, 'register.html', {'form': form})
    form = RegisterModelForm(data=request.POST)
    if form.is_valid():
        # 验证通过  写入数据库(密码要是密文)
        # form.instance.password = "******"
        form.save()  # 会自动剔除数据库中没用的字段
        # instance = models.UserInfo.objects.create(**form.cleaned_data) #和上面的是一样的但是要手动剔除字典中的数据 pop
        return JsonResponse({'status': True, 'data': '/login/sms/'})
    return JsonResponse({'status': False, 'error': form.errors})
Exemplo n.º 8
0
def register(request):
    '''注册'''
    if request.method == 'GET':
        form = RegisterModelForm()
        return render(request, 'web/register.html', {'form': form})

    form = RegisterModelForm(data=request.POST)
    if form.is_valid():
        #验证通过,写入数据库,form.save()比较简单,自动剔除表单中有但是数据库中没有的字段
        #密码要是密文
        form.save()
        return JsonResponse({'status': True, 'data': "/login/"})

    return JsonResponse({'status': False, 'error': form.errors})
Exemplo n.º 9
0
def register(request):
    if request.method == 'GET':
        form = RegisterModelForm()
        return render(request, 'register.html', {'form': form})
    form = RegisterModelForm(data=request.POST)
    if form.is_valid():
        # 验证通过,写入数据库(密码要是密文)
        # instance = form.save,在数据库中新增一条数据,并将新增的这条数据赋值给instance
        # 用户表中新建一条数据(注册)
        form.instance.isvip = False
        form.save()
        # 创建交易记录
        return JsonResponse({'status': True, 'data': '/login/'})
    return JsonResponse({'status': False, 'error': form.errors})
Exemplo n.º 10
0
Arquivo: views.py Projeto: wmyzzz/blog
def register(request):
    """注册"""
    if request.method == "GET":
        form = RegisterModelForm()
        return render(request, "register.html", {'form': form})
    form = RegisterModelForm(request.POST)
    if form.is_valid():
        instance = form.save()
        print("存入数据库")
        return JsonResponse({'status': True, 'data': '/login/'})
    return JsonResponse({'status': False, 'error': form.errors})
Exemplo n.º 11
0
def register(request):
    """ 注册 """
    if request.method == 'GET':
        form = RegisterModelForm()
        return render(request, 'register.html', {'form': form})

    form = RegisterModelForm(data=request.POST)
    if form.is_valid():
        # 验证通过,写入数据库(密码要使用密文存储)
        # data = form.cleaned_data
        # data.pop('code')
        # data.pop('confirm_password')
        # instance = models.UserInfo.objects.create(**data)

        # save()方法只会将ModelForm中定义的字段存入数据库,自动去除code和confirm_password
        # 用户表中新建一条数据(注册)
        form.save()
        return JsonResponse({'status': True, 'data': '/login/'})

    return JsonResponse({'status': False, 'error': form.errors})
Exemplo n.º 12
0
def register(request):
    if request.method == 'GET':
        form = RegisterModelForm()
        return render(request, 'register.html', {'form': form})
    form = RegisterModelForm(data=request.POST)
    if form.is_valid():
        # 验证通过,密码保存为密文
        instance = form.save()
        # 创建交易记录
        policy_object = models.PricePolicy.objects.filter(
            category=1, title='个人免费版').first()
        models.Transaction.objects.create(status=2,
                                          user=instance,
                                          price_policy=policy_object,
                                          count=0,
                                          price=0,
                                          start_time=datetime.datetime.now(),
                                          order=str(uuid.uuid4()))
        # instance = models.UserInfo.objects.create(**form.cleaned_data),如果这么写需要移除没有用的字段
        return JsonResponse({'status': True, 'data': '/login/'})

    return JsonResponse({'status': False, 'error': form.errors})
Exemplo n.º 13
0
 def get(self, request, *args, **kwargs):
     form = RegisterModelForm()
     return render(request, 'register.html', {'form': form})
Exemplo n.º 14
0
def register(request):
    """注册"""
    form = RegisterModelForm()
    return render(request, 'web/register.html', {'form': form})
Exemplo n.º 15
0
def register(request):
    form = RegisterModelForm()
    return render(request, 'register.html', {'form': form})