示例#1
0
def reg(request):
    form_obj = RegForm()
    if request.method == 'POST':
        form_obj = RegForm(request.POST)
        if form_obj.is_valid():
            form_obj.cleaned_data.pop('re_password')
            models.UserProfile.objects.create_user(**form_obj.cleaned_data)
            return redirect('/login/')
    return render(request, 'crm/login_reg/reg.html', {'form_obj': form_obj})
示例#2
0
 def post(self, request):
     form_obj = RegForm(request.POST)
     if form_obj.is_valid():
         #二选一,上面是自定义保存的,下面是自己保存自动踢出多余数据
         # form_obj.cleaned_data.pop('re_password')
         # models.UserProfile.objects.create(**form_obj.cleaned_data)
         form_obj.save()
         return redirect('/crm/login/')
     print(form_obj.errors)
     return render(request, "new_register.html", {"form_obj": form_obj})
示例#3
0
def register(request):
    form_obj = RegForm()
    if request.method == 'POST':
        # 校验参数
        form_obj = RegForm(request.POST)
        if form_obj.is_valid():
            # 创建新用户
            form_obj.cleaned_data.pop('re_password')
            models.UserProfile.objects.create_user(**form_obj.cleaned_data)

            # 方法二 form_obj.save()就能完成注册但是密码是明文,接受返回值单独设置密码
            # obj = form_obj.save()
            # obj.set_password(obj.password)
            # obj.save()

            return redirect('/login/')

    return render(request, 'reg.html', {'form_obj': form_obj})
示例#4
0
文件: views.py 项目: q18688062/CRM
def register(request):
    form_obj = RegForm()
    if request.method == 'POST':
        form_obj = RegForm(request.POST)
        if form_obj.is_valid():
            form_obj.save()
            return redirect(reverse('login'))
    return render(request, 'reg.html', {'form_obj': form_obj})
示例#5
0
def register(request):
    reg_obj = RegForm()

    if request.method == 'POST':
        reg_obj = RegForm(request.POST)
        if reg_obj.is_valid():
            print(reg_obj.cleaned_data)  # 需要手动删除 re_password键
            reg_obj.save()  # 直接保存
            return redirect('crm:login')

    return render(request, 'register.html', {'reg_obj': reg_obj})
示例#6
0
def reg(request):
    form_obj = RegForm()
    if request.method == 'POST':
        form_obj = RegForm(request.POST)
        if form_obj.is_valid():
            obj = form_obj.save()
            models.Department.objects.filter(pk=obj.department.pk).update(count=F('count') + 1)
            return redirect(reverse('login'))
    return render(request, 'reg.html', {'form_obj': form_obj})
示例#7
0
def register(request):
    if request.method == 'POST':
        form_obj = RegForm(request.POST)
        # print(form_obj)
        if form_obj.is_valid():
            form_obj.save()
            # print(form_obj.is_valid())
            return redirect(reverse('login'))
        # print(">>>>",form_obj.is_valid())
        return render(request, 'register.html', {'form_obj': form_obj})
    else:
        form_obj = RegForm()
    return render(request, 'register.html', {'form_obj': form_obj})
示例#8
0
def reg(request):
    form_obj = RegForm()
    if request.method == 'POST':
        form_obj = RegForm(request.POST)
        if form_obj.is_valid():
            # 写入到数据库中
            # form_obj.cleaned_data.pop('re_password')
            # obj = models.UserProfile.objects.create(**form_obj.cleaned_data)
            # print(obj)
            form_obj.save()
            return redirect('/login/')

    return render(request, 'reg.html', {'form_obj': form_obj})
示例#9
0
def reg(request):
    form_obj = RegForm()
    if request.method == 'POST':
        # 把提交的数据交给form进行校验
        form_obj = RegForm(request.POST)
        if form_obj.is_valid():
            # 所有数据通过校验   保存到数据库
            # form_obj.cleaned_data.pop('re_password')
            # models.UserProfile.objects.create(**form_obj.cleaned_data)
            form_obj.save()
            return redirect('/crm/login/')

    return render(request, 'reg.html', {'form_obj': form_obj})
示例#10
0
def reg(request):
    form_obj = RegForm()
    if request.method == 'POST':
        form_obj = RegForm(request.POST)
        if form_obj.is_valid():
            # 插入到数据库
            # print(form_obj.cleaned_data)
            # form_obj.cleaned_data.pop('re_pwd')
            # models.UserProfile.objects.create(**form_obj.cleaned_data)
            form_obj.save()
            return redirect(reverse('login'))

    return render(request, 'reg.html', {'form_obj': form_obj})
示例#11
0
def reg(request):
    form_obj = RegForm()
    if request.method == 'POST':
        form_obj = RegForm(request.POST)
        if form_obj.is_valid():
            # 创建新用户
            obj = form_obj.save()
            obj.set_password(obj.password)
            obj.save()
            return redirect('/login/')
    return render(request, 'reg.html', {'form_obj': form_obj})
示例#12
0
def reg(request):
    form_obj = RegForm()
    if request.method == 'POST':
        form_obj = RegForm(request.POST)
        if form_obj.is_valid():
            # form_obj.cleaned_data.pop('re_password')
            # models.UserProfile.objects.create_user(**form_obj.cleaned_data)
            # return redirect('/login/')
            obj = form_obj.save()
            obj.set_password(obj.password)
            obj.save()
            return redirect('/login/')
    return render(request, 'reg.html', {'form_obj': form_obj})
示例#13
0
def reg(request):
    form_obj = RegForm()
    if request.method == 'POST':
        form_obj = RegForm(request.POST)
        if form_obj.is_valid():  # 校验数据是否符合UserProfile中字段的格式要求
            # print(form_obj.cleaned_data)
            # 写入到数据库中
            # form_obj.cleaned_data.pop('re_password')
            # obj = models.UserProfile.objects.create(**form_obj.cleaned_data)
            # print(obj)
            form_obj.save()
            # print(form_obj.cleaned_data)  # 字典 字段名对应数据
            user_obj = models.UserProfile.objects.filter(username=form_obj.cleaned_data['username']).first()
            request.session['user_id'] = user_obj.pk
            # print(request.session['user_id'])
            return redirect(reverse('index'))

    return render(request, 'reg.html', {'form_obj': form_obj})
示例#14
0
def reg(request):
    # 1. 实例化RegForm
    form_obj = RegForm()

    if request.method == 'POST':
        # 2. 将post请求提交的数据交给RegForm重新实例化
        form_obj = RegForm(request.POST)
        # 3. 如果form组件校验成功
        if form_obj.is_valid():
            """
            # 插入到数据库
            # print(form_obj.cleaned_data)
            # form_obj.cleaned_data.pop('re_pwd')
            # models.UserProfile.objects.create(**form_obj.cleaned_data)
            """
            # 3.1 将校验成功的数据保存到数据库中
            form_obj.save()
            # 3.2 跳转到登录页面进行登录
            return redirect(reverse('login'))

    return render(request, 'reg.html', {'form_obj': form_obj})
示例#15
0
文件: sales.py 项目: Dream-thorn/CRM
def reg(request):
    reg_obj = RegForm()

    if request.method == 'POST':
        reg_obj = RegForm(request.POST)
        if reg_obj.is_valid():
            # 成功通过校验, 创建新用户

            # 方案一
            # reg_obj.cleaned_data.pop('re_password')
            # models.UserProfile.objects.create_user(**reg_obj.cleaned_data)

            # 方案二
            obj = reg_obj.save()  # 相当于使用create方法创建, 所以密码是明文
            obj.set_password(obj.password)  # 将密码重新设置为密文
            obj.save()

            return redirect('/login/')

    return render(request, 'reg.html', {'reg_obj': reg_obj})
示例#16
0
 def get(self, request):
     form_obj = RegForm()
     context = {}
     context['form_obj'] = form_obj
     return render(request, "new_register.html", context)