stages/authenticator_validate: cleanup

This commit is contained in:
Jens Langhammer 2021-03-02 22:20:54 +01:00
parent 5c739ebed2
commit 23de9df2a5

View file

@ -1,9 +1,7 @@
"""OTP Validate stage forms""" """OTP Validate stage forms"""
from django import forms from django import forms
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django_otp import match_token
from authentik.core.models import User
from authentik.flows.models import NotConfiguredAction from authentik.flows.models import NotConfiguredAction
from authentik.stages.authenticator_validate.models import ( from authentik.stages.authenticator_validate.models import (
AuthenticatorValidateStage, AuthenticatorValidateStage,
@ -11,35 +9,6 @@ from authentik.stages.authenticator_validate.models import (
) )
class ValidationForm(forms.Form):
"""OTP Validate stage forms"""
user: User
code = forms.CharField(
label=_("Please enter the token from your device."),
widget=forms.TextInput(
attrs={
"autocomplete": "one-time-code",
"placeholder": "123456",
"autofocus": "autofocus",
}
),
)
def __init__(self, user, *args, **kwargs):
super().__init__(*args, **kwargs)
self.user = user
def clean_code(self):
"""Validate code against all confirmed devices"""
code = self.cleaned_data.get("code")
device = match_token(self.user, code)
if not device:
raise forms.ValidationError(_("Invalid Token"))
return code
class AuthenticatorValidateStageForm(forms.ModelForm): class AuthenticatorValidateStageForm(forms.ModelForm):
"""OTP Validate stage forms""" """OTP Validate stage forms"""