B
B
BogBel2015-11-19 12:42:06
Django
BogBel, 2015-11-19 12:42:06

How to make field user.is_active = True by default(django-registration-redux)?

Continuing my topic about registering for Django.
I redefined my form and now it looks like this

class RegistrationForm(RegistrationFormUniqueEmail):
    first_name = forms.CharField(label=u"First Name", required=True)
    last_name = forms.CharField(label=u"Last Name", required=True)
    username = forms.CharField(label=None)
    email = forms.CharField(label=None)
    password1 = forms.CharField(label="Password", widget=forms.PasswordInput)
    password2 = forms.CharField(label="Password confirmation", widget=forms.PasswordInput)

    def save(self, profile_callback=None):
        new_user = User.objects.create_user(username=self.cleaned_data['username'],
                                            password=self.cleaned_data['password1'],
                                            email=self.cleaned_data['email'],
                                            first_name=self.cleaned_data['first_name'],
                                            last_name=self.cleaned_data['last_name'],
                                            )

        new_user.is_active = True
        new_user.save()
        g = Group.objects.get(name='users')
        g.user_set.add(new_user)
        
        return new_user

In this form, I also add the user to the previously created Group users.
So.
Wrote a template, url.
I go to / register / enter my data, send it to the server. Registration completed.
But I'm looking at the database, and my user's is_active field = 0
Then I noticed.
If I write something in save() that throws an exception (for example, print 1/0), then I get an error, but the user is added to the database and is_active = 1
This is so, an interesting fact.
But in fact, I want to get advice on how to make a user active right away, without confirmation by email?
I enter the requested data

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2015-11-19
@deliro

new_user = User.objects.create_user(username=self.cleaned_data['username'],
                                            password=self.cleaned_data['password1'],
                                            email=self.cleaned_data['email'],
                                            first_name=self.cleaned_data['first_name'],
                                            last_name=self.cleaned_data['last_name'],
                                            )

        new_user.is_active = True
        new_user.save()

Replaced by
new_user = User.objects.create_user(username=self.cleaned_data['username'],
                                            password=self.cleaned_data['password1'],
                                            email=self.cleaned_data['email'],
                                            first_name=self.cleaned_data['first_name'],
                                            last_name=self.cleaned_data['last_name'],
                                            is_active=True,
                                            )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question