julianwachholz / django-guest-user

A Django app that allows visitors to interact with your site as a guest user without requiring registration.
https://django-guest-user.readthedocs.io/
MIT License
74 stars 10 forks source link

Using django-guest-user with allauth #14

Open lchen198 opened 3 months ago

lchen198 commented 3 months ago

I recently discovered django-guest-user as an updated version of the django lazy user library. I'd love to see more documentation about integrating with allauth.

I have a customized signup form inherited from the allauth.account.forms.SignupForm and a customized User model.

My sign up form doesn't work with django-guest-user as it expects a UserCreationForm to convert a guest user to a real user.

The difference is that the allauth SignupForm's save function needs a request parameter that the django-guest-user view doesn't provide.

My solution is to create a new form and copy all the existing sign up fields over.

class GuestUserSignupForm(UserCreationForm):
    class Meta:
        model = User
        fields = ["username", "password1", "password2", ...]
    first_name = forms.CharField(max_length=30, label=_("First Name"))
    last_name = forms.CharField(max_length=30, label=_("Last Name"))
    #  other user signup fields ...

I wonder if there's better way to implement this.