Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4266168
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:43:25+00:00 2026-05-21T06:43:25+00:00

I have created a django app where users can be looged in with both

  • 0

I have created a django app where users can be looged in with both django app username or facebook username. Now i want to implement a logout functionality while logging in through facebook . Can somebody help me to do this.Please help me to find any tutorials which explains these. I will paste my code here.

html facebook part

{% load facebookconnect %}
{% facebook_connect_login_button %}
{% facebook_connect_script %}

facebookconnect.py

from django import template
from django.conf import settings
from django.core.urlresolvers import reverse

register = template.Library()

class FacebookScriptNode(template.Node):
        def render(self, context):
            return """
            <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>

            <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

            <script type="text/javascript"> FB.init("%s", "%s");
                function facebook_onlogin() {
                    var uid = FB.Facebook.apiClient.get_session().uid;
                    var session_key = FB.Facebook.apiClient.get_session().session_key;
                    var expires = FB.Facebook.apiClient.get_session().expires;
                    var secret = FB.Facebook.apiClient.get_session().secret;
                    var sig = FB.Facebook.apiClient.get_session().sig;

                    fb_connect_ajax(expires, session_key, secret, uid, sig);

                }

                function fb_connect_ajax(expires, session_key, ss, user, sig) {

                    var post_string = 'expires=' + expires;
                    post_string = post_string + '&session_key=' + session_key;
                    post_string = post_string + '&ss=' + ss;
                    post_string = post_string + '&user=' + user;
                    post_string = post_string + '&sig=' + sig;

                    $.ajax({
                        type: "POST",
                        url: "%s",
                        data: post_string,
                        success: function(msg) {
                            window.location = '%s'; //.reload()
                        }
                    });
                } 
            </script>       
            """ % (settings.FACEBOOK_API_KEY, reverse('xd_receiver'), reverse('facebook_connect_ajax'), settings.LOGIN_REDIRECT_URL)


def facebook_connect_script(parser, token): return FacebookScriptNode()

register.tag(facebook_connect_script)

class FacebookLoginNode(template.Node):
    def render(self, context): 
        return "<fb:login-button onlogin='facebook_onlogin();'></fb:login-button>"
        #return "<fb:login-button onclick="openPopup('https://graph.facebook.com/oauth/authorize?client_id=a0acfd122e64fc21cfa34d47369f0c97&redirect_uri=http://mysite.com/mypage&display=popup');"></fb:login-button>"



def facebook_connect_login_button(parser, token): return FacebookLoginNode()

register.tag(facebook_connect_login_button)

function in views.py

def login_facebook_connect(request):
    status = 'unknown failure'
    try:
        expires = request.POST['expires']
        ss = request.POST['ss']
        session_key = request.POST['session_key']
        user = request.POST['user']
        sig = request.POST['sig']

        pre_hash_string = "expires=%ssession_key=%sss=%suser=%s%s" % (
            expires,
            session_key,
            ss,
            user,
            settings.FACEBOOK_APPLICATION_SECRET,
        )
        post_hash_string = hashlib.new('md5')
        post_hash_string.update(pre_hash_string)
        if post_hash_string.hexdigest() == sig:
            try:
                fb = FacebookUser.objects.get(facebook_id=user)
                status = "logged in existing user"
            except FacebookUser.DoesNotExist:
                contrib_user = User()
                contrib_user.save()
                contrib_user.username = u"fbuser_%s" % contrib_user.id

                fb = FacebookUser()
                fb.facebook_id = user
                fb.contrib_user = contrib_user

                temp = hashlib.new('sha1')
                temp.update(str(datetime.datetime.now()))
                password = temp.hexdigest()

                contrib_user.set_password(password)
                fb.contrib_password = password
                fb.save()
                contrib_user.save()
                status = "created new user"

            authenticated_user = auth.authenticate(
                                         username=fb.contrib_user.username, 
                                         password=fb.contrib_password)
            auth.login(request, authenticated_user)
        else:
            status = 'wrong hash sig'

            logging.debug("FBConnect: user %s with exit status %s" % (user, status))

    except Exception, e:
        logging.debug("Exception thrown in the FBConnect ajax call: %s" % e)

    return HttpResponse("%s" % status)

def xd_receiver(request):
        return render_to_response('xd_receiver.html')
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T06:43:26+00:00Added an answer on May 21, 2026 at 6:43 am

    i got it working with this

    <a href="http://m.facebook.com/logout.php?confirm=1&next=http://10.1.0.90:8080/registrationForm" >Sign Out</a> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a django application. Using this app users can be created or
I have a Django app in which the users can create reports at various
I am creating a Django app and want to have visualizations of a social
I've created a simple 'favourites' system in my django app. I have events which
I want to create a django app that can upload and display images. However
I have problem in connecting with Facebook backend of django-social-auth. I have created a
I have created a django app. It has got a user login/registration on the
I have created a form in my Google App Engine application for users to
I have a new Django 1.3 project and app that I've created. I added
On my django app I have a report (a csv download) that can take

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.