Django-facebook icon indicating copy to clipboard operation
Django-facebook copied to clipboard

Integration with Django Userena?

Open alzearafat opened this issue 8 years ago • 3 comments

Hi,

I'm having dificulties integrating django-facebook with django-userena. I already have an app running with django-userena, and decide to create "Login with Facebook" in sign up form. Here's my issue :

1- The loading is infinite : The loading screen is just keep loading and never take me anywhere...

alt text

2- Should I edit my userena models? This is my userena model :

from django.db import models
from django.contrib.auth.models import User
from userena.models import UserenaBaseProfile
from django.utils.translation import ugettext as _

from django.db import models
from django.dispatch.dispatcher import receiver
from django_facebook.models import FacebookModel
from django.db.models.signals import post_save
from django_facebook.utils import get_user_model, get_profile_model
from gogotrip import settings


# MODEL ORM
class MyProfile(UserenaBaseProfile, FacebookModel):
    user = models.OneToOneField(User, unique=True, verbose_name=_('user'), related_name='my_profile')
    facebook = models.URLField(max_length=100, blank=True, null=True)
        ...

    @receiver(post_save)
    def create_profile(sender, instance, created, **kwargs):
        """Create a matching profile whenever a user object is created."""
        if sender == get_user_model():
            user = instance
            profile_model = get_profile_model()
            if profile_model == MyProfile and created:
                profile, new = MyProfile.objects.get_or_create(user=instance)

    def __str__(self):
        return str(self.user)

my settings.py

"""
Django settings for gogotrip project.

Generated by 'django-admin startproject' using Django 1.8.6.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
MODE = os.environ.get('MODE', 'standalone')
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '8tdr*!cefa^g0q=r%*($t_!l#evfqg7nzw+m++lms)$4b3a88e'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',

    # MAIN APPS
    'trip_app',
    'accounts',

    # 3RD-PARTY APPS
    'userena', 
    'guardian',
    'easy_thumbnails', 
    'ckeditor',
    'crispy_forms',
    'watson',
    'djrill',
    'django_facebook',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'gogotrip.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
            'django.contrib.auth.context_processors.auth',
            'django.core.context_processors.debug',
            'django.core.context_processors.i18n',
            'django.core.context_processors.media',
            'django.core.context_processors.static',
            'django.core.context_processors.tz',
            'django.core.context_processors.request',
            'django.contrib.messages.context_processors.messages',
            'django_facebook.context_processors.facebook',
            ],
        },
    },
]

WSGI_APPLICATION = 'gogotrip.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.sqlite3',
#         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
#     }
# }
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'startup_gogotripDB',
        'USER': 'root',
        'PASSWORD': 'root',
        'HOST': 'localhost',
        'PORT': '',
    }
}


# CKEDITOR SETTING
CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': 'Custom',
        'toolbar_Custom': [
            ['Bold', 'Italic', 'Underline'],
            ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
            ['Link', 'Unlink'],
            ['codesnippet', 'codesnippetgeshi'],
            ['RemoveFormat', 'Source']
        ],
        # 'extraPlugins': ','.join([
        #     'codesnippet',
        # ]),
           'height': 400,
           'width': 700,
    }
}

# FACEBOOK CONNECT
FACEBOOK_APP_ID = '9xxx78xxxxx31314028'
FACEBOOK_APP_SECRET = '0c8c413648a2473d880cxxxxf8xxxaa6405'
FACEBOOK_REGISTRATION_BACKEND = 'django_facebook.registration_backends.UserenaBackend'
# AUTH_USER_MODEL = 'django_facebook.FacebookCustomUser'

# Auth Userarena
AUTHENTICATION_BACKENDS = (
    'userena.backends.UserenaAuthenticationBackend',
    'guardian.backends.ObjectPermissionBackend',
    'django_facebook.auth_backends.FacebookBackend',
    'django.contrib.auth.backends.ModelBackend',
)

# CRISP_FORMS_SETTINGS
CRISPY_CLASS_CONVERTERS = {'textinput': "uk-form uk-form-large uk-form-width-large", 'emailinput': "uk-form uk-form-large uk-form-width-large", 'dateinput': "uk-form uk-form-large uk-form-width-large", 'urlinput': "uk-form uk-form-large uk-form-width-large", }

# USERENA_SETTINGS
SITE_ID = 1
ANONYMOUS_USER_ID = -1
AUTH_PROFILE_MODULE = 'accounts.MyProfile'
USERENA_MUGSHOT_SIZE = 150
USERENA_DEFAULT_PRIVACY = 'open'
# USERENA_DISABLE_PROFILE_LIST = True
# USERENA_USE_MESSAGES = True
USERENA_SIGNIN_REDIRECT_URL = '/accounts/%(username)s/'
LOGIN_URL = '/accounts/signin/'
LOGOUT_URL = '/accounts/signout/'

# EMAIL SERVER SETTING
MANDRILL_API_KEY = "xxx"
EMAIL_BACKEND = "djrill.mail.backends.djrill.DjrillBackend"
DEFAULT_FROM_EMAIL = "[email protected]"  # if you don't already have this in settings


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
    '/home/zea/Startup/gogotrip_env/gogotrip/static_dir',
)
STATIC_URL = '/static/'

MEDIA_ROOT = '/home/zea/Startup/gogotrip_env/gogotrip/media'
MEDIA_URL = '/trip/media/'

CKEDITOR_UPLOAD_PATH = 'media/uploads/'
CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'

3- When I try localhost:8000/facebook/connect, it turns out to error :

This field is required.

![alt text](http://i63.tinypic.com/fa4mjp.png" Logo Title Text 1")

Thank you in advance for any help you are able to provide Regards

alzearafat avatar Jan 13 '16 13:01 alzearafat

Anyone please? :/

alzearafat avatar Jan 20 '16 10:01 alzearafat

amazing

alzearafat avatar Aug 28 '16 13:08 alzearafat

This is more likely not an issue with userena.. Did you check your browser console? I had a similar issue, but it was : Uncaught TypeError: formElement.submit is not a function at VM6317 facebook.js:74 at v.__wrapper (all.js:90) at all.js:87 at Object.la [as _xdRecv] (all.js:112) at all.js:112 at Object.ra [as onMessage] (all.js:85) at all.js:75 at all.js:36 at all.js:36

This is because formElement is pointing to the window, which does not have a submit action. I think the placement of the embeddable code is the culprit AFAICT.

johnsonc avatar Jan 11 '17 13:01 johnsonc