Ejemplo n.º 1
0
    def test_register(self, api_client, test_user):
        allow(UserService).register_new_user.and_return(test_user)

        user_data = generate_user_profile()
        response = api_client.post(self.register_url, user_data)
        response_json = response.json()
        serialized_data = SessionSerializer(test_user).data
        assert response.status_code == status.HTTP_200_OK
        assert response_json.keys() == serialized_data.keys()
    def test_valid_token(self, api_client, test_user):
        allow(SessionService).process_facebook_token.and_return(test_user)

        login_data = {'accessToken': 'valid_token'}
        response = api_client.post(self.facebook_login_url, login_data)
        response_json = response.json()

        assert response.status_code == status.HTTP_200_OK
        user_data = SessionSerializer(test_user).data
        assert response_json.keys() == user_data.keys()
Ejemplo n.º 3
0
    def post(self, request):
        """Get session from facebook access token.

        POST /api/v1/auth/facebook-login/
        """
        serializer = AccessTokenSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        user = SessionService.process_facebook_token(
            serializer.validated_data['access_token'], )

        return Response(SessionSerializer(user).data)
Ejemplo n.º 4
0
    def post(self, request):
        """Get session from google token id.

        POST /api/v1/auth/google-login/
        """
        serializer = GoogleTokenSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        user = SessionService.process_google_token(
            serializer.validated_data['token'], )

        return Response(SessionSerializer(user).data)
Ejemplo n.º 5
0
    def post(self, request):
        """Registers an user using the info."""
        serializer = RegisterSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        if config.REGISTER_REQUIRES_EMAIL_CONFIRMATION:
            user = UserService.register_new_user(
                user_data=serializer.validated_data)
            AuthService.send_confirmation_email(user)
            return Response(AccountsResponses.CONFIRMATION_EMAIL_SENT)
        else:
            user = UserService.register_new_user(
                user_data=serializer.validated_data)
            return Response(SessionSerializer(user).data)
Ejemplo n.º 6
0
    def post(self, request):
        """Get session from google token id.

        POST /api/v1/auth/login/
        """
        serializer = LoginSerializer(
            data=request.data,
            context={'request': request},
        )
        serializer.is_valid(raise_exception=True)

        username_or_email = serializer.validated_data.get('user')
        plain_password = serializer.validated_data.get('password')

        user = UserSelector.get_by_username_or_email(username_or_email)
        SessionService.validate_session(user, plain_password)

        return Response(SessionSerializer(user).data)