本文整理汇总了Python中social.utils.module_member函数的典型用法代码示例。如果您正苦于以下问题:Python module_member函数的具体用法?Python module_member怎么用?Python module_member使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了module_member函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_strategy
def get_strategy(backends, strategy, storage, request=None, backend=None, *args, **kwargs):
if backend:
Backend = get_backend(backends, backend)
if not Backend:
raise ValueError("Missing backend entry")
else:
Backend = None
Strategy = module_member(strategy)
Storage = module_member(storage)
return Strategy(Backend, Storage, request, backends=backends, *args, **kwargs)
示例2: init_social
def init_social(app, db):
User = module_member(app.config[setting_name('USER_MODEL')])
database_proxy.initialize(db)
class UserSocialAuth(PeeweeUserMixin):
"""Social Auth association model"""
user = ForeignKeyField(User, related_name='social_auth')
@classmethod
def user_model(cls):
return User
class Nonce(PeeweeNonceMixin):
"""One use numbers"""
pass
class Association(PeeweeAssociationMixin):
"""OpenId account association"""
pass
class Code(PeeweeCodeMixin):
pass
# Set the references in the storage class
FlaskStorage.user = UserSocialAuth
FlaskStorage.nonce = Nonce
FlaskStorage.association = Association
FlaskStorage.code = Code
示例3: load_backends
def load_backends(backends, force_load=False):
"""
Load backends defined on SOCIAL_AUTH_AUTHENTICATION_BACKENDS, backends will
be imported and cached on BACKENDSCACHE. The key in that dict will be the
backend name, and the value is the backend class.
Only subclasses of BaseAuth (and sub-classes) are considered backends.
Previously there was a BACKENDS attribute expected on backends modules,
this is not needed anymore since it's enough with the
AUTHENTICATION_BACKENDS setting. BACKENDS was used because backends used to
be split on two classes the authentication backend and another class that
dealt with the auth mechanism with the provider, those classes are joined
now.
A force_load boolean argument is also provided so that get_backend
below can retry a requested backend that may not yet be discovered.
"""
global BACKENDSCACHE
if force_load:
BACKENDSCACHE = {}
if not BACKENDSCACHE:
for auth_backend in backends:
backend = module_member(auth_backend)
if issubclass(backend, BaseAuth):
BACKENDSCACHE[backend.name] = backend
return BACKENDSCACHE
示例4: get_login_providers
def get_login_providers(request, short=False):
"""
Returns a list of available login providers based on the
AUTHENTICATION_BACKENDS setting. Each provider is represented as a
dictionary containing the backend name, name of required parameter if
required and its verbose name.
"""
def extract_backend_data(klass):
"""
Helper function which extracts information useful for use in
templates from SocialAuth subclasses and returns it as a
dictionary.
"""
return {
'name': klass.name,
'required_field': klass.REQUIRED_FIELD_NAME,
'required_field_verbose': klass.REQUIRED_FIELD_VERBOSE_NAME,
}
backends = (module_member(auth_backend) for auth_backend in setting('AUTHENTICATION_BACKENDS'))
providers = [extract_backend_data(backend) for backend in backends if issubclass(backend, BaseAuth)]
if short:
return providers[:setting('AUTHENTICATION_PROVIDERS_BRIEF',
DEFAULT_AUTHENTICATION_PROVIDERS_BRIEF)]
return providers
示例5: init_social
def init_social(config, Base, session):
if hasattr(config, 'registry'):
config = config.registry.settings
UID_LENGTH = config.get(setting_name('UID_LENGTH'), 255)
User = module_member(config[setting_name('USER_MODEL')])
app_session = session
class _AppSession(object):
COMMIT_SESSION = False
@classmethod
def _session(cls):
return app_session
class UserSocialAuth(_AppSession, Base, SQLAlchemyUserMixin):
"""Social Auth association model"""
__tablename__ = 'social_auth_usersocialauth'
__table_args__ = (UniqueConstraint('provider', 'uid'),)
id = Column(Integer, primary_key=True)
provider = Column(String(32))
uid = Column(String(UID_LENGTH))
extra_data = Column(JSONType)
user_id = Column(Integer, ForeignKey(User.id),
nullable=False, index=True)
user = relationship(User, backref=backref('social_auth',
lazy='dynamic'))
@classmethod
def username_max_length(cls):
return User.__table__.columns.get('username').type.length
@classmethod
def user_model(cls):
return User
class Nonce(_AppSession, Base, SQLAlchemyNonceMixin):
"""One use numbers"""
__tablename__ = 'social_auth_nonce'
__table_args__ = (UniqueConstraint('server_url', 'timestamp', 'salt'),)
id = Column(Integer, primary_key=True)
server_url = Column(String(255))
timestamp = Column(Integer)
salt = Column(String(40))
class Association(_AppSession, Base, SQLAlchemyAssociationMixin):
"""OpenId account association"""
__tablename__ = 'social_auth_association'
__table_args__ = (UniqueConstraint('server_url', 'handle'),)
id = Column(Integer, primary_key=True)
server_url = Column(String(255))
handle = Column(String(255))
secret = Column(String(255)) # base64 encoded
issued = Column(Integer)
lifetime = Column(Integer)
assoc_type = Column(String(64))
# Set the references in the storage class
PyramidStorage.user = UserSocialAuth
PyramidStorage.nonce = Nonce
PyramidStorage.association = Association
示例6: init_social
def init_social(app, db):
User = module_member(app.config[setting_name('USER_MODEL')])
class UserSocialAuth(db.Document, MongoengineUserMixin):
"""Social Auth association model"""
user = ReferenceField(User)
@classmethod
def user_model(cls):
return User
class Nonce(db.Document, MongoengineNonceMixin):
"""One use numbers"""
pass
class Association(db.Document, MongoengineAssociationMixin):
"""OpenId account association"""
pass
class Code(db.Document, MongoengineCodeMixin):
pass
# Set the references in the storage class
FlaskStorage.user = UserSocialAuth
FlaskStorage.nonce = Nonce
FlaskStorage.association = Association
FlaskStorage.code = Code
示例7: wrapper
def wrapper(request, *args, **kwargs):
is_logged_in = module_member(
request.backend.setting('LOGGEDIN_FUNCTION')
)
if not is_logged_in(request):
raise HTTPForbidden('Not authorized user')
return func(request, *args, **kwargs)
示例8: _get_user_model
def _get_user_model():
"""
Get the User Document class user for MongoEngine authentication.
Use the model defined in SOCIAL_AUTH_USER_MODEL if defined, or
defaults to MongoEngine's configured user document class.
"""
custom_model = getattr(settings, setting_name('USER_MODEL'), None)
if custom_model:
return module_member(custom_model)
try:
# Custom user model support with MongoEngine 0.8
from mongoengine.django.mongo_auth.models import get_user_document
return get_user_document()
except ImportError:
return module_member('mongoengine.django.auth.User')
示例9: __init__
def __init__(self, *args, **kwargs):
self.backend = module_member(self.backend_path)
self.complete_url = '/complete/{0}/?{1}&{2}'.format(
self.backend.name,
'oauth_verifier=bazqux',
'oauth_token=foobar'
)
super(OAuth1Test, self).__init__(*args, **kwargs)
示例10: setUp
def setUp(self):
HTTPretty.enable()
User.reset_cache()
TestUserSocialAuth.reset_cache()
TestNonce.reset_cache()
TestAssociation.reset_cache()
self.backend = module_member('social.backends.github.GithubOAuth2')
self.strategy = TestStrategy(self.backend, TestStorage)
self.user = None
示例11: load_backends
def load_backends(backends, force_load=False):
global BACKENDSCACHE
if force_load:
BACKENDSCACHE = {}
if not BACKENDSCACHE:
for data_backend in backends:
backend = module_member(data_backend)
BACKENDSCACHE[backend.name] = backend
return BACKENDSCACHE
示例12: backends
def backends(request, user):
"""Load Social Auth current user data to context under the key 'backends'.
Will return the output of social.backends.utils.user_backends_data."""
storage = module_member(get_helper('STORAGE'))
return {
'backends': user_backends_data(
user, get_helper('AUTHENTICATION_BACKENDS'), storage
)
}
示例13: setUp
def setUp(self):
HTTPretty.enable()
self.backend = module_member(self.backend_path)
self.complete_url = "/complete/{0}/".format(self.backend.name)
self.strategy = TestStrategy(self.backend, TestStorage, redirect_uri=self.complete_url)
self.strategy.set_settings(
{"SOCIAL_AUTH_AUTHENTICATION_BACKENDS": (self.backend_path, "tests.backends.broken_test.BrokenBackendAuth")}
)
# Force backends loading to trash PSA cache
load_backends(self.strategy.get_setting("SOCIAL_AUTH_AUTHENTICATION_BACKENDS"), force_load=True)
示例14: setUp
def setUp(self):
HTTPretty.enable()
User.reset_cache()
TestUserSocialAuth.reset_cache()
TestNonce.reset_cache()
TestAssociation.reset_cache()
Backend = module_member("social.backends.github.GithubOAuth2")
self.strategy = self.strategy or TestStrategy(TestStorage)
self.backend = Backend(self.strategy, redirect_uri="/complete/github")
self.user = None
示例15: init_social
def init_social(Base, session, settings):
if TornadoStorage._AppSession is not None:
# Initialize only once. New calls are expected to have the same Base
# and will set the session to be the new session passed.
assert Base == TornadoStorage._Base
TornadoStorage._AppSession.__use_db_session__ = session
return
UID_LENGTH = settings.get(setting_name('UID_LENGTH'), 255)
User = module_member(settings[setting_name('USER_MODEL')])
class _AppSession(object):
@classmethod
def _session(cls):
return _AppSession.__use_db_session__
_AppSession.__use_db_session__ = session
TornadoStorage._AppSession = _AppSession
TornadoStorage._Base = Base
class UserSocialAuth(_AppSession, Base, SQLAlchemyUserMixin):
"""Social Auth association model"""
uid = Column(String(UID_LENGTH))
user_id = Column(Integer, ForeignKey(User.id),
nullable=False, index=True)
user = relationship(User, backref=backref('social_auth',
lazy='dynamic'))
@classmethod
def username_max_length(cls):
return User.__table__.columns.get('username').type.length
@classmethod
def user_model(cls):
return User
class Nonce(_AppSession, Base, SQLAlchemyNonceMixin):
"""One use numbers"""
pass
class Association(_AppSession, Base, SQLAlchemyAssociationMixin):
"""OpenId account association"""
pass
class Code(_AppSession, Base, SQLAlchemyCodeMixin):
pass
# Set the references in the storage class
TornadoStorage.user = UserSocialAuth
TornadoStorage.nonce = Nonce
TornadoStorage.association = Association
TornadoStorage.code = Code