diff --git a/seahub/auth/forms.py b/seahub/auth/forms.py index 05f4ed5b22..46191fd7f7 100644 --- a/seahub/auth/forms.py +++ b/seahub/auth/forms.py @@ -7,7 +7,7 @@ from django.utils.http import int_to_base36 from seahub.base.accounts import User from seahub.auth import authenticate from seahub.auth.tokens import default_token_generator -from seahub.utils import IS_EMAIL_CONFIGURED +from seahub.utils import IS_EMAIL_CONFIGURED, get_service_url from captcha.fields import CaptchaField @@ -92,24 +92,24 @@ class PasswordResetForm(forms.Form): if not domain_override: current_site = Site.objects.get_current() site_name = current_site.name - domain = current_site.domain else: - site_name = domain = domain_override + site_name = domain_override + + service_url = get_service_url() t = loader.get_template(email_template_name) c = { 'email': user.username, - 'domain': domain, 'site_name': site_name, 'uid': int_to_base36(user.id), 'user': user, 'token': token_generator.make_token(user), - 'protocol': use_https and 'https' or 'http', + 'service_url': service_url, 'media_url': settings.MEDIA_URL, 'logo_path': settings.LOGO_PATH, } - msg = EmailMessage(_("Password reset on %s") % site_name, + msg = EmailMessage(_("Reset Password on %s") % site_name, t.render(Context(c)), None, [user.username]) msg.content_subtype = "html" # Main content is now text/html msg.send() diff --git a/seahub/group/templates/group/add_member_email.html b/seahub/group/templates/group/add_member_email.html index 211e966036..db82b6f3f3 100644 --- a/seahub/group/templates/group/add_member_email.html +++ b/seahub/group/templates/group/add_member_email.html @@ -1,9 +1,18 @@ -{% load url from future %}{% load i18n %}{% autoescape off %} -{% blocktrans %}{{ email }} invite you to join group {{ group.group_name }}. Please go to the following page and sign up:{% endblocktrans %} -{{ protocol }}://{{ domain }}{% url 'registration_register' %}?src={{ to_email }} +{% extends 'email_base.html' %} -{% trans "Thanks for using our site!" %} +{% load i18n seahub_tags %} -{% blocktrans %}The {{ site_name }} team{% endblocktrans %} +{% block email_con %} +{% autoescape off %} + +
{% trans "Hi, " %}
+ +
+{% blocktrans with grp_name=group.group_name %}{{ email }} invited you to join group {{ grp_name }} on {{ site_name }}: {% endblocktrans %}
+{{ service_url }}{% url 'registration_register' %}?src={{ to_email }}
+
{% blocktrans with name=to_user|email2nickname %}Hi {{ name }},{% endblocktrans %}
+ ++{% blocktrans count num=notice_count %} +You've got 1 new notice on {{ site_name }}. +{% plural %} +You've got {{num}} new notices on {{ site_name }}. +{% endblocktrans %} +
+ +
+{% trans "Go check out at the following page:" %}
+{{ service_url }}{% url 'user_notification_list' %}
+
{% trans "Hi," %}
-{% blocktrans %}You're receiving this e-mail because you requested a password reset for your user account at {{ site_name }}. {% endblocktrans %}
-
-{% trans "Please go to the following page and choose a new password:" %}
-{% block reset_link %}
-{{ protocol }}://{{ domain }}{% url 'auth_password_reset_confirm' uidb36=uid token=token %}
-{% endblock %}
+{% blocktrans with account=user.username %}To reset the password of your account {{ account }} on {{ site_name }}, please click the following link: {% endblocktrans %}
+{{ service_url }}{% url 'auth_password_reset_confirm' uidb36=uid token=token %}
-{% trans "Your username, in case you've forgotten:" %} {{ user.username }}
+{% trans "If you did not request it, just skip it." %}
{% trans "Hi," %}
-{% blocktrans %}You're receiving this e-mail because {{ email }} is sharing a file to you on {{ site_name }}.{% endblocktrans%} -
- -
-{% trans "Please go to the following page and view the file:" %}
+{% blocktrans %}{{ email }} shared a file to you on {{ site_name }}:{% endblocktrans%}
{{ file_shared_link }}
{% trans "Hi," %}
-{% blocktrans %}You're receiving this e-mail because {{ email }} has shared an upload link to you on {{ site_name }}.{% endblocktrans%} +{% blocktrans %}{{ email }} shared an upload link to you on {{ site_name }}.{% endblocktrans%}
diff --git a/seahub/templates/sysadmin/user_activation_email.html b/seahub/templates/sysadmin/user_activation_email.html new file mode 100644 index 0000000000..a6ce48ad09 --- /dev/null +++ b/seahub/templates/sysadmin/user_activation_email.html @@ -0,0 +1,19 @@ +{% extends 'email_base.html' %} + +{% load i18n %} + +{% block email_con %} + +{% autoescape off %} + +
{% trans "Hi," %}
+ ++{% blocktrans %}Your account {{ username }} on {{ site_name }} has been activated.{% endblocktrans %} +
+ +{% trans "Log In" %} + +{% endautoescape %} + +{% endblock %} diff --git a/seahub/templates/sysadmin/user_activation_email.txt b/seahub/templates/sysadmin/user_activation_email.txt deleted file mode 100644 index 56ca2b5dab..0000000000 --- a/seahub/templates/sysadmin/user_activation_email.txt +++ /dev/null @@ -1,10 +0,0 @@ -{% load i18n %}{% blocktrans %}You're receiving this e-mail because your account on {{site_name}} is activated by site admin.{% endblocktrans %} - -{% trans "Please click the following link to log in:" %} -{{login_url}} - -{% trans "Your username, in case you've forgotten:" %} {{ username }} - -{% trans "Thanks for using our site!" %} - -{% blocktrans %}The {{ site_name }} team{% endblocktrans %} diff --git a/seahub/templates/sysadmin/user_activation_email_subject.txt b/seahub/templates/sysadmin/user_activation_email_subject.txt deleted file mode 100644 index 7cfe762ed7..0000000000 --- a/seahub/templates/sysadmin/user_activation_email_subject.txt +++ /dev/null @@ -1 +0,0 @@ -{% load i18n %}{% blocktrans %}Your account on {{site_name}} is activated{% endblocktrans %} diff --git a/seahub/templates/sysadmin/user_add_email.html b/seahub/templates/sysadmin/user_add_email.html index 3638fdec2f..3398f4e70f 100644 --- a/seahub/templates/sysadmin/user_add_email.html +++ b/seahub/templates/sysadmin/user_add_email.html @@ -10,22 +10,19 @@{% if org %} -{% blocktrans with org_name=org.org_name %}You're receiving this e-mail because {{ user }} added you to organization "{{ org_name }}" on {{ site_name }}.{% endblocktrans%} +{% blocktrans with org_name=org.org_name %}{{ user }} invited you to join organization "{{ org_name }}" on {{ site_name }}.{% endblocktrans%} {% else %} -{% blocktrans %}You're receiving this e-mail because {{ user }} added you to {{ site_name }}.{% endblocktrans%} +{% blocktrans %}{{ user }} invited you to join {{ site_name }}.{% endblocktrans%} {% endif %}
-{% trans "Following is your account information:" %}
+{% trans "Here is your account information:" %}
{% blocktrans %}Email: {{ email }}{% endblocktrans %}
-{% blocktrans %}Password: {{ password }}{% endblocktrans %}
+{% blocktrans %}Password: {{ password }}{% endblocktrans %}
-{% trans "Please go to the following page and log in:" %}
-{{ protocol }}://{{ domain }}{% url 'auth_login' %}
-
{% trans "Hi," %}
-{% blocktrans %}You're receiving this e-mail because staff has reset your password at {{ site_name }}. {% endblocktrans %} -
- --{% blocktrans %}Your new password is {{ password }}, please modify your password as soon as possible.{% endblocktrans %} +{% blocktrans %}Your password on {{ site_name }} has been reset. Now it is {{ password }}. Please change it as soon as possible. {% endblocktrans %}
{% endautoescape %} diff --git a/seahub/views/__init__.py b/seahub/views/__init__.py index 28303151e4..6eb2875769 100644 --- a/seahub/views/__init__.py +++ b/seahub/views/__init__.py @@ -18,7 +18,6 @@ from urllib import quote from django.core.cache import cache from django.core.urlresolvers import reverse -from django.core.mail import send_mail from django.contrib import messages from django.contrib.sites.models import Site, RequestSite from django.db import IntegrityError diff --git a/seahub/views/sysadmin.py b/seahub/views/sysadmin.py index db841d2f4c..12ef117c08 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -33,7 +33,7 @@ from seahub.share.models import FileShare import seahub.settings as settings from seahub.settings import INIT_PASSWD, \ SEND_EMAIL_ON_ADDING_SYSTEM_MEMBER, SEND_EMAIL_ON_RESETTING_USER_PASSWD -from seahub.utils import get_site_scheme_and_netloc +from seahub.utils import get_site_scheme_and_netloc, get_service_url logger = logging.getLogger(__name__) @@ -407,20 +407,21 @@ def user_deactivate(request, user_id): def email_user_on_activation(user): """Send an email to user when admin activate his/her account. """ - ctx_dict = { - "site_name": settings.SITE_NAME, - "login_url": "%s%s" % (get_site_scheme_and_netloc(), - reverse('auth_login')), - "username": user.email, + service_url = get_service_url() + site_name = settings.SITE_NAME + + t = loader.get_template('sysadmin/user_activation_email.html') + c = { + 'site_name': site_name, + 'media_url': settings.MEDIA_URL, + 'logo_path': settings.LOGO_PATH, + 'service_url': service_url, + 'username': user.email, } - subject = render_to_string('sysadmin/user_activation_email_subject.txt', - ctx_dict) - # Email subject *must not* contain newlines - subject = ''.join(subject.splitlines()) - - message = render_to_string('sysadmin/user_activation_email.txt', ctx_dict) - - user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL) + msg = EmailMessage(_(u'Your account on s% is activated') % site_name, t.render(Context(c)), + None, [user.email]) + msg.content_subtype = "html" + msg.send() @login_required @sys_staff_required @@ -459,22 +460,19 @@ def send_user_reset_email(request, email, password): Send email when reset user password. """ - use_https = request.is_secure() - domain = RequestSite(request).domain + service_url = get_service_url() + site_name = settings.SITE_NAME t = loader.get_template('sysadmin/user_reset_email.html') c = { 'email': email, 'password': password, - 'site_name': settings.SITE_NAME, - 'media_url': settings.MEDIA_URL, - 'logo_path': settings.LOGO_PATH, - 'domain': domain, - 'protocol': use_https and 'https' or 'http', + 'site_name': site_name, 'media_url': settings.MEDIA_URL, 'logo_path': settings.LOGO_PATH, + 'service_url': service_url, } - msg = EmailMessage(_(u'Password Reset'), t.render(Context(c)), + msg = EmailMessage(_(u'Password has been reset on %s') % site_name, t.render(Context(c)), None, [email]) msg.content_subtype = "html" msg.send() @@ -519,22 +517,21 @@ def user_reset(request, user_id): def send_user_add_mail(request, email, password): """Send email when add new user.""" - use_https = request.is_secure() - domain = RequestSite(request).domain - + service_url = get_service_url() + site_name = settings.SITE_NAME + t = loader.get_template('sysadmin/user_add_email.html') c = { 'user': request.user.username, 'org': request.user.org, 'email': email, 'password': password, - 'domain': domain, - 'protocol': use_https and 'https' or 'http', - 'site_name': settings.SITE_NAME, + 'service_url': service_url, + 'site_name': site_name, 'media_url': settings.MEDIA_URL, 'logo_path': settings.LOGO_PATH, } - msg = EmailMessage(_(u'Seafile Registration Information'), t.render(Context(c)), + msg = EmailMessage(_(u'You are invited to join %s') % site_name, t.render(Context(c)), None, [email]) msg.content_subtype = "html" msg.send()