| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.account.forms import BaseSignupForm |
| 4 |
from allauth.headless.internal.restkit import inputs |
| 5 |
from allauth.mfa.base.forms import AuthenticateForm |
| 6 |
from allauth.mfa.models import Authenticator |
| 7 |
from allauth.mfa.recovery_codes.forms import GenerateRecoveryCodesForm |
| 8 |
from allauth.mfa.totp.forms import ActivateTOTPForm |
| 9 |
from allauth.mfa.webauthn.forms import ( |
| 10 |
AddWebAuthnForm, |
| 11 |
AuthenticateWebAuthnForm, |
| 12 |
LoginWebAuthnForm, |
| 13 |
ReauthenticateWebAuthnForm, |
| 14 |
SignupWebAuthnForm, |
| 15 |
) |
| 16 |
|
| 17 |
|
| 18 |
class AuthenticateInput(AuthenticateForm, inputs.Input): |
| 19 |
pass |
| 20 |
|
| 21 |
|
| 22 |
class ActivateTOTPInput(ActivateTOTPForm, inputs.Input): |
| 23 |
pass |
| 24 |
|
| 25 |
|
| 26 |
class GenerateRecoveryCodesInput(GenerateRecoveryCodesForm, inputs.Input): |
| 27 |
pass |
| 28 |
|
| 29 |
|
| 30 |
class AddWebAuthnInput(AddWebAuthnForm, inputs.Input): |
| 31 |
pass |
| 32 |
|
| 33 |
|
| 34 |
class CreateWebAuthnInput(SignupWebAuthnForm, inputs.Input): |
| 35 |
pass |
| 36 |
|
| 37 |
|
| 38 |
class UpdateWebAuthnInput(inputs.Input): |
| 39 |
id = inputs.ModelChoiceField(queryset=Authenticator.objects.none()) |
| 40 |
name = inputs.CharField(required=True, max_length=100) |
| 41 |
|
| 42 |
def __init__(self, *args, **kwargs) -> None: |
| 43 |
self.user = kwargs.pop("user") |
| 44 |
super().__init__(*args, **kwargs) |
| 45 |
id_field: inputs.ModelChoiceField = self.fields["id"] # type: ignore[assignment] |
| 46 |
id_field.queryset = Authenticator.objects.filter( |
| 47 |
user=self.user, type=Authenticator.Type.WEBAUTHN |
| 48 |
) |
| 49 |
|
| 50 |
|
| 51 |
class DeleteWebAuthnInput(inputs.Input): |
| 52 |
authenticators = inputs.ModelMultipleChoiceField( |
| 53 |
queryset=Authenticator.objects.none() |
| 54 |
) |
| 55 |
|
| 56 |
def __init__(self, *args, **kwargs) -> None: |
| 57 |
self.user = kwargs.pop("user") |
| 58 |
super().__init__(*args, **kwargs) |
| 59 |
auth_field: inputs.ModelMultipleChoiceField = self.fields["authenticators"] # type: ignore[assignment] |
| 60 |
auth_field.queryset = Authenticator.objects.filter( |
| 61 |
user=self.user, type=Authenticator.Type.WEBAUTHN |
| 62 |
) |
| 63 |
|
| 64 |
|
| 65 |
class ReauthenticateWebAuthnInput(ReauthenticateWebAuthnForm, inputs.Input): |
| 66 |
pass |
| 67 |
|
| 68 |
|
| 69 |
class AuthenticateWebAuthnInput(AuthenticateWebAuthnForm, inputs.Input): |
| 70 |
pass |
| 71 |
|
| 72 |
|
| 73 |
class LoginWebAuthnInput(LoginWebAuthnForm, inputs.Input): |
| 74 |
pass |
| 75 |
|
| 76 |
|
| 77 |
class SignupWebAuthnInput(BaseSignupForm, inputs.Input): |
| 78 |
pass |
| 79 |
|
| 80 |
|
| 81 |
class TrustInput(inputs.Input): |
| 82 |
trust = inputs.BooleanField(required=False) |