We have our own login decorator and we want to disable the default @login_required so anyone who will import and use the original decorator will get an exception.
How can we money-patch / disable this function?
Edit: As I read the comments I understand that this is the wrong approach. we've added 2fa authentication and with it wrote this decorator to replace @login_required:
def is_user_2fa(user):
for company in user.companies:
if company.two_factor_auth:
return True
return False
def tfa_authenticated(user):
return user.is_verified() or (user.is_authenticated() and not is_user_2fa(user))
def login_2fa_required(view=None, redirect_field_name='next', login_url=None):
if login_url is None:
login_url = settings.OTP_LOGIN_URL
def test(user):
return tfa_authenticated(user)
decorator = user_passes_test(test, login_url=login_url, redirect_field_name=redirect_field_name)
return decorator if (view is None) else decorator(view)
What's right way to keep @login_required while enforcing 2fa when it applies?
Thank you