Browse Source

[Update] 修改只有local用户需要发送创建成功邮件、发送密码过期邮件;

pull/3775/head
Bai 5 years ago
parent
commit
04945809a5
  1. 5
      apps/users/models/user.py
  2. 2
      apps/users/signals_handler.py
  3. 6
      apps/users/tasks.py

5
apps/users/models/user.py

@ -596,6 +596,11 @@ class User(AuthMixin, TokenMixin, RoleMixin, MFAMixin, AbstractUser):
user.save()
user.groups.add(UserGroup.initial())
def can_send_created_mail(self):
if self.email and self.source == self.SOURCE_LOCAL:
return True
return False
@classmethod
def generate_fake(cls, count=100):
from random import seed, choice

2
apps/users/signals_handler.py

@ -17,7 +17,7 @@ def on_user_create(sender, user=None, **kwargs):
logger.debug("Receive user `{}` create signal".format(user.name))
from .utils import send_user_created_mail
logger.info(" - Sending welcome mail ...".format(user.name))
if user.email:
if user.can_send_created_mail():
send_user_created_mail(user)

6
apps/users/tasks.py

@ -22,15 +22,15 @@ logger = get_logger(__file__)
@shared_task
def check_password_expired():
users = User.objects.exclude(role=User.ROLE_APP)
users = User.objects.filter(source=User.SOURCE_LOCAL).exclude(role=User.ROLE_APP)
for user in users:
if not user.is_valid:
continue
if not user.password_will_expired:
continue
send_password_expiration_reminder_mail(user)
msg = "The user {} password expires in {} days"
logger.info(msg.format(user, user.password_expired_remain_days))
send_password_expiration_reminder_mail(user)
@shared_task
@ -55,6 +55,8 @@ def check_user_expired():
continue
if not user.will_expired:
continue
msg = "The user {} will expires in {} days"
logger.info(msg.format(user, user.expired_remain_days))
send_user_expiration_reminder_mail(user)

Loading…
Cancel
Save