diff --git a/media/css/seahub.css b/media/css/seahub.css index ee8f781396..077976f1da 100644 --- a/media/css/seahub.css +++ b/media/css/seahub.css @@ -2065,3 +2065,11 @@ a.sf-popover-item { background: #6e7687; height: 12px; } + +#email-audit-form .email-input { + width: 172px; +} + +#email-audit-form .get-code-btn { + width: 102px; +} diff --git a/seahub/api2/utils.py b/seahub/api2/utils.py index f5c17ee249..6c5f35218a 100644 --- a/seahub/api2/utils.py +++ b/seahub/api2/utils.py @@ -32,6 +32,7 @@ from seahub.avatar.settings import AVATAR_DEFAULT_SIZE from seahub.avatar.templatetags.avatar_tags import api_avatar_url from seahub.utils import get_user_repos from seahub.utils.mail import send_html_email_with_dj_template +from django.utils.translation import gettext as _ from seahub.settings import SECRET_KEY logger = logging.getLogger(__name__) @@ -285,7 +286,7 @@ def is_web_request(request): return True else: return False - + def is_wiki_repo(repo): return repo.repo_type == REPO_TYPE_WIKI @@ -306,9 +307,9 @@ def get_search_repos(username, org_id): repos.append((repo.id, repo.origin_repo_id, repo.origin_path, repo.name)) return repos - + def send_share_link_emails(emails, fs, shared_from): - subject = "Share links" + subject = _("A share link for you") for email in emails: c = {'url': "%s?email=%s" % (fs.get_full_url(), email), 'shared_from': shared_from} send_success = send_html_email_with_dj_template( @@ -321,7 +322,7 @@ def send_share_link_emails(emails, fs, shared_from): continue def is_valid_internal_jwt(auth): - + if not auth or auth[0].lower()!= 'token' or len(auth) != 2: return False @@ -337,5 +338,5 @@ def is_valid_internal_jwt(auth): is_internal = payload.get('is_internal') if is_internal: return True - + return False diff --git a/seahub/share/decorators.py b/seahub/share/decorators.py index fb77ebbb06..854251e1c9 100644 --- a/seahub/share/decorators.py +++ b/seahub/share/decorators.py @@ -12,27 +12,33 @@ from seahub.share.models import FileShare, UploadLinkShare from seahub.share.utils import SCOPE_SPECIFIC_EMAILS, SCOPE_ALL_USERS, SCOPE_SPECIFIC_USERS from seahub.utils import render_error from seahub.utils import normalize_cache_key, is_pro_version, redirect_to_login +from seahub.utils.auth import get_login_bg_image_path from seahub.constants import REPO_SHARE_LINK_COUNT_LIMIT def _share_link_auth_email_entry(request, fileshare, func, *args, **kwargs): if request.user.username == fileshare.username: return func(request, fileshare, *args, **kwargs) - + session_key = "link_authed_email_%s" % fileshare.token if request.session.get(session_key) is not None: return func(request, fileshare, *args, **kwargs) - + + login_bg_image_path = get_login_bg_image_path() if request.method == 'GET': email = request.GET.get('email', '') - return render(request, 'share/share_link_email_audit.html', {'email': email, 'token': fileshare.token}) - + return render(request, 'share/share_link_email_audit.html', { + 'email': email, + 'token': fileshare.token, + 'login_bg_image_path': login_bg_image_path, + }) + elif request.method == 'POST': code_post = request.POST.get('code', '') email_post = request.POST.get('email', '') cache_key = normalize_cache_key(email_post, 'share_link_email_auth_', token=fileshare.token) code = cache.get(cache_key) - + authed_details = json.loads(fileshare.authed_details) if code == code_post and email_post in authed_details.get('authed_emails'): request.session[session_key] = email_post @@ -40,12 +46,13 @@ def _share_link_auth_email_entry(request, fileshare, func, *args, **kwargs): return func(request, fileshare, *args, **kwargs) else: return render(request, 'share/share_link_email_audit.html', { - 'err_msg': 'Invalid token, please try again.', + 'login_bg_image_path': login_bg_image_path, + 'err_msg': _('Invalid verification code, please try again.'), 'email': email_post, 'code': code, 'token': fileshare.token, 'code_verify': False - + }) else: assert False, 'TODO' @@ -56,7 +63,7 @@ def share_link_audit(func): def _decorated(request, token, *args, **kwargs): assert token is not None # Checked by URLconf - + is_for_upload = False try: fileshare = FileShare.objects.get(token=token) @@ -69,22 +76,22 @@ def share_link_audit(func): is_for_upload = True except UploadLinkShare.DoesNotExist: fileshare = None - + if not fileshare: return render_error(request, _('Link does not exist.')) - + if fileshare.is_expired(): return render_error(request, _('Link is expired.')) - + if is_for_upload: return func(request, fileshare, *args, **kwargs) - + if fileshare.user_scope in [SCOPE_ALL_USERS, SCOPE_SPECIFIC_USERS]: return func(request, fileshare, *args, **kwargs) if fileshare.user_scope == SCOPE_SPECIFIC_EMAILS: return _share_link_auth_email_entry(request, fileshare, func, *args, **kwargs) - + return _decorated def share_link_login_required(func): diff --git a/seahub/share/templates/share/audit_code_email.html b/seahub/share/templates/share/audit_code_email.html index beb6d691bd..e6f682f78c 100644 --- a/seahub/share/templates/share/audit_code_email.html +++ b/seahub/share/templates/share/audit_code_email.html @@ -2,15 +2,16 @@ {% load i18n %} {% block email_con %} - {% autoescape off %}

{% trans "Hi," %}

-{% blocktrans %}Your code is {{code}}, this code will be valid for one hour.{% endblocktrans%} +{% blocktrans %}The verification code is {{code}}, and it will be valid in one hour.{% endblocktrans%}

{% endautoescape %} - +{% endblock %} + +{% block thanks %} {% endblock %} diff --git a/seahub/share/templates/share/share_link_audit.html b/seahub/share/templates/share/share_link_audit.html deleted file mode 100644 index edf6d4e0ed..0000000000 --- a/seahub/share/templates/share/share_link_audit.html +++ /dev/null @@ -1,80 +0,0 @@ -{% extends "base.html" %} -{% load i18n %} - -{% block main_panel %} -
-

{% trans "Email Verification" %}

- -
-{% endblock %} -{% block extra_script %} - -{% endblock %} diff --git a/seahub/share/templates/share/share_link_email.html b/seahub/share/templates/share/share_link_email.html index 13b179be04..7f9a14d785 100644 --- a/seahub/share/templates/share/share_link_email.html +++ b/seahub/share/templates/share/share_link_email.html @@ -2,18 +2,21 @@ {% load i18n %} {% block email_con %} - {% autoescape off %} -

{% trans "Hi," %}

{% blocktrans %} - {{ shared_from }} has shared a library with you. - Please click here to verify your email. + {{ shared_from }} shared a file link with you. +{% endblocktrans%} +

+

+{% blocktrans %} +You can click here to verify your email address and visit it. {% endblocktrans%}

- {% endautoescape %} - +{% endblock %} + +{% block thanks %} {% endblock %} diff --git a/seahub/share/templates/share/share_link_email_audit.html b/seahub/share/templates/share/share_link_email_audit.html index bd5f21a43c..5cfd264a61 100644 --- a/seahub/share/templates/share/share_link_email_audit.html +++ b/seahub/share/templates/share/share_link_email_audit.html @@ -1,82 +1,112 @@ {% extends "base.html" %} {% load i18n %} +{% block sub_title %}{% trans "Email address verification" %} - {% endblock %} +{% block header_css_class %}hide{% endblock %} +{% block extra_base_style %} + +{% endblock %} + +{% block extra_style %} + +{% endblock %} + {% block main_panel %} -
-

{% trans "Email Verification" %}

- {% endblock %} + {% block extra_script %} {% endblock %} diff --git a/seahub/share/urls.py b/seahub/share/urls.py index db80c858f0..97a8c29a23 100644 --- a/seahub/share/urls.py +++ b/seahub/share/urls.py @@ -7,6 +7,5 @@ urlpatterns = [ path('link/save/', save_shared_link, name='save_shared_link'), path('link/export-excel/', export_shared_link, name='export_shared_link'), path('ajax/private-share-dir/', ajax_private_share_dir, name='ajax_private_share_dir'), - path('ajax/get-link-audit-code/', ajax_get_link_audit_code, name='ajax_get_link_audit_code'), path('ajax/get-link-email-audit-code/', ajax_get_link_email_audit_code, name='ajax_get_link_email_audit_code'), ] diff --git a/seahub/share/views.py b/seahub/share/views.py index 9688b498fb..c0d2f18bf2 100644 --- a/seahub/share/views.py +++ b/seahub/share/views.py @@ -344,56 +344,6 @@ def ajax_private_share_dir(request): data = json.dumps({"error": _("Please check the email(s) you entered")}) return HttpResponse(data, status=400, content_type=content_type) - -def ajax_get_link_audit_code(request): - """ - Generate a token, and record that token with email in cache, expires in - one hour, send token to that email address. - - User provide token and email at share link page, if the token and email - are valid, record that email in session. - """ - content_type = 'application/json; charset=utf-8' - - token = request.POST.get('token') - email = request.POST.get('email') - if not is_valid_email(email): - return HttpResponse(json.dumps({ - 'error': _('Email address is not valid') - }), status=400, content_type=content_type) - - dfs = FileShare.objects.get_valid_file_link_by_token(token) - ufs = UploadLinkShare.objects.get_valid_upload_link_by_token(token) - - fs = dfs if dfs else ufs - if fs is None: - return HttpResponse(json.dumps({ - 'error': _('Share link is not found') - }), status=400, content_type=content_type) - - cache_key = normalize_cache_key(email, 'share_link_audit_') - code = gen_token(max_length=6) - cache.set(cache_key, code, SHARE_LINK_AUDIT_CODE_TIMEOUT) - - # send code to user via email - subject = _("Verification code for visiting share links") - c = {'code': code} - - send_success = send_html_email_with_dj_template(email, - subject=subject, - dj_template='share/audit_code_email.html', - context=c) - - if not send_success: - logger.error('Failed to send audit code via email to %s') - return HttpResponse(json.dumps({ - "error": _("Failed to send a verification code, please try again later.") - }), status=500, content_type=content_type) - - return HttpResponse(json.dumps({'success': True}), status=200, - content_type=content_type) - - def ajax_get_link_email_audit_code(request): content_type = 'application/json; charset=utf-8' @@ -422,7 +372,7 @@ def ajax_get_link_email_audit_code(request): cache.set(cache_key, code, 60 * 60) # send code to user via email - subject = _("Verification code for visiting share links") + subject = _("The verification code") c = {'code': code} send_success = send_html_email_with_dj_template(email, diff --git a/seahub/templates/email_base.html b/seahub/templates/email_base.html index 54f665cafa..64b44f4459 100644 --- a/seahub/templates/email_base.html +++ b/seahub/templates/email_base.html @@ -5,11 +5,13 @@
{% block email_con %}{% endblock %} -

+ {% block thanks %} +

{% trans "Thanks for using our site!" %}

+ {% endblock %} -

+

{% blocktrans %}The {{ site_name }} team{% endblocktrans %}

diff --git a/seahub/templates/registration/login.html b/seahub/templates/registration/login.html index 82af04af9a..a987125973 100644 --- a/seahub/templates/registration/login.html +++ b/seahub/templates/registration/login.html @@ -2,9 +2,7 @@ {% load i18n %} {% block sub_title %}{% trans "Log In" %} - {% endblock %} - {% block header_css_class %}hide{% endblock %} - {% block extra_base_style %} {% endblock %}