mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-24 01:30:57 +00:00
update
This commit is contained in:
parent
b19e942841
commit
f49e4f7519
@ -16,7 +16,7 @@ from seahub.organizations.models import OrgSettings
|
||||
from seahub.organizations.settings import ORG_AUTO_URL_PREFIX
|
||||
from seahub.organizations.views import gen_org_url_prefix
|
||||
from seahub.password_session import update_session_auth_hash
|
||||
from seahub.utils import is_valid_email, send_html_email, get_site_name
|
||||
from seahub.utils import is_valid_email, send_html_email, get_site_name, IS_EMAIL_CONFIGURED
|
||||
from seahub.api2.authentication import TokenAuthentication
|
||||
from seahub.api2.throttling import UserRateThrottle
|
||||
from seahub.api2.utils import api_error
|
||||
@ -253,15 +253,17 @@ class ResetPasswordView(APIView):
|
||||
user.set_password(new_password)
|
||||
user.save()
|
||||
enable_pwd_email = bool(UserOptions.objects.get_password_update_email_enable_status(user.username))
|
||||
if enable_pwd_email:
|
||||
|
||||
if IS_EMAIL_CONFIGURED and enable_pwd_email:
|
||||
email_template_name = 'registration/password_change_email.html'
|
||||
send_to = email2contact_email(request.user.username)
|
||||
site_name = get_site_name()
|
||||
c = {
|
||||
'email': send_to
|
||||
'email': send_to,
|
||||
'name': email2nickname(user.username)
|
||||
}
|
||||
try:
|
||||
send_html_email(_("Successfully Changed Password on %s") % site_name,
|
||||
send_html_email(_("[%s]Your Password Has Been Successfully Updated") % site_name,
|
||||
email_template_name, c, None,
|
||||
[send_to])
|
||||
except Exception as e:
|
||||
|
@ -22,6 +22,7 @@ from seaserv import seafile_api, ccnet_api, \
|
||||
get_group, seafserv_threaded_rpc
|
||||
from pysearpc import SearpcError
|
||||
|
||||
from seahub.auth.utils import send_login_email
|
||||
from seahub.base.templatetags.seahub_tags import email2nickname, \
|
||||
translate_seahub_time, file_icon_filter, email2contact_email
|
||||
from seahub.constants import REPO_TYPE_WIKI
|
||||
@ -30,7 +31,7 @@ from seahub.group.utils import is_group_member
|
||||
from seahub.api2.models import Token, TokenV2, DESKTOP_PLATFORMS
|
||||
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, send_html_email, get_site_name
|
||||
from seahub.utils import get_user_repos, send_html_email, get_site_name, IS_EMAIL_CONFIGURED
|
||||
from seahub.utils.mail import send_html_email_with_dj_template
|
||||
from django.utils.translation import gettext as _
|
||||
import seahub.settings as settings
|
||||
@ -193,6 +194,7 @@ def get_token_v1(username):
|
||||
return token
|
||||
|
||||
_ANDROID_DEVICE_ID_PATTERN = re.compile('^[a-f0-9]{1,16}$')
|
||||
|
||||
def get_token_v2(request, username, platform, device_id, device_name,
|
||||
client_version, platform_version):
|
||||
|
||||
@ -213,23 +215,16 @@ def get_token_v2(request, username, platform, device_id, device_name,
|
||||
else:
|
||||
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/login_email.html'
|
||||
send_to = email2contact_email(username)
|
||||
site_name = get_site_name()
|
||||
c = {
|
||||
'name': email2nickname(username)
|
||||
}
|
||||
try:
|
||||
send_html_email(_("Welcome to %s") % site_name,
|
||||
email_template_name, c, None,
|
||||
[send_to])
|
||||
except Exception as e:
|
||||
logger.error('Failed to send notification to %s' % send_to)
|
||||
|
||||
return TokenV2.objects.get_or_create_token(
|
||||
|
||||
has_device = TokenV2.objects.filter(user=username, device_id=device_id, platform=platform).first()
|
||||
token = TokenV2.objects.get_or_create_token(
|
||||
username, platform, device_id, device_name,
|
||||
client_version, platform_version, get_client_ip(request))
|
||||
|
||||
if IS_EMAIL_CONFIGURED and enable_new_device_email and (not has_device):
|
||||
send_login_email(username)
|
||||
|
||||
return token
|
||||
|
||||
def get_api_token(request, keys=None, key_prefix='shib_'):
|
||||
|
||||
|
@ -1,13 +1,15 @@
|
||||
# Copyright (c) 2012-2016 Seafile Ltd.
|
||||
import logging
|
||||
from django.core.cache import cache
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from seahub.profile.models import Profile
|
||||
from seahub.utils import normalize_cache_key
|
||||
from seahub.utils import normalize_cache_key, get_site_name, send_html_email
|
||||
from seahub.utils.ip import get_remote_ip
|
||||
|
||||
LOGIN_ATTEMPT_PREFIX = 'UserLoginAttempt_'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def get_login_failed_attempts(username=None, ip=None):
|
||||
"""Get login failed attempts base on username and ip.
|
||||
@ -84,3 +86,19 @@ def get_virtual_id_by_email(email):
|
||||
return email
|
||||
else:
|
||||
return p.user
|
||||
|
||||
|
||||
def send_login_email(username):
|
||||
from seahub.base.templatetags.seahub_tags import email2contact_email, email2nickname
|
||||
email_template_name = 'registration/login_email.html'
|
||||
send_to = email2contact_email(username)
|
||||
site_name = get_site_name()
|
||||
c = {
|
||||
'name': email2nickname(username)
|
||||
}
|
||||
try:
|
||||
send_html_email(_("Welcome to %s") % site_name,
|
||||
email_template_name, c, None,
|
||||
[send_to])
|
||||
except Exception as e:
|
||||
logger.error('Failed to send notification to %s, %s' % (send_to, e))
|
||||
|
@ -30,12 +30,12 @@ from seahub.auth.signals import user_logged_in_failed
|
||||
from seahub.auth.tokens import default_token_generator
|
||||
from seahub.auth.utils import (
|
||||
get_login_failed_attempts, incr_login_failed_attempts,
|
||||
clear_login_failed_attempts)
|
||||
clear_login_failed_attempts, send_login_email)
|
||||
from seahub.base.accounts import User, UNUSABLE_PASSWORD
|
||||
from seahub.options.models import UserOptions
|
||||
from seahub.profile.models import Profile
|
||||
from seahub.two_factor.views.login import is_device_remembered
|
||||
from seahub.utils import render_error, get_site_name, is_valid_email, get_service_url
|
||||
from seahub.utils import render_error, get_site_name, is_valid_email, get_service_url, IS_EMAIL_CONFIGURED
|
||||
from seahub.utils.http import rate_limit
|
||||
from seahub.utils.ip import get_remote_ip
|
||||
from seahub.utils.file_size import get_quota_from_string
|
||||
@ -79,19 +79,9 @@ def log_user_in(request, user, redirect_to):
|
||||
auth_login(request, user)
|
||||
enable_login_email = bool(UserOptions.objects.get_login_email_enable_status(user.username))
|
||||
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 = {
|
||||
'name': email2nickname(user.username)
|
||||
}
|
||||
try:
|
||||
send_html_email(_("Welcome to %s") % site_name,
|
||||
email_template_name, c, None,
|
||||
[send_to])
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
|
||||
if IS_EMAIL_CONFIGURED and (user.username not in already_login_users) and enable_login_email:
|
||||
send_login_email(user.username)
|
||||
|
||||
return HttpResponseRedirect(redirect_to)
|
||||
|
||||
|
@ -10,10 +10,14 @@
|
||||
{% blocktrans with account=name %}Dear, {{ account }}{% endblocktrans %}
|
||||
</p>
|
||||
<p style="font-size:14px;color:#434144;">
|
||||
{% blocktrans %}
|
||||
Greetings!
|
||||
{% endblocktrans %}
|
||||
</p>
|
||||
<p style="font-size:14px;color:#434144;">
|
||||
{% 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." %}
|
||||
{% blocktrans %}
|
||||
We are thrilled to inform you that you have successfully joined {{ site_name }} - 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.
|
||||
{% endblocktrans %}
|
||||
</p>
|
||||
|
||||
{% endautoescape %}
|
||||
|
@ -4,14 +4,22 @@
|
||||
|
||||
{% block email_con %}
|
||||
|
||||
<p style="color:#121214;font-size:14px;">{% trans "Hi," %}</p>
|
||||
{% autoescape off %}
|
||||
|
||||
<p style="font-size:14px;color:#434144;">
|
||||
{% blocktrans with account=email %}Your password was changed. {% endblocktrans %}
|
||||
{% blocktrans with account=name %}Dear, {{ account }}{% endblocktrans %}
|
||||
</p>
|
||||
<p style="font-size:14px;color:#434144;">
|
||||
{{ email }}
|
||||
{% blocktrans %}
|
||||
Greetings!
|
||||
{% endblocktrans %}
|
||||
</p>
|
||||
<p style="font-size:14px;color:#434144;">
|
||||
{% blocktrans %}
|
||||
We are pleased to inform you that your password for {{ site_name }} has been successfully updated. To ensure the security of your account, we recommend regularly changing your password and avoiding simple or personally identifiable combinations.
|
||||
{% endblocktrans %}
|
||||
</p>
|
||||
|
||||
{% endautoescape %}
|
||||
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user