Exemplo n.º 1
0
 def get_search_fields(self, request=None):
     search_fields = getattr(
         settings, setting_name('ADMIN_USER_SEARCH_FIELDS'), None
     )
     if search_fields is None:
         _User = UserSocialAuth.user_model()
         username = getattr(_User, 'USERNAME_FIELD', None) or \
                    hasattr(_User, 'username') and 'username' or \
                    None
         fieldnames = ('first_name', 'last_name', 'email', username)
         all_names = self._get_all_field_names(_User._meta)
         search_fields = [name for name in fieldnames
                             if name and name in all_names]
     return ['user__' + name for name in search_fields] + \
         getattr(settings, setting_name('ADMIN_SEARCH_FIELDS'), [])
Exemplo n.º 2
0
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, HttpResponsePermanentRedirect
from django.views.decorators.csrf import csrf_exempt, csrf_protect
from django.views.decorators.http import require_POST
from django.views.decorators.cache import never_cache

from managestage.utli.wrapper import Web_Maintain
from .models import UserSocialAuth
from social_django.social_core.utils import setting_name
from social_django.social_core.actions import do_auth, do_complete, do_disconnect
from .utils import psa
from account.util.email_send import send_auth_email
from account.models import User
from account.util.decorator import auth_filter

NAMESPACE = getattr(settings, setting_name('URL_NAMESPACE'), None) or 'social'

# Calling `session.set_expiry(None)` results in a session lifetime equal to
# platform default session lifetime.
DEFAULT_SESSION_TIMEOUT = None


@Web_Maintain
@never_cache
@psa('{0}:complete'.format(NAMESPACE))
def auth(request, backend):
    #print('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', request)
    return do_auth(request.backend, redirect_name=REDIRECT_FIELD_NAME)


@Web_Maintain
Exemplo n.º 3
0
# coding=utf-8
from functools import wraps

from django.conf import settings
from django.http import Http404

from social_django.social_core.utils import setting_name, module_member, get_strategy
from social_django.social_core.exceptions import MissingBackend
from social_django.social_core.backends.utils import get_backend
from .compat import reverse

BACKENDS = settings.AUTHENTICATION_BACKENDS
STRATEGY = getattr(settings, setting_name('STRATEGY'),
                   'social_django.strategy.DjangoStrategy')
STORAGE = getattr(settings, setting_name('STORAGE'),
                  'social_django.models.DjangoStorage')
Strategy = module_member(STRATEGY)
Storage = module_member(STORAGE)


def load_strategy(request=None):
    return get_strategy(STRATEGY, STORAGE, request)


def load_backend(strategy, name, redirect_uri):

    Backend = get_backend(BACKENDS, name)

    return Backend(strategy, redirect_uri)

Exemplo n.º 4
0
"""URLs module"""
from django.conf import settings
from django.conf.urls import url

from social_django.social_core.utils import setting_name
from . import views


extra = getattr(settings, setting_name('TRAILING_SLASH'), True) and '/' or ''

app_name = 'social'

urlpatterns = [
    # authentication / association
    url(r'^login/(?P<backend>[^/]+){0}$'.format(extra), views.auth,  name='begin'),
    url(r'^complete/(?P<backend>[^/]+){0}auth$'.format(extra), views.complete, name='complete'),
    url(r'^register/auto/$', views.auth_password, name='auth_password'),
    # disconnection
    url(r'^disconnect/(?P<backend>[^/]+){0}$'.format(extra), views.disconnect, name='disconnect'),
    url(r'^disconnect/(?P<backend>[^/]+)/(?P<association_id>\d+){0}$'.format(extra), views.disconnect, name='disconnect_individual'),

]
Exemplo n.º 5
0
    from django.utils.encoding import smart_unicode as smart_text
    smart_text  # placate pyflakes
except ImportError:
    from django.utils.encoding import smart_text

# SubfieldBase causes RemovedInDjango110Warning in 1.8 and 1.9, and
# will not work in 1.10 or later
if django.VERSION[:2] >= (1, 8):
    field_metaclass = type
else:
    from django.db.models import SubfieldBase
    field_metaclass = SubfieldBase

field_class = functools.partial(six.with_metaclass, field_metaclass)

if getattr(settings, setting_name('POSTGRES_JSONFIELD'), False):
    from django.contrib.postgres.fields import JSONField as JSONFieldBase
else:
    JSONFieldBase = field_class(models.TextField)


class JSONField(JSONFieldBase):
    """Simple JSON field that stores python structures as JSON strings
    on database.
    """

    def __init__(self, *args, **kwargs):
        kwargs.setdefault('default', dict)
        super(JSONField, self).__init__(*args, **kwargs)

    def from_db_value(self, value, expression, connection, context):
Exemplo n.º 6
0
from django.db import models
from django.conf import settings
from django.db.utils import IntegrityError

from social_django.social_core.utils import setting_name

from .compat import get_rel_model
from .storage import DjangoUserMixin, DjangoAssociationMixin, \
                     DjangoNonceMixin, DjangoCodeMixin, \
                     DjangoPartialMixin, BaseDjangoStorage
from .fields import JSONField
from .managers import UserSocialAuthManager


USER_MODEL = getattr(settings, setting_name('USER_MODEL'), None) or \
             getattr(settings, 'AUTH_USER_MODEL', None) or \
             'auth.User'
UID_LENGTH = getattr(settings, setting_name('UID_LENGTH'), 255)
EMAIL_LENGTH = getattr(settings, setting_name('EMAIL_LENGTH'), 254)
NONCE_SERVER_URL_LENGTH = getattr(
    settings, setting_name('NONCE_SERVER_URL_LENGTH'), 255)
ASSOCIATION_SERVER_URL_LENGTH = getattr(
    settings, setting_name('ASSOCIATION_SERVER_URL_LENGTH'), 255)
ASSOCIATION_HANDLE_LENGTH = getattr(
    settings, setting_name('ASSOCIATION_HANDLE_LENGTH'), 255)


class AbstractUserSocialAuth(models.Model, DjangoUserMixin):
    """Abstract Social Auth association model"""
    user = models.ForeignKey(USER_MODEL, related_name='social_auth',