-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
密码即将过期邮件提醒 #117
Comments
配置部分
请求地址/api/v2/categories/<int: category_id>/settings/namespaces/notification/ 请求方法GET 响应{
"result": true,
"code": 0,
"message": "success",
"data": [
{
"key": "expired_sms_config",
"value": {
"sender": "蓝鲸智云企业版",
"content": "【蓝鲸智云企业版】密码到期提醒!{username}您好!您的蓝鲸智云企业版平台密码已过期,为避免影响使用,请尽快登陆平台({url})修改密码。"
},
"namespace": "notification",
"region": "default",
"enabled": true
},
{
"key": "be_about_to_expire_sms_config",
"value": {
"sender": "蓝鲸智云企业版",
"content": "【蓝鲸智云企业版】密码到期提醒!{username},您好,您的蓝鲸平台密码将于{expire_at}天后到期,为避免影响使用,请尽快登陆平台({url})修改密码。"
},
"namespace": "notification",
"region": "default",
"enabled": true
},
{
"key": "expired_email_config",
"value": {
"title": "【蓝鲸智云企业版】密码到期提醒",
"sender": "蓝鲸智云企业版",
"content": "{username},您好!您的蓝鲸智云企业版平台密码已过期,为避免影响使用,请尽快登陆平台({url})修改密码。蓝鲸智云平台用户管理处"
},
"namespace": "notification",
"region": "default",
"enabled": true
},
{
"key": "be_about_to_expire_email_config",
"value": {
"title": "【蓝鲸智云企业版】密码到期提醒",
"sender": "蓝鲸智云企业版",
"content": "{username},您好!您的蓝鲸智云企业版平台密码将于{expire_at}天后到期,为避免影响使用,请尽快登陆平台({url})修改密码。蓝鲸智云平台用户管理处"
},
"namespace": "notification",
"region": "default",
"enabled": true
},
{
"key": "notice_time",
"value": [
1,
7,
15
],
"namespace": "notification",
"region": "default",
"enabled": true
},
{
"key": "notice_method",
"value": [
"send_email",
"send_sms"
],
"namespace": "notification",
"region": "default",
"enabled": true
}
]
}
请求地址/api/v2/categories/<int: category_id>/settings/namespaces/notification/ 请求方法PUT 请求参数[
{
"key": "notice_method",
"value": "[send_sms]",
"region": "default"
},
{
"key": "notice_time",
"value": [
3,
5,
7
],
"region": "default"
},
{
"key": "be_about_to_expire_email_config",
"value": {
"title": "【蓝鲸智云企业版】密码到期提醒",
"sender": "蓝鲸智云企业版",
"content": "{username},您好yya!您的蓝鲸智云企业版平台密码将于{expire_at}天后到期,为避免影响使用,请尽快登陆平台({url})修改密码。蓝鲸智云平台用户管理处"
},
"region": "default"
},
{
"key": "expired_email_config",
"value": {
"title": "【蓝鲸智云企业版】密码到期提醒",
"sender": "蓝鲸智云企业版",
"content": "{username},您好!您的蓝鲸智云企业版平台密码已过期,为避免影响使用,请尽快登陆平台({url})修改密码。蓝鲸智云平台用户管理处"
},
"region": "default"
},
{
"key": "be_about_to_expire_sms_config",
"value": {
"sender": "蓝鲸智云企业版",
"content": "【蓝鲸智云企业版】密码到期提醒!{username},您好,您的蓝鲸平台密码将于{expire_at}天后到期,为避免影响使用,请尽快登陆平台({url})修改密码。"
},
"region": "default"
},
{
"key": "expired_sms_config",
"value": {
"sender": "蓝鲸智云企业版",
"content": "【蓝鲸智云企业版】密码到期提醒!{username}您好!您的蓝鲸智云企业版平台密码已过期,为避免影响使用,请尽快登陆平台({url})修改密码。"
},
"region": "default"
}
] 响应{
"result": true,
"code": 0,
"message": "success",
"data": [
{
"key": "notice_method",
"value": "[send_sms]",
"namespace": "notification",
"region": "default",
"enabled": true
},
{
"key": "notice_time",
"value": [
3,
5,
7
],
"namespace": "notification",
"region": "default",
"enabled": true
},
{
"key": "be_about_to_expire_email_config",
"value": {
"title": "【蓝鲸智云企业版】密码到期提醒",
"sender": "蓝鲸智云企业版",
"content": "{username},您好yya!您的蓝鲸智云企业版平台密码将于{expire_at}天后到期,为避免影响使用,请尽快登陆平台({url})修改密码。蓝鲸智云平台用户管理处"
},
"namespace": "notification",
"region": "default",
"enabled": true
},
{
"key": "expired_email_config",
"value": {
"title": "【蓝鲸智云企业版】密码到期提醒",
"sender": "蓝鲸智云企业版",
"content": "{username},您好!您的蓝鲸智云企业版平台密码已过期,为避免影响使用,请尽快登陆平台({url})修改密码。蓝鲸智云平台用户管理处"
},
"namespace": "notification",
"region": "default",
"enabled": true
},
{
"key": "be_about_to_expire_sms_config",
"value": {
"sender": "蓝鲸智云企业版",
"content": "【蓝鲸智云企业版】密码到期提醒!{username},您好,您的蓝鲸平台密码将于{expire_at}天后到期,为避免影响使用,请尽快登陆平台({url})修改密码。"
},
"namespace": "notification",
"region": "default",
"enabled": true
},
{
"key": "expired_sms_config",
"value": {
"sender": "蓝鲸智云企业版",
"content": "【蓝鲸智云企业版】密码到期提醒!{username}您好!您的蓝鲸智云企业版平台密码已过期,为避免影响使用,请尽快登陆平台({url})修改密码。"
},
"namespace": "notification",
"region": "default",
"enabled": true
}
]
}
通知部分思路:
@periodic_task(run_every=48000)
def notice_for_password_expiration():
category_id = ProfileCategory.objects.filter(type=CategoryType.LOCAL.value).id
# 获取本地目录下所有 password_valid_days>0 的所有用户
local_profiles = Profile.objects.filter(category_id=category_id, password_valid_days__gt=0)
for profile in local_profiles:
Notification(profile=profile).handler()
class Notification:
def __init__(self, config_loader, profile):
self.config_loader = config_loader
self.profile = profile
self.url = settings.LOGIN_REDIRECT_TO 2.2 Notification类中定义handler方法,根据用户目录配置的通知方法,执行Notification类下定义的通知方法 def handler(self):
notice_method_map = {
"send_email": self._notice_by_email,
"send_sms": self._notice_by_sms,
}
for notice_method in self.config_loader["notice_methods"]:
notice_method_map[notice_method]() 2.3 Notification类中定义_notice_by_email方法,实现邮件通知用户 def _notice_by_email(self):
# 判断用户密码为过期状态还是处于通知配置中的有效期
if 密码过期:
email_config=xxx
if 密码有效期 in config_loader["notice_time"]:
email_config=yyy
send_mail(
sender=email_config["sender"],
receivers=[self.profile.email],
message=message,
title=email_config["title"],
) 2.4 Notification类中定义_notice_by_sms方法,实现使用短信通知用户 def _notice_by_sms(self):
# 判断用户密码为过期状态还是处于通知配置中的有效期
if 密码过期:
sms_config=xxx
if 密码有效期 in config_loader["notice_time"]:
sms_config=yyy
send_sms(
sender=sms_config["sender"],
receivers=[self.profile.telephone],
message=message
)
|
密码过期这里,我感觉需要评估一下,我们是否需要有一些防御机制:
|
密码过期需求调整如下: |
用户管理消息通知整合: |
【排期】 |
确认是否可以关闭 |
对应需求代码已经合入,可以关闭 |
No description provided.
The text was updated successfully, but these errors were encountered: