From b19e9428411aa4dd03f2d36730786cc6bf19fff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=B0=B8=E5=BC=BA?= <11704063+s-yongqiang@user.noreply.gitee.com> Date: Fri, 16 Aug 2024 15:39:09 +0800 Subject: [PATCH] update email content --- .../components/user-settings/email-notice.js | 3 +-- seahub/api2/utils.py | 8 ++++--- seahub/auth/__init__.py | 10 +++++---- seahub/auth/views.py | 14 ++++++------- .../registration/browse_login_email.html | 20 ------------------ .../templates/registration/login_email.html | 21 +++++++++++++++++++ .../registration/new_device_login_email.html | 21 ------------------- 7 files changed, 40 insertions(+), 57 deletions(-) delete mode 100644 seahub/templates/registration/browse_login_email.html create mode 100644 seahub/templates/registration/login_email.html delete mode 100644 seahub/templates/registration/new_device_login_email.html diff --git a/frontend/src/components/user-settings/email-notice.js b/frontend/src/components/user-settings/email-notice.js index 1d3d96a7bc..fd4972cb17 100644 --- a/frontend/src/components/user-settings/email-notice.js +++ b/frontend/src/components/user-settings/email-notice.js @@ -130,8 +130,7 @@ class EmailNotice extends React.Component { ); })} -

{gettext('Notifications of login')}

-

{gettext('Send a mail as soon as a new device or browser has signed into the account (like google and many other services do).')}

+

{gettext(' Send a mail as soon as a new device or browser has signed into the account')}

{this.loginOption.map((item, index) => { return (
diff --git a/seahub/api2/utils.py b/seahub/api2/utils.py index 5dc5ff9683..1701950ccc 100644 --- a/seahub/api2/utils.py +++ b/seahub/api2/utils.py @@ -214,12 +214,14 @@ def get_token_v2(request, username, platform, device_id, device_name, raise serializers.ValidationError('invalid platform') enable_new_device_email = bool(UserOptions.objects.get_login_email_enable_status(username)) if not TokenV2.objects.filter(user=username, device_id=device_id).first() and enable_new_device_email: - email_template_name='registration/new_device_login_email.html' + email_template_name='registration/login_email.html' send_to = email2contact_email(username) site_name = get_site_name() - c = {'email': send_to} + c = { + 'name': email2nickname(username) + } try: - send_html_email(_("New Device Login on %s") % site_name, + send_html_email(_("Welcome to %s") % site_name, email_template_name, c, None, [send_to]) except Exception as e: diff --git a/seahub/auth/__init__.py b/seahub/auth/__init__.py index 682fbf5858..16600bf8e1 100644 --- a/seahub/auth/__init__.py +++ b/seahub/auth/__init__.py @@ -13,6 +13,7 @@ from constance import config from seaserv import ccnet_api SESSION_KEY = '_auth_user_name' +SESSION_USERS_LOGIN = '_already_loging_users' BACKEND_SESSION_KEY = '_auth_user_backend_2' REDIRECT_FIELD_NAME = 'next' SESSION_MOBILE_LOGIN_KEY = "MOBILE_LOGIN" @@ -119,12 +120,13 @@ def logout(request): session data. Also remove all passwords used to decrypt repos. """ - already_logged_list = request.session.get('_already_logged', []) + already_logged_list = request.session.get(SESSION_USERS_LOGIN, []) request.session.flush() - if request.user.username not in already_logged_list: - already_logged_list.append(request.user.username) - request.session['_already_logged'] = already_logged_list if hasattr(request, 'user'): + username = request.user.username + if username not in already_logged_list: + already_logged_list.append(username) + request.session[SESSION_USERS_LOGIN] = already_logged_list from seahub.base.accounts import User if isinstance(request.user, User): # Do not directly/indirectly import models in package root level. diff --git a/seahub/auth/views.py b/seahub/auth/views.py index 470415096b..8901dc55af 100644 --- a/seahub/auth/views.py +++ b/seahub/auth/views.py @@ -20,7 +20,7 @@ from saml2.ident import decode from seaserv import seafile_api, ccnet_api from seahub.settings import SSO_SECRET_KEY from seahub.auth import REDIRECT_FIELD_NAME, get_backends -from seahub.auth import login as auth_login +from seahub.auth import login as auth_login, SESSION_USERS_LOGIN from seahub.auth.models import SocialAuthUser from seahub.auth.decorators import login_required from seahub.auth.forms import AuthenticationForm, CaptchaAuthenticationForm, \ @@ -52,7 +52,7 @@ from seahub.onlyoffice.settings import ONLYOFFICE_DESKTOP_EDITOR_HTTP_USER_AGENT from seahub.utils import send_html_email from django.utils.translation import gettext_lazy as _ -from seahub.base.templatetags.seahub_tags import email2contact_email +from seahub.base.templatetags.seahub_tags import email2contact_email, email2nickname # Get an instance of a logger logger = logging.getLogger(__name__) @@ -78,16 +78,16 @@ def log_user_in(request, user, redirect_to): # Okay, security checks complete. Log the user in. auth_login(request, user) enable_login_email = bool(UserOptions.objects.get_login_email_enable_status(user.username)) - already_logs = request.session.get('_already_logged', []) - if user.username not in already_logs and enable_login_email: - email_template_name = 'registration/browse_login_email.html' + already_login_users = request.session.get(SESSION_USERS_LOGIN, []) + if user.username not in already_login_users and enable_login_email: + email_template_name = 'registration/login_email.html' send_to = email2contact_email(request.user.username) site_name = get_site_name() c = { - 'email': send_to + 'name': email2nickname(user.username) } try: - send_html_email(_("%s account login reminder") % site_name, + send_html_email(_("Welcome to %s") % site_name, email_template_name, c, None, [send_to]) except Exception as e: diff --git a/seahub/templates/registration/browse_login_email.html b/seahub/templates/registration/browse_login_email.html deleted file mode 100644 index 9b90f9f436..0000000000 --- a/seahub/templates/registration/browse_login_email.html +++ /dev/null @@ -1,20 +0,0 @@ -{% extends 'email_base.html' %} - -{% load i18n %} - -{% block email_con %} - -{% autoescape off %} - -

{% trans "Hi," %}

- -

-{% blocktrans with account=email %}You are currently logging into this site using a browser{% endblocktrans %} -

-

-{{ email }} -

- -{% endautoescape %} - -{% endblock %} diff --git a/seahub/templates/registration/login_email.html b/seahub/templates/registration/login_email.html new file mode 100644 index 0000000000..b0dcbb6443 --- /dev/null +++ b/seahub/templates/registration/login_email.html @@ -0,0 +1,21 @@ +{% extends 'email_base.html' %} + +{% load i18n %} + +{% block email_con %} + +{% autoescape off %} + +

+{% blocktrans with account=name %}Dear, {{ account }}{% endblocktrans %} +

+

+Greetings! +

+

+{% trans " We are thrilled to inform you that you have successfully joined Seafile - a cloud-based platform dedicated to file management and team collaboration. Here, you'll find seamless and secure digital workspaces for document sharing, version control, and teamwork." %} +

+ +{% endautoescape %} + +{% endblock %} diff --git a/seahub/templates/registration/new_device_login_email.html b/seahub/templates/registration/new_device_login_email.html deleted file mode 100644 index 343e5c1e47..0000000000 --- a/seahub/templates/registration/new_device_login_email.html +++ /dev/null @@ -1,21 +0,0 @@ -{% extends 'email_base.html' %} - -{% load i18n %} - -{% block email_con %} - -{% autoescape off %} - -

{% trans "Hi," %}

- -

-{% blocktrans with account=email %}You are trying to log in to your account with a new device {{ account }}{% endblocktrans %} -

- -

-{% trans "If you do not have this operation, please change your password as soon as possible." %} -

- -{% endautoescape %} - -{% endblock %}