You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To my surprise the TOKEN_STEP form was being switched to AuthenticationTokenForm, I finally tracked it down to code in the LoginView class
def get_form(self, step=None, **kwargs):
"""
Returns the form for the step
"""
if (step or self.steps.current) == self.TOKEN_STEP:
# Set form class dynamically depending on user device.
method = registry.method_from_device(self.get_device())
self.form_list[self.TOKEN_STEP] = method.get_token_form_class() #<-- returns AuthenticationTokenForm from registry but in other setups would be other forms
It is not clear what the best approach is here. I overrode get_form() in my LoginView subclass to bypass this:
def get_form(self, step=None, **kwargs):
"""
Returns the form for the step
"""
# This is a copy of code from core.py but it does not override the self.TOKEN_STEP which LoginView does
form = super(LoginView, self).get_form(step=step, **kwargs)
if self.show_timeout_error:
form.cleaned_data = getattr(form, 'cleaned_data', {})
form.add_error(None, ValidationError(_('Your session has timed out. Please login again.')))
return form
but possibly I should be doing something different/better maybe with registry?
It feels like a gap in the docs regarding what you do if you want to specify a fixed class in the token step and don't want it dynamically switching on you.
Expected Behavior
For my use case either it should respect the token step form defined in forms_list or block setting that value because it will be ignored, i.e.
form_list = (
(LoginView.AUTH_STEP, forms.MyAuthenticationForm),
(LoginView.TOKEN_STEP, forms.MyAuthenticationTokenForm), <-- This should be a runtime error, don't do that?
(LoginView.BACKUP_STEP, forms.MyBackupTokenForm),
)
Current Behavior
Quietly switches classes on you behind your back without warning you that your TOKEN_STEP value is going to be overridden from the registry which is very confusing.
The text was updated successfully, but these errors were encountered:
That is surprising and a little bit confusing too! I'm almost tempted to call this a bug as we populate form_list and then just go and ignore it - I feel like we should do something different to make it clearer that we're going to call the registry for that particular form.
I have a subclassed LoginView which defines a set of forms:
To my surprise the TOKEN_STEP form was being switched to AuthenticationTokenForm, I finally tracked it down to code in the LoginView class
It is not clear what the best approach is here. I overrode get_form() in my LoginView subclass to bypass this:
but possibly I should be doing something different/better maybe with registry?
It feels like a gap in the docs regarding what you do if you want to specify a fixed class in the token step and don't want it dynamically switching on you.
Expected Behavior
For my use case either it should respect the token step form defined in forms_list or block setting that value because it will be ignored, i.e.
Current Behavior
Quietly switches classes on you behind your back without warning you that your TOKEN_STEP value is going to be overridden from the registry which is very confusing.
The text was updated successfully, but these errors were encountered: