mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-19 18:29:23 +00:00
Email admin to activate newly registered account
This commit is contained in:
@@ -36,7 +36,23 @@ class UserManager(object):
|
||||
def create_superuser(self, email, password):
|
||||
u = self.create_user(email, password, is_staff=True, is_active=True)
|
||||
return u
|
||||
|
||||
|
||||
def get_superusers(self):
|
||||
"""Return a list of admins.
|
||||
"""
|
||||
emailusers = ccnet_threaded_rpc.get_superusers()
|
||||
|
||||
user_list = []
|
||||
for e in emailusers:
|
||||
user = User(e.email)
|
||||
user.id = e.id
|
||||
user.is_staff = e.is_staff
|
||||
user.is_active = e.is_active
|
||||
user.ctime = e.ctime
|
||||
user_list.append(user)
|
||||
|
||||
return user_list
|
||||
|
||||
def get(self, email=None, id=None):
|
||||
if not email and not id:
|
||||
raise User.DoesNotExist, 'User matching query does not exits.'
|
||||
|
6
seahub/templates/registration/activate_request_email.txt
Normal file
6
seahub/templates/registration/activate_request_email.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
{% load i18n %} {% blocktrans %}You're receiving this e-mail because you are the admin of {{site_name }}, and a newly registered account need to be activated.{% endblocktrans%}
|
||||
|
||||
{% trans "Please click the following link to active the new account:" %}
|
||||
{{ user_search_link }}
|
||||
|
||||
|
@@ -0,0 +1 @@
|
||||
{% load i18n %}{% blocktrans %}New account need activated on {{site_name}}{% endblocktrans %}
|
@@ -289,3 +289,49 @@ class RegistrationProfile(models.Model):
|
||||
except User.DoesNotExist:
|
||||
pass
|
||||
|
||||
|
||||
########## signal handlers
|
||||
import logging
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.dispatch import receiver
|
||||
from django.utils.http import urlquote
|
||||
|
||||
from registration.signals import user_registered
|
||||
from seahub.utils import get_service_url
|
||||
|
||||
# Get an instance of a logger
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@receiver(user_registered)
|
||||
def email_admin_on_registration(sender, **kwargs):
|
||||
"""Send an email notification to admin when a newly registered user need
|
||||
activate.
|
||||
|
||||
This email will be sent when both ``ACTIVATE_AFTER_REGISTRATION`` and
|
||||
``REGISTRATION_SEND_MAIL`` are set to False.
|
||||
"""
|
||||
if settings.ACTIVATE_AFTER_REGISTRATION is False and \
|
||||
settings.REGISTRATION_SEND_MAIL is False:
|
||||
reg_email = kwargs['user'].email
|
||||
|
||||
ctx_dict = {
|
||||
"site_name": settings.SITE_NAME,
|
||||
"user_search_link": "%s%s?email=%s" % (
|
||||
get_service_url().rstrip('/'), reverse("user_search"),
|
||||
urlquote(reg_email)),
|
||||
}
|
||||
subject = render_to_string('registration/activate_request_email_subject.txt',
|
||||
ctx_dict)
|
||||
# Email subject *must not* contain newlines
|
||||
subject = ''.join(subject.splitlines())
|
||||
|
||||
message = render_to_string('registration/activate_request_email.txt',
|
||||
ctx_dict)
|
||||
|
||||
admins = User.objects.get_superusers()
|
||||
for admin in admins:
|
||||
try:
|
||||
admin.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
|
Reference in New Issue
Block a user