Exemple #1
0
    def get(self, request, *args, **kwargs):
        """Function for getting information about view"""

        if validate_given_user_token(token=kwargs["token"]):
            message = {"details": "Write new email address below."}
            return Response(data=message, status=status.HTTP_200_OK)

        message = {"details": "Invalid link!"}
        return Response(data=message, status=status.HTTP_400_BAD_REQUEST)
Exemple #2
0
def test_validate_given_user_token_with_right_token(user_instance):
    """
    Ensure that function return right response after checking user token
    Since token is right for the given user, function has to return True
    """

    token = get_user_token(user_id=user_instance.id)
    result = validate_given_user_token(token=token)

    assert result
Exemple #3
0
def test_validate_given_user_token_with_wrong_token(user_instance):
    """
    Ensure that function return right response after checking user token
    Since token is wrong for the given user, function has to return False
    """

    token = get_user_token(user_id=user_instance.id)[:-3]
    result = validate_given_user_token(token=token)

    assert not result
Exemple #4
0
    def get(self, request, *args, **kwargs):
        """Return response to user with information about email confirmation"""

        if validate_given_user_token(token=kwargs["token"]):
            confirm_user_email_by_given_token(token=kwargs["token"])
            message = {"details": "Thank you for your email confirmation."}
            return Response(data=message, status=status.HTTP_200_OK)

        message = {"details": "Invalid link!"}
        return Response(data=message, status=status.HTTP_400_BAD_REQUEST)
Exemple #5
0
    def get(self, request, *args, **kwargs):
        """Return response to user with information about new user's email confirmation"""

        if validate_given_user_token(token=kwargs["token"]):
            confirm_user_email_by_given_token(token=kwargs["token"])
            change_user_offer_after_changing_email(token=kwargs["token"],
                                                   value=True)
            message = {
                "details": "Thank for your new email address confirmation."
            }
            return Response(data=message, status=status.HTTP_200_OK)

        message = {"details": "Invalid link!"}
        return Response(data=message, status=status.HTTP_400_BAD_REQUEST)
Exemple #6
0
    def create(self, request, *args, **kwargs):
        """Function for changing user's password"""

        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        if validate_given_user_token(token=kwargs["token"]):
            update_user_password(token=kwargs["token"],
                                 password=request.data["password"])
            message = {"details": "Password has been successfully changed."}
            return Response(data=message, status=status.HTTP_201_CREATED)

        message = {"details": "Invalid link!"}
        return Response(data=message, status=status.HTTP_400_BAD_REQUEST)
Exemple #7
0
    def create(self, request, *args, **kwargs):
        """Function for changing user's password"""

        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        if validate_given_user_token(token=kwargs["token"]):
            change_email_address(
                username=self.request.user.username,
                to_email=request.data["email"],
                token=kwargs["token"],
            )
            message = {
                "details":
                "We send you confirmation mail for "
                "change your email address."
            }
            return Response(data=message, status=status.HTTP_201_CREATED)

        message = {"details": "Invalid link!"}
        return Response(data=message, status=status.HTTP_400_BAD_REQUEST)