예제 #1
0
    def test_confirm_reset_password(test_user):
        plain_password = '******'
        pending_action = PendingActionFactory(user=test_user, category=ActionCategory.RESET_PASSWORD)
        PasswordService.confirm_reset_password(pending_action, plain_password)
        updated_pending_action = PendingAction.objects.filter(pk=pending_action.pk).first()

        assert test_user.check_password(plain_password)
        assert updated_pending_action is None
예제 #2
0
    def update_password(self, request):
        """Updates the useer passwrod."""
        serializer = PasswordUpdateSerializer(
            data=request.data,
            context={'request': request},
        )
        serializer.is_valid(raise_exception=True)

        new_plain_password = serializer.validated_data['new_password']
        PasswordService.set_pasword(request.user, new_plain_password)
        update_session_auth_hash(request, request.user)

        return Response(AccountsResponses.PASSWORD_UPDATED)
예제 #3
0
    def set_password(self, request):
        """Sets the user password."""
        serializer = PasswordSetSerializer(
            data=request.data,
            context={'request': request},
        )
        serializer.is_valid(raise_exception=True)

        plain_password = serializer.validated_data['password']
        PasswordService.set_pasword(request.user, plain_password)

        return Response(AccountsResponses.PASSWORD_ADDED,
                        status=status.HTTP_201_CREATED)
예제 #4
0
    def reset_password_confirm(self, request):
        """Confirms a password reset."""
        serializer = PasswordResetConfirmSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        plain_password = serializer.validated_data['password']
        action_token = serializer.validated_data['token']

        pending_action = PendingActionSelector.get_by_token(
            action_token,
            category=ActionCategory.RESET_PASSWORD.value,
        )
        PasswordService.confirm_reset_password(pending_action, plain_password)

        return Response(AccountsResponses.PASSWORD_UPDATED)
예제 #5
0
    def reset_password(self, request):
        """Request a password reset."""
        serializer = PasswordResetSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        username_or_email = serializer.validated_data['user']
        user = UserSelector.get_by_username_or_email(username_or_email)

        pending_action = PasswordService.perform_reset_password(user)
        AuthEmailService.send_reset_password(pending_action)

        return Response(AccountsResponses.RESET_PASSWORD_SENT)
예제 #6
0
 def test_set_pasword(test_user):
     plain_password = '******'
     PasswordService.set_pasword(test_user, plain_password)
     assert test_user.check_password(plain_password)
예제 #7
0
 def test_perform_reset_password(test_user):
     pending_action = PasswordService.perform_reset_password(test_user)
     assert isinstance(pending_action, PendingAction)
     assert pending_action.category == ActionCategory.RESET_PASSWORD