2021-09-27 11:06:26 +00:00
|
|
|
from django.utils.translation import ugettext as _
|
2021-10-20 11:45:37 +00:00
|
|
|
from django.template.loader import render_to_string
|
2021-09-27 11:06:26 +00:00
|
|
|
|
|
|
|
from notifications.notifications import UserMessage
|
|
|
|
from common.utils import get_logger
|
2022-01-12 08:33:45 +00:00
|
|
|
from common.utils.timezone import local_now_display
|
2021-09-27 11:06:26 +00:00
|
|
|
|
|
|
|
logger = get_logger(__file__)
|
|
|
|
|
|
|
|
|
|
|
|
class DifferentCityLoginMessage(UserMessage):
|
|
|
|
def __init__(self, user, ip, city):
|
|
|
|
self.ip = ip
|
|
|
|
self.city = city
|
|
|
|
super().__init__(user)
|
|
|
|
|
|
|
|
def get_html_msg(self) -> dict:
|
2022-01-12 08:33:45 +00:00
|
|
|
now = local_now_display()
|
2021-10-20 11:45:37 +00:00
|
|
|
subject = _('Different city login reminder')
|
|
|
|
context = dict(
|
|
|
|
subject=subject,
|
|
|
|
name=self.user.name,
|
2021-09-27 11:06:26 +00:00
|
|
|
username=self.user.username,
|
|
|
|
ip=self.ip,
|
2021-10-20 11:45:37 +00:00
|
|
|
time=now,
|
2021-09-27 11:06:26 +00:00
|
|
|
city=self.city,
|
|
|
|
)
|
2021-10-20 11:45:37 +00:00
|
|
|
message = render_to_string('authentication/_msg_different_city.html', context)
|
2021-09-27 11:06:26 +00:00
|
|
|
return {
|
2021-10-20 11:45:37 +00:00
|
|
|
'subject': subject,
|
2021-09-27 11:06:26 +00:00
|
|
|
'message': message
|
|
|
|
}
|
2021-10-20 11:45:37 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def gen_test_msg(cls):
|
|
|
|
from users.models import User
|
|
|
|
user = User.objects.first()
|
|
|
|
ip = '8.8.8.8'
|
|
|
|
city = '洛杉矶'
|
|
|
|
return cls(user, ip, city)
|
2022-01-12 08:33:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
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()
|
2022-01-12 08:33:45 +00:00
|
|
|
subject = self.oauth_name + ' ' + _('binding reminder')
|
2022-01-12 08:33:45 +00:00
|
|
|
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')
|