From be30c4d2341b21f80b4038114d21055d813072d9 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 9 Mar 2023 10:54:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/system/views.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/system/views.py b/apps/system/views.py index 3f11301c..44f8f431 100755 --- a/apps/system/views.py +++ b/apps/system/views.py @@ -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):