Пример #1
0
    def delete(self, request, social_network=None):

        payload = dict()

        try:
            social_network = auto_format_social_network(social_network)

            request.user.reset_social_network_credentials(
                network=social_network)

            payload["success"] = True
            payload["username"] = request.user.username
            payload["social_network"] = social_network

            if social_network == "twitter":
                payload["auth_url"] = TwitterAPI.get_authorization_url(request)
            elif social_network == "facebook":
                payload["auth_url"] = FacebookAPI.get_authorization_url()
            elif social_network == "linkedin":
                payload["auth_url"] = LinkedInAPI.get_authorization_url()
            elif social_network == "slack":
                payload["auth_url"] = SlackAPI.get_authorization_url()
            else:
                raise Exception("'social_network' (" + social_network +
                                ") is not supported.")

        except Exception as e:
            payload["success"] = False
            payload[
                "error"] = "FC_API.UnLinkUserSocialNetworkView() - An error occured in the process:  " + str(
                    e)

        payload["operation"] = "Unlink User Social_Network"
        payload["timestamp"] = get_timestamp()
        return Response(payload)
Пример #2
0
def linkedin_callback(request):

    try:
        access_code = request.GET['code']

        lk_request = LinkedInAPI.get_authorized_tokens(access_code)

        if not lk_request['status']:
            raise Exception(lk_request['error'])

        expire_datetime = datetime.now() + timedelta(seconds=int(lk_request['expires_in']))

        setattr(request.user, request.user.social_fields["linkedin"]["token"], lk_request['access_token'])
        setattr(request.user, request.user.social_fields["linkedin"]["expire_datetime"], expire_datetime)

        request.user.save()

        return render(request, 'admin/self_closing.html')

    except Exception as e:
        data = dict()

        data["status"] = "error"
        data["error"] = str(e)
        data["feedname"] = request.user.username

        return JsonResponse(data)
Пример #3
0
def services_form(request, feedname=None):

    check_passed = check_admin(feedname, request.user)
    if check_passed != True:
        return check_passed
    else:
        request_data = dict()

        if not request.user.is_social_network_activated(network="twitter"):
            request_data[
                "twitter_auth_url"] = TwitterAPI.get_authorization_url(request)
        else:
            request_data[
                "twitter_auth_url"] = False  # False => Don't need to authenticate with Twitter

        if not request.user.is_social_network_activated(network="facebook"):
            request_data[
                "facebook_auth_url"] = FacebookAPI.get_authorization_url()
        else:
            request_data[
                "facebook_auth_url"] = False  # False => Don't need to authenticate with Facebook

        if not request.user.is_social_network_activated(network="linkedin"):
            request_data[
                "linkedin_auth_url"] = LinkedInAPI.get_authorization_url()
        else:
            request_data[
                "linkedin_auth_url"] = False  # False => Don't need to authenticate with LinkedIn

        request_data["slack_auth_url"] = SlackAPI.get_authorization_url()

        return render(request, 'admin/admin_social_sharing.html', request_data)
Пример #4
0
def publish_on_linkedin(id_article):
    try:

        try:
            post = Post.objects.get(id=id_article)
        except ObjectDoesNotExist:
            raise Exception("The given id_article ('" + str(id_article) +
                            "') doesn't exist.")

        linkedin_API = LinkedInAPI(post.user)

        if linkedin_API.connection_status():
            tag_list = [t.name for t in post.tags.all()]
            lk_rslt = linkedin_API.publish_post(post.title, post.id, tag_list)

            if not lk_rslt['status']:
                raise Exception(
                    "An error occured in the linkedin posting process: " +
                    lk_rslt['error'])
        else:
            raise Exception("Not connected to the LinkedIn API")

    except Exception as e:
        raise Exception("task.publish_on_linkedin - Error: " + str(e))
Пример #5
0
    def is_social_network_activated(self, network):
        if network == "twitter":
            if self.is_social_network_enabled(network=network):
                if TwitterAPI(self).verify_credentials()['status']:
                    return True
                else:
                    self.reset_social_network_credentials(network=network)
                    return False
            else:
                return False

        elif network == "facebook":
            if self.is_social_network_enabled(network=network):
                if FacebookAPI(self).verify_credentials()['status']:
                    return True
                else:
                    self.reset_social_network_credentials(network=network)
                    return False
            else:
                return False

        elif network == "linkedin":
            if self.is_social_network_enabled(network=network):
                if LinkedInAPI(self).verify_credentials()['status']:
                    return True
                else:
                    self.reset_social_network_credentials(network=network)
                    return False
            else:
                return False

        elif network == "slack":
            if self.is_social_network_enabled(network=network):
                if SlackAPI(self).verify_credentials()['status']:
                    return True
                else:
                    self.reset_social_network_credentials(network=network)
                    return False
            else:
                return False

        else:
            raise Exception("The network requested " + network +
                            " doesn't exist in this application")
Пример #6
0
def onboarding_view(request, feedname=None):

    check_passed = check_admin(feedname,
                               request.user,
                               bypassOnboardingCheck=True)
    if check_passed != True:
        return check_passed

    else:
        interest_list = Interest.objects.all().order_by('name')
        country_list = Country.objects.all().order_by('name')

        request_data = dict()

        if not request.user.is_social_network_activated(network="twitter"):
            request_data[
                "twitter_auth_url"] = TwitterAPI.get_authorization_url(request)
        else:
            request_data[
                "twitter_auth_url"] = False  # False => Don't need to authenticate with Twitter

        if not request.user.is_social_network_activated(network="facebook"):
            request_data[
                "facebook_auth_url"] = FacebookAPI.get_authorization_url()
        else:
            request_data[
                "facebook_auth_url"] = False  # False => Don't need to authenticate with Facebook

        if not request.user.is_social_network_activated(network="linkedin"):
            request_data[
                "linkedin_auth_url"] = LinkedInAPI.get_authorization_url()
        else:
            request_data[
                "linkedin_auth_url"] = False  # False => Don't need to authenticate with LinkedIn

        request_data["slack_auth_url"] = SlackAPI.get_authorization_url()

        request_data['interests'] = interest_list
        request_data['countries'] = country_list

        return render(request, 'admin/onboarding.html', request_data)