Exemplo n.º 1
0
 def put(self, request, *args, **kwargs):
     self.object = self.get_object()
     data = {
         'old_password': request.data['old_password'],
         'new_password': request.data['new_password']
     }
     serializer = ChangePasswordSerializer(data)
     if serializer.is_valid():
         old_password = serializer.data.get('old_password')
         if not self.object.check_password(old_password):
             return Response({'old_password': '******'},
                             status=status.HTTP_400_BAD_REQUEST)
         self.object.set_password(serializer.data.get('new_password'))
         self.object.save()
         return Response(status=status.HTTP_204_NO_CONTENT)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 2
0
    def put(self, request, *args, **kwargs):
        self.object = self.get_object()
        data = {"old_password": request.data.get('old_password'),
                "new_password": request.data.get('new_password')}

        serializer = ChangePasswordSerializer(data=data)
        if serializer.is_valid():
            print(serializer.data)
            old_password = serializer.data.get('old_password')
            if not self.object.check_password(old_password):
                return Response({"old_password": "******"}, status=status.HTTP_400_BAD_REQUEST)

            self.object.set_password(serializer.data.get('new_password'))
            self.object.save()
            return Response(status=status.HTTP_204_NO_CONTENT)
        return Response(status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 3
0
    def put(self, request, *args, **kwargs):
        self.object = self.request.user

        serializer = ChangePasswordSerializer(data=request.data)

        if serializer.is_valid():
            old_password = serializer.data.get("old_password")
            if not self.object.check_password(old_password):
                return Response({"old_password": "******"},
                                status=status.HTTP_400_BAD_REQUEST)

            self.object.set_password(serializer.data.get("new_password"))
            self.object.save()
            update_session_auth_hash(request, self.object)
            return Response(status=status.HTTP_204_NO_CONTENT)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 4
0
Arquivo: views.py Projeto: selamet/DRF
    def put(self, request, *args, **kwargs):
        self.object = self.get_object()

        serializer = ChangePasswordSerializer(data=request.data)
        if serializer.is_valid():
            print(serializer.data)
            old_password = serializer.data.get('old_password')
            if not self.object.check_password(old_password):
                return Response({'old_password': '******'},
                                status=status.HTTP_400_BAD_REQUEST)

            self.object.set_password(serializer.data.get('new_password'))
            self.object.save()
            update_session_auth_hash(
                request, self.object)  # update sonrası oturumda kalmayı sağlar
            return Response(status=status.HTTP_204_NO_CONTENT)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 5
0
def change_password_view(request):
    serializer = ChangePasswordSerializer(data=request.data)
    if serializer.is_valid():
        return_value, return_data = serializer.update(request.user)
        if return_value:
            return Response({"success": True,
                             "message": "Password successfully changed.",
                             "data": {}},
                            status=status.HTTP_200_OK)
        else:
            return Response({"success": False,
                             "message": return_data,
                             "data": {},
                             "error": 0000}, status=status.HTTP_400_BAD_REQUEST)
    else:
        return Response({"success": False,
                         "message": "Token Not Found",
                         "data": {}},
                        status=status.HTTP_401_UNAUTHORIZED)
Exemplo n.º 6
0
    def put(self, request, *args, **kwargs):
        self.object = self.get_object()
        serializer = ChangePasswordSerializer(data=request.data)

        if serializer.is_valid():
            # Check old password
            old_password = request.data["old_password"]
            if not self.object.check_password(old_password):
                return Response({"old_password": ["Wrong password."]},
                                status=status.HTTP_400_BAD_REQUEST)
            # set_password also hashes the password that the user will get

            if request.data["new_password"] != request.data["new_password2"]:
                return Response({"new_password": ["Password must match"]},
                                status=status.HTTP_400_BAD_REQUEST)
            self.object.set_password(request.data["new_password"])
            self.object.save()
            return Response({"Status": ["OK"]},
                            status=status.HTTP_204_NO_CONTENT)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)