mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-04 17:01:09 +00:00
feat: 添加短信服务和用户消息通知
This commit is contained in:
@@ -10,7 +10,6 @@ import time
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.core.cache import cache
|
||||
from datetime import datetime
|
||||
|
||||
from common.tasks import send_mail_async
|
||||
from common.utils import reverse, get_object_or_none, get_request_ip_or_data, get_request_user_agent
|
||||
@@ -79,184 +78,6 @@ def send_user_created_mail(user):
|
||||
send_mail_async.delay(subject, message, recipient_list, html_message=message)
|
||||
|
||||
|
||||
def send_reset_password_mail(user):
|
||||
subject = _('Reset password')
|
||||
recipient_list = [user.email]
|
||||
message = _("""
|
||||
Hello %(name)s:
|
||||
<br>
|
||||
Please click the link below to reset your password, if not your request, concern your account security
|
||||
<br>
|
||||
<a href="%(rest_password_url)s?token=%(rest_password_token)s">Click here reset password</a>
|
||||
<br>
|
||||
This link is valid for 1 hour. After it expires, <a href="%(forget_password_url)s?email=%(email)s">request new one</a>
|
||||
|
||||
<br>
|
||||
---
|
||||
|
||||
<br>
|
||||
<a href="%(login_url)s">Login direct</a>
|
||||
|
||||
<br>
|
||||
""") % {
|
||||
'name': user.name,
|
||||
'rest_password_url': reverse('authentication:reset-password', external=True),
|
||||
'rest_password_token': user.generate_reset_token(),
|
||||
'forget_password_url': reverse('authentication:forgot-password', external=True),
|
||||
'email': user.email,
|
||||
'login_url': reverse('authentication:login', external=True),
|
||||
}
|
||||
if settings.DEBUG:
|
||||
logger.debug(message)
|
||||
|
||||
send_mail_async.delay(subject, message, recipient_list, html_message=message)
|
||||
|
||||
|
||||
def send_reset_password_success_mail(request, user):
|
||||
subject = _('Reset password success')
|
||||
recipient_list = [user.email]
|
||||
message = _("""
|
||||
|
||||
Hi %(name)s:
|
||||
<br>
|
||||
|
||||
|
||||
<br>
|
||||
Your JumpServer password has just been successfully updated.
|
||||
<br>
|
||||
|
||||
<br>
|
||||
If the password update was not initiated by you, your account may have security issues.
|
||||
It is recommended that you log on to the JumpServer immediately and change your password.
|
||||
<br>
|
||||
|
||||
<br>
|
||||
If you have any questions, you can contact the administrator.
|
||||
<br>
|
||||
<br>
|
||||
---
|
||||
<br>
|
||||
<br>
|
||||
IP Address: %(ip_address)s
|
||||
<br>
|
||||
<br>
|
||||
Browser: %(browser)s
|
||||
<br>
|
||||
|
||||
""") % {
|
||||
'name': user.name,
|
||||
'ip_address': get_request_ip_or_data(request),
|
||||
'browser': get_request_user_agent(request),
|
||||
}
|
||||
if settings.DEBUG:
|
||||
logger.debug(message)
|
||||
|
||||
send_mail_async.delay(subject, message, recipient_list, html_message=message)
|
||||
|
||||
|
||||
def send_password_expiration_reminder_mail(user):
|
||||
subject = _('Security notice')
|
||||
recipient_list = [user.email]
|
||||
message = _("""
|
||||
Hello %(name)s:
|
||||
<br>
|
||||
Your password will expire in %(date_password_expired)s,
|
||||
<br>
|
||||
For your account security, please click on the link below to update your password in time
|
||||
<br>
|
||||
<a href="%(update_password_url)s">Click here update password</a>
|
||||
<br>
|
||||
If your password has expired, please click
|
||||
<a href="%(forget_password_url)s?email=%(email)s">Password expired</a>
|
||||
to apply for a password reset email.
|
||||
|
||||
<br>
|
||||
---
|
||||
|
||||
<br>
|
||||
<a href="%(login_url)s">Login direct</a>
|
||||
|
||||
<br>
|
||||
""") % {
|
||||
'name': user.name,
|
||||
'date_password_expired': datetime.fromtimestamp(datetime.timestamp(
|
||||
user.date_password_expired)).strftime('%Y-%m-%d %H:%M'),
|
||||
'update_password_url': reverse('users:user-password-update', external=True),
|
||||
'forget_password_url': reverse('authentication:forgot-password', external=True),
|
||||
'email': user.email,
|
||||
'login_url': reverse('authentication:login', external=True),
|
||||
}
|
||||
if settings.DEBUG:
|
||||
logger.debug(message)
|
||||
|
||||
send_mail_async.delay(subject, message, recipient_list, html_message=message)
|
||||
|
||||
|
||||
def send_user_expiration_reminder_mail(user):
|
||||
subject = _('Expiration notice')
|
||||
recipient_list = [user.email]
|
||||
message = _("""
|
||||
Hello %(name)s:
|
||||
<br>
|
||||
Your account will expire in %(date_expired)s,
|
||||
<br>
|
||||
In order not to affect your normal work, please contact the administrator for confirmation.
|
||||
<br>
|
||||
""") % {
|
||||
'name': user.name,
|
||||
'date_expired': datetime.fromtimestamp(datetime.timestamp(
|
||||
user.date_expired)).strftime('%Y-%m-%d %H:%M'),
|
||||
}
|
||||
if settings.DEBUG:
|
||||
logger.debug(message)
|
||||
|
||||
send_mail_async.delay(subject, message, recipient_list, html_message=message)
|
||||
|
||||
|
||||
def send_reset_ssh_key_mail(user):
|
||||
subject = _('SSH Key Reset')
|
||||
recipient_list = [user.email]
|
||||
message = _("""
|
||||
Hello %(name)s:
|
||||
<br>
|
||||
Your ssh public key has been reset by site administrator.
|
||||
Please login and reset your ssh public key.
|
||||
<br>
|
||||
<a href="%(login_url)s">Login direct</a>
|
||||
|
||||
<br>
|
||||
""") % {
|
||||
'name': user.name,
|
||||
'login_url': reverse('authentication:login', external=True),
|
||||
}
|
||||
if settings.DEBUG:
|
||||
logger.debug(message)
|
||||
|
||||
send_mail_async.delay(subject, message, recipient_list, html_message=message)
|
||||
|
||||
|
||||
def send_reset_mfa_mail(user):
|
||||
subject = _('MFA Reset')
|
||||
recipient_list = [user.email]
|
||||
message = _("""
|
||||
Hello %(name)s:
|
||||
<br>
|
||||
Your MFA has been reset by site administrator.
|
||||
Please login and reset your MFA.
|
||||
<br>
|
||||
<a href="%(login_url)s">Login direct</a>
|
||||
|
||||
<br>
|
||||
""") % {
|
||||
'name': user.name,
|
||||
'login_url': reverse('authentication:login', external=True),
|
||||
}
|
||||
if settings.DEBUG:
|
||||
logger.debug(message)
|
||||
|
||||
send_mail_async.delay(subject, message, recipient_list, html_message=message)
|
||||
|
||||
|
||||
def get_user_or_pre_auth_user(request):
|
||||
user = request.user
|
||||
if user.is_authenticated:
|
||||
|
Reference in New Issue
Block a user