1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-02 07:47:32 +00:00

[two factor] Refactor code

This commit is contained in:
zhengxie 2017-08-23 14:43:32 +08:00
parent d0975c7836
commit f15aa06978
6 changed files with 16 additions and 39 deletions

View File

@ -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):

View File

@ -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<user>[^/]+)/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<username>[^/]*)/$', 'user_profile', name="user_profile"),

View File

@ -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 %}
<h4>{% trans "Library" %}</h4>

View File

@ -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

View File

@ -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

View File

@ -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'),
)