Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(headless): Allow for INPUTS customizations via settings #4026

Conversation

mecampbellsoup
Copy link
Contributor

Submitting Pull Requests

General

  • Make sure you use semantic commit messages.
    Examples: "fix(google): Fixed foobar bug", "feat(accounts): Added foobar feature".
  • All Python code must formatted using Black, and clean from pep8 and isort issues.
  • JavaScript code should adhere to StandardJS.
  • If your changes are significant, please update ChangeLog.rst.
  • If your change is substantial, feel free to add yourself to AUTHORS.

Provider Specifics

In case you add a new provider:

  • Make sure unit tests are available.
  • Add an entry of your provider in test_settings.py::INSTALLED_APPS and docs/installation.rst::INSTALLED_APPS.
  • Add documentation to docs/providers/<provider name>.rst and docs/providers/index.rst Provider Specifics toctree.
  • Add an entry to the list of supported providers over at docs/overview.rst.

@@ -27,6 +27,10 @@ def TOKEN_STRATEGY(self):
def FRONTEND_URLS(self):
return self._setting("FRONTEND_URLS", {})

@property
def INPUTS(self):
return self._setting("INPUTS", {})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These class overrides need to inherit from allauth.headless.inputs, we can document that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an example I'm using locally:

from allauth.headless.account.inputs import RequestPasswordResetInput
from django.http import HttpRequest

from cloud_console.django.apps.webauth.models import User


class RequestPasswordResetInput(RequestPasswordResetInput):
    def save(self, request: HttpRequest, **kwargs):
        # Only users w/ passwords can request to reset their password
        if self.users:
            email = self.cleaned_data["email"]
            try:
                user = User.objects.get(email=email)
            except User.DoesNotExist:
                return email
            else:
                if not user.has_usable_password():
                    return email
        return super().save(request, **kwargs)

Here is how I configure my settings:

HEADLESS_INPUTS = {
    "reset_password": "cloud_console.django.apps.webauth.inputs.RequestPasswordResetInput"
}

@coveralls
Copy link

coveralls commented Aug 12, 2024

Coverage Status

coverage: 95.827% (+0.002%) from 95.825%
when pulling fca5686 on mecampbellsoup:mc/headless/inputs-customizations
into ef8743c on pennersr:main.

@mecampbellsoup mecampbellsoup force-pushed the mc/headless/inputs-customizations branch from 18ccecd to fca5686 Compare August 12, 2024 20:33
@pennersr
Copy link
Owner

Closing -- as mentioned, headless inputs are just a private implementation detail that is best not exposed publically.

@pennersr pennersr closed this Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants