I need help implementing django-recapcha in a Django project that has a custom user and also has django-allauth.
When I first set up this project I set up a custom user, as it is the recommendation from the official Django site.(https://docs.djangoproject.com/en/4.0/topics/auth/customizing/#using-a-custom-user-model-when-starting-a-project).
After that I implemented django-allauth for authentication.
Now I want to implement django-recapctha and I haven't found the right way to do it. I don't know how I should configure the forms.py file, because I don't understand well what is happening with this combination of custom user and django-allauth. Which is the form I should edit to configure django-recapcha and from which app?
When I configured the custom user I did it as follows:
I created an app called accounts.
I created accounts/models.py with the following code:
from django.contrib.auth.models import AbstractUser
from django.db import models
class CustomUser(AbstractUser):
profile_pic = models.ImageField(default='default.jpg', upload_to='profile_pics')
I created accounts/forms.py with the following code:
from django.contrib.auth import get_user_model
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
class CustomUserCreationForm(UserCreationForm):
class Meta:
model = get_user_model()
fields = (
'email',
'username',
)
class CustomUserChangeForm(UserChangeForm):
class Meta:
model = get_user_model()
fields = (
'email',
'username',
)
Then I added the following to settings.py:
AUTH_USER_MODEL = 'accounts.CustomUser'
The django-recaptcha instructions indicate that I need to add a ReCaptchaField to a form:
Instructions at https://pypi.org/project/django-recaptcha/#installation
from django import forms
from captcha.fields import ReCaptchaField
class FormWithCaptcha(forms.Form):
captcha = ReCaptchaField()
But I don't know in which part of the project I should do it. I don't know if it is correct to do it in the forms.py file of the accounts app, where I defined the CustomUserCreationForm, or should I override the django-allauth Signup form? and if this is the case where I do it? in the accounts app where I configured the custom user model or elsewhere?
I really would appreciate any help or guidance on how to move forward with this.