<commit_before>from django import template
from django.conf import settings
from django.core.urlresolvers import reverse
    
register = template.Library()
    
class FacebookClientScriptNode(template.Node):
    def render(self, context):

        scope = getattr(settings, "FACEBOOK_SCOPE", "email")
        redirect = getattr(settings, "FACEBOOK_LOGIN_REDIRECT", "/")

        facebook_app_id = settings.FACEBOOK_APP_ID
        channel_url = reverse('channel_url')

        params = {
            "scope":scope,
            "facebook_app_id":facebook_app_id,
            "channel_url":channel_url,
            "redirect":redirect
        }

        return """

<div id="fb-root"></div>
<script type="text/javascript"> 
    
    function facebook_login(){ 
        FB.login(function(response){
            send_response_to_server(response)
        }, {scope:"%(scope)s"}
       )
    }

    function facebook_connect(){
        FB.getLoginStatus(function(response) {

            if (response.status == "connected") {
                send_response_to_server(response);
            } else {
                facebook_login();
            }   

        });
    }

    function send_response_to_server(response){

        var ajax_data = {"access_token" : response.authResponse.accessToken,
                         "sig"          : response.authResponse.signedRequest,
                         "id"           : response.authResponse.userID}

        $.ajax({
            type:"POST",
            url: "/facebook_connect/facebook_connect/",<commit_msg>Parameterize the connect url in the js.<commit_after>from django import template
from django.conf import settings
from django.core.urlresolvers import reverse
    
register = template.Library()
    
class FacebookClientScriptNode(template.Node):
    def render(self, context):

        scope = getattr(settings, "FACEBOOK_SCOPE", "email")
        redirect = getattr(settings, "FACEBOOK_LOGIN_REDIRECT", "/")

        facebook_app_id = settings.FACEBOOK_APP_ID
        channel_url = reverse('channel_url')
        connect_url = reverse('facebook_connect')

        params = {
            "scope":scope,
            "facebook_app_id":facebook_app_id,
            "channel_url":channel_url,
            "connect_url":connect_url,
            "redirect":redirect
        }

        return """

<div id="fb-root"></div>
<script type="text/javascript"> 
    
    function facebook_login(){ 
        FB.login(function(response){
            send_response_to_server(response)
        }, {scope:"%(scope)s"}
       )
    }

    function facebook_connect(){
        FB.getLoginStatus(function(response) {

            if (response.status == "connected") {
                send_response_to_server(response);
            } else {
                facebook_login();
            }   

        });
    }

    function send_response_to_server(response){

        var ajax_data = {"access_token" : response.authResponse.accessToken,
                         "sig"          : response.authResponse.signedRequest,
                         "id"           : response.authResponse.userID}

        $.ajax({
            type:"POST",
            url: "%(connect_url)s",
{'fraction_non_alphanumeric': 0.10898841215158159, 'fraction_numerical': 0.0, 'mean_word_length': 2.0919651500484027, 'pattern_counts': {'":': 9, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3514558', 'n_tokens_mistral': 893, 'n_tokens_neox': 844, 'n_words': 144}