mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-01 23:47:40 +00:00
feat: 添加短信服务和用户消息通知
This commit is contained in:
@@ -4,14 +4,13 @@ import uuid
|
||||
from rest_framework import generics
|
||||
from common.permissions import IsOrgAdmin
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from django.conf import settings
|
||||
|
||||
from users.notifications import ResetPasswordMsg, ResetPasswordSuccessMsg, ResetSSHKeyMsg
|
||||
from common.permissions import (
|
||||
IsCurrentUserOrReadOnly
|
||||
)
|
||||
from .. import serializers
|
||||
from ..models import User
|
||||
from ..utils import send_reset_password_success_mail
|
||||
from .mixins import UserQuerysetMixin
|
||||
|
||||
__all__ = [
|
||||
@@ -29,11 +28,10 @@ class UserResetPasswordApi(UserQuerysetMixin, generics.UpdateAPIView):
|
||||
def perform_update(self, serializer):
|
||||
# Note: we are not updating the user object here.
|
||||
# We just do the reset-password stuff.
|
||||
from ..utils import send_reset_password_mail
|
||||
user = self.get_object()
|
||||
user.password_raw = str(uuid.uuid4())
|
||||
user.save()
|
||||
send_reset_password_mail(user)
|
||||
ResetPasswordMsg(user).publish_async()
|
||||
|
||||
|
||||
class UserResetPKApi(UserQuerysetMixin, generics.UpdateAPIView):
|
||||
@@ -41,11 +39,11 @@ class UserResetPKApi(UserQuerysetMixin, generics.UpdateAPIView):
|
||||
permission_classes = (IsOrgAdmin,)
|
||||
|
||||
def perform_update(self, serializer):
|
||||
from ..utils import send_reset_ssh_key_mail
|
||||
user = self.get_object()
|
||||
user.public_key = None
|
||||
user.save()
|
||||
send_reset_ssh_key_mail(user)
|
||||
|
||||
ResetSSHKeyMsg(user).publish_async()
|
||||
|
||||
|
||||
# 废弃
|
||||
@@ -84,4 +82,4 @@ class UserPublicKeyApi(generics.RetrieveUpdateAPIView):
|
||||
|
||||
def perform_update(self, serializer):
|
||||
super().perform_update(serializer)
|
||||
send_reset_password_success_mail(self.request, self.get_object())
|
||||
ResetPasswordSuccessMsg(self.get_object(), self.request).publish_async()
|
||||
|
@@ -8,6 +8,7 @@ from rest_framework.response import Response
|
||||
from rest_framework_bulk import BulkModelViewSet
|
||||
from django.db.models import Prefetch
|
||||
|
||||
from users.notifications import ResetMFAMsg
|
||||
from common.permissions import (
|
||||
IsOrgAdmin, IsOrgAdminOrAppUser,
|
||||
CanUpdateDeleteUser, IsSuperUser
|
||||
@@ -16,7 +17,7 @@ from common.mixins import CommonApiMixin
|
||||
from common.utils import get_logger
|
||||
from orgs.utils import current_org
|
||||
from orgs.models import ROLE as ORG_ROLE, OrganizationMember
|
||||
from users.utils import send_reset_mfa_mail, LoginBlockUtil, MFABlockUtils
|
||||
from users.utils import LoginBlockUtil, MFABlockUtils
|
||||
from .. import serializers
|
||||
from ..serializers import UserSerializer, UserRetrieveSerializer, MiniUserSerializer, InviteSerializer
|
||||
from .mixins import UserQuerysetMixin
|
||||
@@ -209,5 +210,6 @@ class UserResetOTPApi(UserQuerysetMixin, generics.RetrieveAPIView):
|
||||
if user.mfa_enabled:
|
||||
user.reset_mfa()
|
||||
user.save()
|
||||
send_reset_mfa_mail(user)
|
||||
|
||||
ResetMFAMsg(user).publish_async()
|
||||
return Response({"msg": "success"})
|
||||
|
Reference in New Issue
Block a user