1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-20 19:08:21 +00:00

[html email] added html email for user add/passwd_reset, link share

This commit is contained in:
llj
2014-02-17 19:43:16 +08:00
parent 2a38fbd6a8
commit 9f67f09ee5
9 changed files with 127 additions and 47 deletions

View File

@@ -11,6 +11,8 @@ from seahub.utils import IS_EMAIL_CONFIGURED
from captcha.fields import CaptchaField from captcha.fields import CaptchaField
import seahub.settings as settings
class AuthenticationForm(forms.Form): class AuthenticationForm(forms.Form):
""" """
Base class for authenticating users. Extend this to get a form that accepts Base class for authenticating users. Extend this to get a form that accepts
@@ -84,7 +86,6 @@ class PasswordResetForm(forms.Form):
""" """
Generates a one-use only link for resetting password and sends to the user Generates a one-use only link for resetting password and sends to the user
""" """
#from django.core.mail import send_mail
from django.core.mail import EmailMessage from django.core.mail import EmailMessage
user = self.users_cache user = self.users_cache
@@ -104,6 +105,8 @@ class PasswordResetForm(forms.Form):
'user': user, 'user': user,
'token': token_generator.make_token(user), 'token': token_generator.make_token(user),
'protocol': use_https and 'https' or 'http', 'protocol': use_https and 'https' or 'http',
'media_url': settings.MEDIA_URL,
'logo_path': settings.LOGO_PATH,
} }
msg = EmailMessage(_("Password reset on %s") % site_name, msg = EmailMessage(_("Password reset on %s") % site_name,

View File

@@ -2,7 +2,7 @@
import os import os
import logging import logging
import simplejson as json import simplejson as json
from django.core.mail import send_mail from django.core.mail import EmailMessage
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db import IntegrityError from django.db import IntegrityError
from django.http import HttpResponse, HttpResponseRedirect, Http404, \ from django.http import HttpResponse, HttpResponseRedirect, Http404, \
@@ -39,6 +39,7 @@ from seahub.utils import render_permission_error, string2list, render_error, \
gen_file_share_link, IS_EMAIL_CONFIGURED, check_filename_with_rename, \ gen_file_share_link, IS_EMAIL_CONFIGURED, check_filename_with_rename, \
get_repo_last_modify, is_valid_username get_repo_last_modify, is_valid_username
import seahub.settings as settings
try: try:
from seahub.settings import CLOUD_MODE from seahub.settings import CLOUD_MODE
except ImportError: except ImportError:
@@ -799,17 +800,24 @@ def send_shared_link(request):
mail_sended.send(sender=None, user=request.user.username, mail_sended.send(sender=None, user=request.user.username,
email=to_email) email=to_email)
use_https = request.is_secure()
domain = RequestSite(request).domain
c = { c = {
'email': request.user.username, 'email': request.user.username,
'to_email': to_email, 'to_email': to_email,
'file_shared_link': file_shared_link, 'file_shared_link': file_shared_link,
'site_name': SITE_NAME, 'site_name': SITE_NAME,
'domain': domain,
'protocol': use_https and 'https' or 'http',
'media_url': settings.MEDIA_URL,
'logo_path': settings.LOGO_PATH,
} }
try: try:
send_mail(_(u'Your friend shared a file to you on Seafile'), msg = EmailMessage(_(u'Your friend shared a file to you on Seafile'),
t.render(Context(c)), None, [to_email], t.render(Context(c)), None, [to_email])
fail_silently=False) msg.content_subtype = "html"
msg.send()
except Exception, e: except Exception, e:
logger.error(str(e)) logger.error(str(e))
data = json.dumps({'error':_(u'Internal server error. Send failed.')}) data = json.dumps({'error':_(u'Internal server error. Send failed.')})
@@ -1073,17 +1081,25 @@ def send_shared_upload_link(request):
mail_sended.send(sender=None, user=request.user.username, mail_sended.send(sender=None, user=request.user.username,
email=to_email) email=to_email)
use_https = request.is_secure()
domain = RequestSite(request).domain
c = { c = {
'email': request.user.username, 'email': request.user.username,
'to_email': to_email, 'to_email': to_email,
'shared_upload_link': shared_upload_link, 'shared_upload_link': shared_upload_link,
'site_name': SITE_NAME, 'site_name': SITE_NAME,
'domain': domain,
'protocol': use_https and 'https' or 'http',
'media_url': settings.MEDIA_URL,
'logo_path': settings.LOGO_PATH,
} }
try: try:
send_mail(_(u'Your friend shared a upload link to you on Seafile'), msg = EmailMessage(_(u'Your friend shared a upload link to you on Seafile'),
t.render(Context(c)), None, [to_email], t.render(Context(c)), None, [to_email])
fail_silently=False) msg.content_subtype = "html"
msg.send()
except Exception, e: except Exception, e:
logger.error(str(e)) logger.error(str(e))
data = json.dumps({'error':_(u'Internal server error. Send failed.')}) data = json.dumps({'error':_(u'Internal server error. Send failed.')})

View File

@@ -1,8 +1,17 @@
{% load i18n %}
<div style="background:#f2f2f2;padding:40px 0;"> <div style="background:#f2f2f2;padding:40px 0;">
<div style="width:700px;background:#fff;border-style:solid;border-width:1px;border-color:#eaeaea #cccccc #a6a6a6;border-radius:4px;box-shadow:0 2px 2px #cdcdcd;margin:0 auto;"> <div style="width:700px;background:#fff;border-style:solid;border-width:1px;border-color:#eaeaea #cccccc #a6a6a6;border-radius:4px;box-shadow:0 2px 2px #cdcdcd;margin:0 auto;">
<img src="https://dev.seafile.com/seahub/media/img/seafile_logo.png" alt="" style="display:block;margin:20px 0 15px 50px;" /> <img src="{{ protocol }}://{{domain}}{{media_url}}{{logo_path}}" alt="" style="display:block;margin:20px 0 15px 50px;" />
<div style="padding:30px 55px 40px;min-height:300px;border-top:1px solid #efefef;box-shadow:inset 0 30px 30px #fcfcfc;"> <div style="padding:30px 55px 40px;min-height:300px;border-top:1px solid #efefef;box-shadow:inset 0 30px 30px #fcfcfc;">
{% block email_con %}{% endblock %} {% block email_con %}{% endblock %}
<p style="font-size:14px;color:#434144;margin:30px 0;">
{% trans "Thanks for using our site!" %}
</p>
<p style="font-size:14px;color:#434144;">
{% blocktrans %}The {{ site_name }} team{% endblocktrans %}
</p>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -21,14 +21,6 @@
{% trans "Your username, in case you've forgotten:" %} {{ user.username }} {% trans "Your username, in case you've forgotten:" %} {{ user.username }}
</p> </p>
<p style="font-size:14px;color:#434144;margin:30px 0;">
{% trans "Thanks for using our site!" %}
</p>
<p style="font-size:14px;color:#434144;">
{% blocktrans %}The {{ site_name }} team{% endblocktrans %}
</p>
{% endautoescape %} {% endautoescape %}
{% endblock %} {% endblock %}

View File

@@ -1,11 +1,22 @@
{% load i18n %}{% autoescape off %} {% extends 'email_base.html' %}
{% load i18n %}
{% block email_con %}
{% autoescape off %}
<p style="color:#121214;font-size:14px;">{% trans "Hi," %}</p>
<p style="font-size:14px;color:#434144;">
{% blocktrans %}You're receiving this e-mail because {{ email }} is sharing a file to you on {{ site_name }}.{% endblocktrans%} {% blocktrans %}You're receiving this e-mail because {{ email }} is sharing a file to you on {{ site_name }}.{% endblocktrans%}
</p>
{% trans "Please go to the following page and view the file:" %} <p style="font-size:14px;color:#434144;">
{% trans "Please go to the following page and view the file:" %}<br />
{{ file_shared_link }} {{ file_shared_link }}
</p>
{% trans "Thanks for using our site!" %}
{% blocktrans %}The {{ site_name }} team{% endblocktrans %}
{% endautoescape %} {% endautoescape %}
{% endblock %}

View File

@@ -1,11 +1,20 @@
{% load i18n %}{% autoescape off %} {% extends 'email_base.html' %}
{% load i18n %}
{% block email_con %}
{% autoescape off %}
<p style="color:#121214;font-size:14px;">{% trans "Hi," %}</p>
<p style="font-size:14px;color:#434144;">
{% blocktrans %}You're receiving this e-mail because {{ email }} has shared an upload link to you on {{ site_name }}.{% endblocktrans%} {% blocktrans %}You're receiving this e-mail because {{ email }} has shared an upload link to you on {{ site_name }}.{% endblocktrans%}
</p>
{% trans "You can go to the following page and upload your files:" %} <p style="font-size:14px;color:#434144;">
{% trans "You can go to the following page and upload your files:" %}<br />
{{ shared_upload_link }} {{ shared_upload_link }}
</p>
{% trans "Thanks for using our site!" %}
{% blocktrans %}The {{ site_name }} team{% endblocktrans %}
{% endautoescape %} {% endautoescape %}
{% endblock %}

View File

@@ -1,19 +1,32 @@
{% load i18n %}{% autoescape off %} {% extends 'email_base.html' %}
{% load i18n %}
{% block email_con %}
{% autoescape off %}
<p style="color:#121214;font-size:14px;">{% trans "Hi," %}</p>
<p style="font-size:14px;color:#434144;">
{% if org %} {% 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 %}You're receiving this e-mail because {{ user }} added you to organization "{{ org_name }}" on {{ site_name }}.{% endblocktrans%}
{% else %} {% else %}
{% blocktrans %}You're receiving this e-mail because {{ user }} added you to {{ site_name }}.{% endblocktrans%} {% blocktrans %}You're receiving this e-mail because {{ user }} added you to {{ site_name }}.{% endblocktrans%}
{% endif %} {% endif %}
</p>
{% trans "Following is your account information:" %} <p style="font-size:14px;color:#434144;">
{% blocktrans %}Email: {{ email }}{% endblocktrans %} {% trans "Following is your account information:" %}<br />
{% blocktrans %}Email: {{ email }}{% endblocktrans %}<br />
{% blocktrans %}Password: {{ password }}{% endblocktrans %} {% blocktrans %}Password: {{ password }}{% endblocktrans %}
</p>
{% trans "Please go to the following page and log in:" %} <p style="font-size:14px;color:#434144;">
{% trans "Please go to the following page and log in:" %}<br />
{{ protocol }}://{{ domain }}{% url 'auth_login' %} {{ protocol }}://{{ domain }}{% url 'auth_login' %}
</p>
{% trans "Thanks for using our site!" %}
{% blocktrans %}The {{ site_name }} team{% endblocktrans %}
{% endautoescape %} {% endautoescape %}
{% endblock %}

View File

@@ -1,10 +1,21 @@
{% load i18n %}{% autoescape off %} {% extends 'email_base.html' %}
{% load i18n %}
{% block email_con %}
{% autoescape off %}
<p style="color:#121214;font-size:14px;">{% trans "Hi," %}</p>
<p style="font-size:14px;color:#434144;">
{% blocktrans %}You're receiving this e-mail because staff has reset your password at {{ site_name }}. {% endblocktrans %} {% blocktrans %}You're receiving this e-mail because staff has reset your password at {{ site_name }}. {% endblocktrans %}
</p>
<p style="font-size:14px;color:#434144;">
{% blocktrans %}Your new password is {{ password }}, please modify your password as soon as possible.{% endblocktrans %} {% blocktrans %}Your new password is {{ password }}, please modify your password as soon as possible.{% endblocktrans %}
</p>
{% trans "Thanks for using our site!" %}
{% blocktrans %}The {{ site_name }} team{% endblocktrans %}
{% endautoescape %} {% endautoescape %}
{% endblock %}

View File

@@ -6,7 +6,7 @@ import logging
import simplejson as json import simplejson as json
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.core.mail import send_mail from django.core.mail import EmailMessage
from django.contrib import messages from django.contrib import messages
from django.http import HttpResponse, Http404, HttpResponseRedirect from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
@@ -459,14 +459,25 @@ def send_user_reset_email(request, email, password):
Send email when reset user password. Send email when reset user password.
""" """
use_https = request.is_secure()
domain = RequestSite(request).domain
t = loader.get_template('sysadmin/user_reset_email.html') t = loader.get_template('sysadmin/user_reset_email.html')
c = { c = {
'email': email, 'email': email,
'password': password, 'password': password,
'site_name': settings.SITE_NAME, 'site_name': settings.SITE_NAME,
'media_url': settings.MEDIA_URL,
'logo_path': settings.LOGO_PATH,
'domain': domain,
'protocol': use_https and 'https' or 'http',
'media_url': settings.MEDIA_URL,
'logo_path': settings.LOGO_PATH,
} }
send_mail(_(u'Password Reset'), t.render(Context(c)), msg = EmailMessage(_(u'Password Reset'), t.render(Context(c)),
None, [email], fail_silently=False) None, [email])
msg.content_subtype = "html"
msg.send()
@login_required @login_required
@sys_staff_required @sys_staff_required
@@ -520,9 +531,14 @@ def send_user_add_mail(request, email, password):
'domain': domain, 'domain': domain,
'protocol': use_https and 'https' or 'http', 'protocol': use_https and 'https' or 'http',
'site_name': settings.SITE_NAME, 'site_name': settings.SITE_NAME,
'media_url': settings.MEDIA_URL,
'logo_path': settings.LOGO_PATH,
} }
send_mail(_(u'Seafile Registration Information'), t.render(Context(c)), msg = EmailMessage(_(u'Seafile Registration Information'), t.render(Context(c)),
None, [email], fail_silently=False) None, [email])
msg.content_subtype = "html"
msg.send()
@login_required @login_required
def user_add(request): def user_add(request):