| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from django.core.checks import Critical, register |
| 4 |
|
| 5 |
|
| 6 |
@register() |
| 7 |
def settings_check(app_configs, **kwargs) -> list: |
| 8 |
from allauth.account import app_settings as account_settings |
| 9 |
from allauth.mfa import app_settings |
| 10 |
from allauth.mfa.models import Authenticator |
| 11 |
|
| 12 |
ret = [] |
| 13 |
if app_settings.PASSKEY_SIGNUP_ENABLED: |
| 14 |
if Authenticator.Type.WEBAUTHN not in app_settings.SUPPORTED_TYPES: |
| 15 |
ret.append( |
| 16 |
Critical( |
| 17 |
msg="MFA_PASSKEY_SIGNUP_ENABLED requires MFA_SUPPORTED_TYPES to include 'webauthn'" |
| 18 |
) |
| 19 |
) |
| 20 |
if not account_settings.EMAIL_VERIFICATION_BY_CODE_ENABLED: |
| 21 |
# The fact that a signup is passkey based is stored in the session, |
| 22 |
# which gets lost when using link based verification. |
| 23 |
ret.append( |
| 24 |
Critical( |
| 25 |
msg="MFA_PASSKEY_SIGNUP_ENABLED requires ACCOUNT_EMAIL_VERIFICATION_BY_CODE_ENABLED" |
| 26 |
) |
| 27 |
) |
| 28 |
email_required = account_settings.SIGNUP_FIELDS.get("email", {}).get("required") |
| 29 |
if not email_required: |
| 30 |
ret.append( |
| 31 |
Critical( |
| 32 |
msg="MFA_PASSKEY_SIGNUP_ENABLED requires ACCOUNT_SIGNUP_FIELDS to contain 'email*'" |
| 33 |
) |
| 34 |
) |
| 35 |
if ( |
| 36 |
account_settings.EMAIL_VERIFICATION |
| 37 |
!= account_settings.EmailVerificationMethod.MANDATORY |
| 38 |
): |
| 39 |
ret.append( |
| 40 |
Critical( |
| 41 |
msg="MFA_PASSKEY_SIGNUP_ENABLED requires ACCOUNT_EMAIL_VERIFICATION = 'mandatory'" |
| 42 |
) |
| 43 |
) |
| 44 |
return ret |