added setting to anable MFA

This commit is contained in:
Matthias 2021-11-01 00:34:00 +01:00
parent a8e18a7972
commit 9d68d6bdca
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
3 changed files with 9 additions and 1 deletions

View File

@ -11,6 +11,7 @@ from rest_framework.authtoken.models import Token
from allauth_2fa.middleware import BaseRequire2FAMiddleware, AllauthTwoFactorMiddleware from allauth_2fa.middleware import BaseRequire2FAMiddleware, AllauthTwoFactorMiddleware
from InvenTree.urls import frontendpatterns from InvenTree.urls import frontendpatterns
from common.models import InvenTreeSetting
logger = logging.getLogger("inventree") logger = logging.getLogger("inventree")
@ -162,7 +163,7 @@ class Check2FAMiddleware(BaseRequire2FAMiddleware):
# Superusers are require to have 2FA. # Superusers are require to have 2FA.
try: try:
if url_matcher.resolve(request.path[1:]): if url_matcher.resolve(request.path[1:]):
return True return InvenTreeSetting.get_setting('LOGIN_ENFORCE_MFA')
except Resolver404: except Resolver404:
pass pass
return False return False

View File

@ -853,6 +853,12 @@ class InvenTreeSetting(BaseInvenTreeSetting):
'default': '', 'default': '',
'choices': settings_group_options 'choices': settings_group_options
}, },
'LOGIN_ENFORCE_MFA': {
'name': _('Enforce MFA'),
'description': _('Users must use multifaktor security.'),
'default': False,
'validator': bool,
},
} }
class Meta: class Meta:

View File

@ -16,6 +16,7 @@
{% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_SSO" icon="fa-info-circle" %} {% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_SSO" icon="fa-info-circle" %}
{% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_PWD_FORGOT" icon="fa-info-circle" %} {% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_PWD_FORGOT" icon="fa-info-circle" %}
{% include "InvenTree/settings/setting.html" with key="LOGIN_MAIL_REQUIRED" icon="fa-info-circle" %} {% include "InvenTree/settings/setting.html" with key="LOGIN_MAIL_REQUIRED" icon="fa-info-circle" %}
{% include "InvenTree/settings/setting.html" with key="LOGIN_ENFORCE_MFA" %}
<tr> <tr>
<td>{% trans 'Signup' %}</td> <td>{% trans 'Signup' %}</td>
<td colspan='4'></td> <td colspan='4'></td>