mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-19 18:29:23 +00:00
[sysadmin] Email user when admin activate his/her account
This commit is contained in:
10
seahub/templates/sysadmin/user_activation_email.txt
Normal file
10
seahub/templates/sysadmin/user_activation_email.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
{% 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 %}
|
@@ -0,0 +1 @@
|
||||
{% load i18n %}{% blocktrans %}Your account on {{site_name}} is activated{% endblocktrans %}
|
@@ -44,10 +44,18 @@ $('.user-status-select').change(function() {
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
success: function(data) {
|
||||
if (data['success']) {
|
||||
if (data['email_sent']) {
|
||||
feedback("{% trans "Edit succeeded, an email has been sent." %}", 'success');
|
||||
select.prev().children('.user-status-cur-value').html(select.children('option[value="' +select.val() + '"]').text());
|
||||
|
||||
} else if (data['email_sent'] === false) {
|
||||
feedback("{% trans "Edit succeeded, but failed to send email, please check your email configuration." %}", 'success');
|
||||
select.prev().children('.user-status-cur-value').html(select.children('option[value="' +select.val() + '"]').text());
|
||||
} else {
|
||||
feedback("{% trans "Edit succeeded" %}", 'success');
|
||||
select.prev().children('.user-status-cur-value').html(select.children('option[value="' +select.val() + '"]').text());
|
||||
}
|
||||
|
||||
select.addClass('hide');
|
||||
select.prev().removeClass('hide');
|
||||
},
|
||||
|
@@ -10,6 +10,7 @@ import tempfile
|
||||
import locale
|
||||
import ConfigParser
|
||||
from datetime import datetime
|
||||
from urlparse import urlparse
|
||||
|
||||
import ccnet
|
||||
|
||||
@@ -802,6 +803,18 @@ def get_service_url():
|
||||
"""
|
||||
return SERVICE_URL
|
||||
|
||||
def get_site_scheme_and_netloc():
|
||||
"""Return a string contains site scheme and network location part from
|
||||
service url.
|
||||
|
||||
For example:
|
||||
>>> get_site_scheme_and_netloc("https://example.com:8000/seafile/")
|
||||
https://example.com:8000
|
||||
|
||||
"""
|
||||
parse_result = urlparse(get_service_url())
|
||||
return "%s://%s" % (parse_result.scheme, parse_result.netloc)
|
||||
|
||||
def gen_dir_share_link(token):
|
||||
"""Generate directory share link.
|
||||
"""
|
||||
|
@@ -11,6 +11,7 @@ from django.contrib import messages
|
||||
from django.http import HttpResponse, Http404, HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template import Context, loader, RequestContext
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.contrib.sites.models import RequestSite
|
||||
|
||||
@@ -30,6 +31,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
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -302,6 +304,24 @@ def user_deactivate(request, user_id):
|
||||
|
||||
return HttpResponseRedirect(next)
|
||||
|
||||
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,
|
||||
}
|
||||
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)
|
||||
|
||||
@login_required
|
||||
@sys_staff_required
|
||||
def user_toggle_status(request, user_id):
|
||||
@@ -316,6 +336,18 @@ def user_toggle_status(request, user_id):
|
||||
user = User.objects.get(id=int(user_id))
|
||||
user.is_active = bool(user_status)
|
||||
user.save()
|
||||
|
||||
if user.is_active is True:
|
||||
try:
|
||||
email_user_on_activation(user)
|
||||
email_sent = True
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
email_sent = False
|
||||
|
||||
return HttpResponse(json.dumps({'success': True,
|
||||
'email_sent': email_sent,
|
||||
}), content_type=content_type)
|
||||
return HttpResponse(json.dumps({'success': True}),
|
||||
content_type=content_type)
|
||||
except User.DoesNotExist:
|
||||
|
@@ -298,7 +298,7 @@ from django.dispatch import receiver
|
||||
from django.utils.http import urlquote
|
||||
|
||||
from registration.signals import user_registered
|
||||
from seahub.utils import get_service_url
|
||||
from seahub.utils import get_site_scheme_and_netloc
|
||||
|
||||
# Get an instance of a logger
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -318,7 +318,7 @@ def email_admin_on_registration(sender, **kwargs):
|
||||
ctx_dict = {
|
||||
"site_name": settings.SITE_NAME,
|
||||
"user_search_link": "%s%s?email=%s" % (
|
||||
get_service_url().rstrip('/'), reverse("user_search"),
|
||||
get_site_scheme_and_netloc(), reverse("user_search"),
|
||||
urlquote(reg_email)),
|
||||
}
|
||||
subject = render_to_string('registration/activate_request_email_subject.txt',
|
||||
|
Reference in New Issue
Block a user