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)
def twitter_callback(request): try: oauth_verifier = request.GET['oauth_verifier'] token = request.session['OAUTH_TOKEN'] token_secret = request.session['OAUTH_TOKEN_SECRET'] tw_request = TwitterAPI.get_authorized_tokens(oauth_verifier, token, token_secret) if not tw_request['status']: raise Exception(tw_request['error']) setattr(request.user, request.user.social_fields["twitter"]["token"], tw_request['oauth_token']) setattr(request.user, request.user.social_fields["twitter"]["secret"], tw_request['oauth_token_secret']) 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)
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)
def publish_on_twitter(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.") twitter_API = TwitterAPI(post.user) if twitter_API.connection_status(): tag_list = [t.name for t in post.tags.all()] tw_rslt = twitter_API.publish_post(post.title, post.id, tag_list) if not tw_rslt['status']: raise Exception( "An error occured in the twitter posting process: " + tw_rslt['error']) else: raise Exception("Not connected to the Twitter API") except Exception as e: raise Exception("task.publish_on_twitter - Error: " + str(e))
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")
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)