管理员重置密码
This commit is contained in:
parent
d91c0b2bfe
commit
be30c4d234
|
@ -8,11 +8,12 @@ from django_celery_beat.models import (CrontabSchedule, IntervalSchedule,
|
||||||
PeriodicTask)
|
PeriodicTask)
|
||||||
from django_celery_results.models import TaskResult
|
from django_celery_results.models import TaskResult
|
||||||
from rest_framework.decorators import action
|
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,
|
from rest_framework.mixins import (CreateModelMixin, DestroyModelMixin,
|
||||||
ListModelMixin, RetrieveModelMixin)
|
ListModelMixin, RetrieveModelMixin)
|
||||||
from rest_framework.parsers import (JSONParser,
|
from rest_framework.parsers import (JSONParser,
|
||||||
MultiPartParser)
|
MultiPartParser)
|
||||||
|
from rest_framework.serializers import Serializer
|
||||||
from rest_framework.permissions import IsAuthenticated, AllowAny
|
from rest_framework.permissions import IsAuthenticated, AllowAny
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
@ -495,6 +496,16 @@ class UserViewSet(CustomModelViewSet):
|
||||||
else:
|
else:
|
||||||
raise ValidationError(**OLD_PASSWORD_WRONG)
|
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])
|
@action(methods=['get'], detail=False, permission_classes=[IsAuthenticated])
|
||||||
def info(self, request, pk=None):
|
def info(self, request, pk=None):
|
||||||
"""登录用户信息
|
"""登录用户信息
|
||||||
|
|
Loading…
Reference in New Issue