I am trying to customize the reauthentication form of the mfa. I aslo customized the TOTP activate and deactivate form and it works, but now i am struggling to customize the reauthentication form with my defined route name in django.
and is there any way to disable this reauth of the allauth mfa - 2fa
settings/urls.py
path('mfa/reauthenticate/', views.CustomReauthenticateView.as_view(), name='mfa_reauthenticate'),
settings/views.py
class CustomReauthenticateView(BaseReauthenticateView):
template_name = "settings/mfa/reauthenticate.html" # Ensure the correct template is used
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['custom_message'] = 'This is a custom message for reauthentication.'
return context
def form_valid(self, form):
response = super().form_valid(form)
return response
but it always rendering to localhost:8000/accounts/reauthenticate/?next=...
and not my defined url. I also tried another way by customizing the allauth.account.decoders - reauthentication_required but not work
Please someone help, that i want to redirect to my customize reauth form
I am trying to customize the reauthentication form of the mfa. I aslo customized the TOTP activate and deactivate form and it works, but now i am struggling to customize the reauthentication form with my defined route name in django.
and is there any way to disable this reauth of the allauth mfa - 2fa
settings/urls.py
path('mfa/reauthenticate/', views.CustomReauthenticateView.as_view(), name='mfa_reauthenticate'),
settings/views.py
class CustomReauthenticateView(BaseReauthenticateView):
template_name = "settings/mfa/reauthenticate.html" # Ensure the correct template is used
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['custom_message'] = 'This is a custom message for reauthentication.'
return context
def form_valid(self, form):
response = super().form_valid(form)
return response
but it always rendering to localhost:8000/accounts/reauthenticate/?next=...
and not my defined url. I also tried another way by customizing the allauth.account.decoders - reauthentication_required but not work
Please someone help, that i want to redirect to my customize reauth form
I don't know if it will still help you but I have a good solution.
If you are using the classic Django Login you need to update the record authentication session:
from allauth.account.internal.flows.login import record_authentication
from django.contrib.auth.views import LoginView
class CustomLoginView(LoginView):
def form_valid(self, form):
res = super().form_valid(form)
record_authentication(self.request, method="password", email=form.cleaned_data["username"])
return res
You also need to set the settings "REAUTHENTICATION_TIMEOUT"
This is use in the method "did_recently_authenticate" which is used in the decorator "reauthentication_required".
This decorator is for example used for activate or deactivate TOTP
/mfa/...
not/accounts/...
? – willeM_ Van Onsem Commented Jan 2 at 14:47/mfa/...
topath('accounts/reauthenticate/', views.CustomReauthenticateView.as_view(), name='mfa_reauthenticate'),
it worked, Thanks man – SamIsRightHere Commented Jan 2 at 17:02