示例#1
0
def register(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            #form.setdefault('is_staff', True)
            form.is_superuser = True
            form.is_active = True
            form.is_staff = True
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            if user is not None:

                if user.is_active:
                    login(request,user)
                    return redirect('/home')
                    return HttpResponse("login successful")
                else:
                    return HttpResponse("disabled account")
            else:
                return HttpResponse("invalid login")

            #login(request, user)
            
    else:
        form = SignUpForm()

    return render(request, 'account/index3.html', {'form': form})