feat: 三方认证绑定发通知

pull/7486/head
xinwen 3 years ago committed by 老广
parent dde7559f47
commit 1e3a15a3d0

@ -1,9 +1,9 @@
from django.utils import timezone
from django.utils.translation import ugettext as _
from django.template.loader import render_to_string
from notifications.notifications import UserMessage
from common.utils import get_logger
from common.utils.timezone import local_now_display
logger = get_logger(__file__)
@ -15,8 +15,7 @@ class DifferentCityLoginMessage(UserMessage):
super().__init__(user)
def get_html_msg(self) -> dict:
now_local = timezone.localtime(timezone.now())
now = now_local.strftime("%Y-%m-%d %H:%M:%S")
now = local_now_display()
subject = _('Different city login reminder')
context = dict(
subject=subject,
@ -39,3 +38,36 @@ class DifferentCityLoginMessage(UserMessage):
ip = '8.8.8.8'
city = '洛杉矶'
return cls(user, ip, city)
class OAuthBindMessage(UserMessage):
def __init__(self, user, ip, oauth_name, oauth_id):
super().__init__(user)
self.ip = ip
self.oauth_name = oauth_name
self.oauth_id = oauth_id
def get_html_msg(self) -> dict:
now = local_now_display()
subject = self.oauth_name + _('binding reminder')
context = dict(
subject=subject,
name=self.user.name,
username=self.user.username,
ip=self.ip,
time=now,
oauth_name=self.oauth_name,
oauth_id=self.oauth_id
)
message = render_to_string('authentication/_msg_oauth_bind.html', context)
return {
'subject': subject,
'message': message
}
@classmethod
def gen_test_msg(cls):
from users.models import User
user = User.objects.first()
ip = '8.8.8.8'
return cls(user, ip, _('WeCom'), '000000')

@ -0,0 +1,18 @@
{% load i18n %}
<p>
{% trans 'Hello' %} {{ name }},
</p>
<p>
{% trans 'Your account has just been bound to' %} {{ oauth_name }}
</p>
<p>
<b>{% trans 'Username' %}:</b> {{ username }}<br>
<b>{{ oauth_name }}:</b> {{ oauth_id }}<br>
<b>{% trans 'Time' %}:</b> {{ time }}<br>
<b>{% trans 'IP' %}:</b> {{ ip }}
</p>
-
<p>
{% trans 'If the operation is not your own, unbind and change the password.' %}
</p>

@ -19,6 +19,8 @@ from common.mixins.views import PermissionsMixin
from authentication import errors
from authentication.mixins import AuthMixin
from common.sdk.im.dingtalk import DingTalk
from common.utils.common import get_request_ip
from authentication.notifications import OAuthBindMessage
logger = get_logger(__file__)
@ -154,6 +156,8 @@ class DingTalkQRBindCallbackView(DingTalkQRMixin, View):
return response
raise e
ip = get_request_ip(request)
OAuthBindMessage(user, ip, _('WeCom'), user_id).publish_async()
msg = _('Binding DingTalk successfully')
response = self.get_success_response(redirect_url, msg, msg)
return response

@ -16,8 +16,10 @@ from common.utils.random import random_string
from common.utils.django import reverse, get_object_or_none
from common.mixins.views import PermissionsMixin
from common.sdk.im.feishu import FeiShu, URL
from common.utils.common import get_request_ip
from authentication import errors
from authentication.mixins import AuthMixin
from authentication.notifications import OAuthBindMessage
logger = get_logger(__file__)
@ -142,6 +144,8 @@ class FeiShuQRBindCallbackView(FeiShuQRMixin, View):
return response
raise e
ip = get_request_ip(request)
OAuthBindMessage(user, ip, _('WeCom'), user_id).publish_async()
msg = _('Binding FeiShu successfully')
response = self.get_success_response(redirect_url, msg, msg)
return response

@ -17,8 +17,10 @@ from common.utils.django import reverse, get_object_or_none
from common.sdk.im.wecom import URL
from common.sdk.im.wecom import WeCom
from common.mixins.views import PermissionsMixin
from common.utils.common import get_request_ip
from authentication import errors
from authentication.mixins import AuthMixin
from authentication.notifications import OAuthBindMessage
logger = get_logger(__file__)
@ -152,6 +154,8 @@ class WeComQRBindCallbackView(WeComQRMixin, View):
return response
raise e
ip = get_request_ip(request)
OAuthBindMessage(user, ip, _('WeCom'), wecom_userid).publish_async()
msg = _('Binding WeCom successfully')
response = self.get_success_response(redirect_url, msg, msg)
return response

Loading…
Cancel
Save