Add an endpoint to change password.
This commit is contained in:
		
							parent
							
								
									9cc68291df
								
							
						
					
					
						commit
						cc23d516a0
					
				| @ -419,3 +419,23 @@ class AuthenticationLoginInnerSerializer(AuthenticationLoginChallengeSerializer) | ||||
| 
 | ||||
|     def update(self, instance, validated_data): | ||||
|         raise NotImplementedError() | ||||
| 
 | ||||
| 
 | ||||
| class AuthenticationChangePasswordSerializer(serializers.ModelSerializer): | ||||
|     loginPubkey = BinaryBase64Field() | ||||
|     encryptedContent = BinaryBase64Field() | ||||
| 
 | ||||
|     class Meta: | ||||
|         model = models.UserInfo | ||||
|         fields = ('loginPubkey', 'encryptedContent') | ||||
| 
 | ||||
|     def create(self, validated_data): | ||||
|         raise NotImplementedError() | ||||
| 
 | ||||
|     def update(self, instance, validated_data): | ||||
|         with transaction.atomic(): | ||||
|             instance.loginPubkey = validated_data.pop('loginPubkey') | ||||
|             instance.encryptedContent = validated_data.pop('encryptedContent') | ||||
|             instance.save() | ||||
| 
 | ||||
|         return instance | ||||
|  | ||||
| @ -48,6 +48,7 @@ from .models import ( | ||||
|     ) | ||||
| from .serializers import ( | ||||
|         b64encode, | ||||
|         AuthenticationChangePasswordSerializer, | ||||
|         AuthenticationSignupSerializer, | ||||
|         AuthenticationLoginChallengeSerializer, | ||||
|         AuthenticationLoginSerializer, | ||||
| @ -668,6 +669,14 @@ class AuthenticationViewSet(viewsets.ViewSet): | ||||
|         # FIXME: expire the token - we need better token handling - using knox? Something else? | ||||
|         return Response({}, status=status.HTTP_200_OK) | ||||
| 
 | ||||
|     @action_decorator(detail=False, methods=['POST'], permission_classes=BaseViewSet.permission_classes) | ||||
|     def change_password(self, request): | ||||
|         serializer = AuthenticationChangePasswordSerializer(request.user.userinfo, data=request.data) | ||||
|         serializer.is_valid(raise_exception=True) | ||||
|         serializer.save() | ||||
| 
 | ||||
|         return Response(status=status.HTTP_200_OK) | ||||
| 
 | ||||
| 
 | ||||
| class TestAuthenticationViewSet(viewsets.ViewSet): | ||||
|     authentication_classes = BaseViewSet.authentication_classes | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Tom Hacohen
						Tom Hacohen