diff --git a/seahub/api2/endpoints/admin/two_factor_auth.py b/seahub/api2/endpoints/admin/two_factor_auth.py index 15c7b343ff..92d6446ba7 100644 --- a/seahub/api2/endpoints/admin/two_factor_auth.py +++ b/seahub/api2/endpoints/admin/two_factor_auth.py @@ -9,7 +9,6 @@ from seahub.api2.base import APIView from seahub.api2.throttling import UserRateThrottle from seahub.api2.utils import json_response, api_error from seahub.api2.authentication import TokenAuthentication -from seahub.utils.two_factor_auth import has_two_factor_auth, two_factor_auth_enabled class TwoFactorAuthView(APIView): diff --git a/seahub/profile/urls.py b/seahub/profile/urls.py index 64d4218418..9280ac8816 100644 --- a/seahub/profile/urls.py +++ b/seahub/profile/urls.py @@ -1,20 +1,16 @@ # Copyright (c) 2012-2016 Seafile Ltd. from django.conf.urls import patterns, url, include -from seahub.utils.two_factor_auth import HAS_TWO_FACTOR_AUTH -urlpatterns = patterns('seahub.profile.views', +urlpatterns = patterns( + 'seahub.profile.views', # url(r'^list_user/$', 'list_userids', name="list_userids"), url(r'^$', 'edit_profile', name="edit_profile"), url(r'^(?P[^/]+)/get/$', 'get_user_profile', name="get_user_profile"), url(r'^delete/$', 'delete_user_account', name="delete_user_account"), url(r'^default-repo/$', 'default_repo', name="default_repo"), + (r'^two_factor_authentication/', include('seahub.two_factor.urls', 'two_factor')), ) -if HAS_TWO_FACTOR_AUTH: - urlpatterns += patterns('', - (r'^two_factor_authentication/', include('seahub.two_factor.urls', 'two_factor')), - ) - # Move the catch-all pattern to the end. urlpatterns += patterns('seahub.profile.views', url(r'^(?P[^/]*)/$', 'user_profile', name="user_profile"), diff --git a/seahub/templates/sysadmin/settings.html b/seahub/templates/sysadmin/settings.html index fcd69f7f91..48a227ea9b 100644 --- a/seahub/templates/sysadmin/settings.html +++ b/seahub/templates/sysadmin/settings.html @@ -104,13 +104,11 @@ {% include "snippets/web_settings_form.html" %} {% endwith %} - {% if has_two_factor_auth %} {% with type="checkbox" setting_name="ENABLE_TWO_FACTOR_AUTH" setting_val=config_dict.ENABLE_TWO_FACTOR_AUTH %} {% trans "enable two factor authentication" as setting_display_name %} {% trans "Enable two factor authentication" as help_tip %} {% include "snippets/web_settings_form.html" %} {% endwith %} - {% endif %}

{% trans "Library" %}

diff --git a/seahub/utils/two_factor_auth.py b/seahub/utils/two_factor_auth.py index b5b9aa933d..f0cf1f3b2a 100644 --- a/seahub/utils/two_factor_auth.py +++ b/seahub/utils/two_factor_auth.py @@ -2,19 +2,11 @@ # encoding: utf-8 from constance import config -try: - from seahub.two_factor.views.login import ( - two_factor_auth_enabled, - handle_two_factor_auth, - verify_two_factor_token, - ) - HAS_TWO_FACTOR_AUTH = True -except ImportError: - two_factor_auth_enabled = lambda *a: False - handle_two_factor_auth = None - verify_two_factor_token = None - HAS_TWO_FACTOR_AUTH = False - +from seahub.two_factor.views.login import ( + two_factor_auth_enabled, handle_two_factor_auth, verify_two_factor_token, +) def has_two_factor_auth(): - return HAS_TWO_FACTOR_AUTH and config.ENABLE_TWO_FACTOR_AUTH + """Global setting to control enable/disable two factor auth. + """ + return config.ENABLE_TWO_FACTOR_AUTH diff --git a/seahub/views/sysadmin.py b/seahub/views/sysadmin.py index 757e5285a5..8c8bed71b2 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -76,7 +76,7 @@ try: from seahub.settings import MULTI_TENANCY except ImportError: MULTI_TENANCY = False -from seahub.utils.two_factor_auth import has_two_factor_auth, HAS_TWO_FACTOR_AUTH +from seahub.utils.two_factor_auth import has_two_factor_auth from termsandconditions.models import TermsAndConditions logger = logging.getLogger(__name__) @@ -2025,12 +2025,9 @@ def sys_settings(request): 'USER_PASSWORD_STRENGTH_LEVEL', 'SHARE_LINK_PASSWORD_MIN_LENGTH', 'ENABLE_USER_CREATE_ORG_REPO', 'FORCE_PASSWORD_CHANGE', 'LOGIN_ATTEMPT_LIMIT', 'FREEZE_USER_ON_LOGIN_FAILED', - 'ENABLE_SHARE_TO_ALL_GROUPS' + 'ENABLE_SHARE_TO_ALL_GROUPS', 'ENABLE_TWO_FACTOR_AUTH' ] - if HAS_TWO_FACTOR_AUTH: - DIGIT_WEB_SETTINGS.append('ENABLE_TWO_FACTOR_AUTH') - STRING_WEB_SETTINGS = ('SERVICE_URL', 'FILE_SERVER_ROOT', 'TEXT_PREVIEW_EXT') if request.is_ajax() and request.method == "POST": @@ -2076,7 +2073,6 @@ def sys_settings(request): return render_to_response('sysadmin/settings.html', { 'config_dict': config_dict, - 'has_two_factor_auth': HAS_TWO_FACTOR_AUTH, }, context_instance=RequestContext(request)) @login_required_ajax diff --git a/thirdpart/registration/auth_urls.py b/thirdpart/registration/auth_urls.py index b6353c3fae..455afe054f 100644 --- a/thirdpart/registration/auth_urls.py +++ b/thirdpart/registration/auth_urls.py @@ -27,7 +27,7 @@ from django.conf import settings from django.conf.urls import patterns, url from seahub.auth import views as auth_views -from seahub.utils.two_factor_auth import HAS_TWO_FACTOR_AUTH +from seahub.two_factor.views.login import TwoFactorVerifyView urlpatterns = patterns('', url(r'^password/change/$', @@ -48,6 +48,10 @@ urlpatterns = patterns('', url(r'^password/reset/done/$', auth_views.password_reset_done, name='auth_password_reset_done'), + + url(r'^login/two-factor-auth/$', + TwoFactorVerifyView.as_view(), + name='two_factor_auth'), ) if getattr(settings, 'ENABLE_LOGIN_SIMPLE_CHECK', False): @@ -74,11 +78,3 @@ else: 'next_page': settings.LOGOUT_REDIRECT_URL}, name='auth_logout'), ) - - if HAS_TWO_FACTOR_AUTH: - from seahub.two_factor.views.login import TwoFactorVerifyView - urlpatterns += patterns('', - url(r'^login/two-factor-auth/$', - TwoFactorVerifyView.as_view(), - name='two_factor_auth'), - )