管理员重置密码

This commit is contained in:
caoqianming 2023-03-09 10:54:41 +08:00
parent d91c0b2bfe
commit be30c4d234
1 changed files with 12 additions and 1 deletions

View File

@ -8,11 +8,12 @@ from django_celery_beat.models import (CrontabSchedule, IntervalSchedule,
PeriodicTask)
from django_celery_results.models import TaskResult
from rest_framework.decorators import action
from rest_framework.exceptions import ParseError, ValidationError
from rest_framework.exceptions import ParseError, ValidationError, PermissionDenied
from rest_framework.mixins import (CreateModelMixin, DestroyModelMixin,
ListModelMixin, RetrieveModelMixin)
from rest_framework.parsers import (JSONParser,
MultiPartParser)
from rest_framework.serializers import Serializer
from rest_framework.permissions import IsAuthenticated, AllowAny
from rest_framework.response import Response
from rest_framework.views import APIView
@ -494,6 +495,16 @@ class UserViewSet(CustomModelViewSet):
raise ParseError(**PASSWORD_NOT_SAME)
else:
raise ValidationError(**OLD_PASSWORD_WRONG)
@action(methods=['post'], detail=True, perms_map={'post': '*'}, serializer_class=Serializer)
def reset_password(self, request, pk=None):
user = self.get_object()
if request.user.is_superuser:
user.set_password('0000')
user.save()
else:
raise PermissionDenied()
return Response()
@action(methods=['get'], detail=False, permission_classes=[IsAuthenticated])
def info(self, request, pk=None):