本文整理汇总了Python中social_auth.backends.pipeline.warn_setting函数的典型用法代码示例。如果您正苦于以下问题:Python warn_setting函数的具体用法?Python warn_setting怎么用?Python warn_setting使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了warn_setting函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create_user
def create_user(backend, details, response, uid, username, user=None, *args,
**kwargs):
"""Create user. Depends on get_username pipeline."""
if user:
return {'user': user}
if not username:
return None
warn_setting('SOCIAL_AUTH_CREATE_USERS', 'create_user')
request = kwargs.get('request')
is_mobile = request.mobile
if is_mobile:
socialauth_not_registered.send(sender=backend.__class__,
uid=uid,
response=response,
details=details)
raise ValueError('Registration is not possible on mobile')
if not getattr(settings, 'SOCIAL_AUTH_CREATE_USERS', True):
# Send signal for cases where tracking failed registering is useful.
socialauth_not_registered.send(sender=backend.__class__,
uid=uid,
response=response,
details=details)
raise ValueError('Registration is currently closed')
email = details.get('email')
return {
'user': User.objects.create_user(username=username, email=email),
'is_new': True
}
开发者ID:drseergio,项目名称:fruitcoins,代码行数:31,代码来源:user.py
示例2: create_user
def create_user(backend, details, response, uid, username, user=None, *args, **kwargs):
"""Create user. Depends on get_username pipeline."""
if user:
return {'user': user}
if not username:
return None
warn_setting('SOCIAL_AUTH_CREATE_USERS', 'create_user')
if not setting('SOCIAL_AUTH_CREATE_USERS', True):
# Send signal for cases where tracking failed registering is useful.
socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details)
return None
email = details.get('email')
request = kwargs["request"]
user = User.objects.create_user(username=username, email=email)
Account.create(request=request, user=user)
EmailAddress.objects.add_email(user, user.email, primary=True)
return {
'user': user,
'is_new': True
}
开发者ID:InQuant,项目名称:crate.web,代码行数:26,代码来源:user.py
示例3: create_user
def create_user(backend, details, response, uid, username, user=None, *args,
**kwargs):
"""Create user. Depends on get_username pipeline."""
if user:
return {'user': user}
if not username:
return None
warn_setting('SOCIAL_AUTH_CREATE_USERS', 'create_user')
if not setting('SOCIAL_AUTH_CREATE_USERS', True):
# Send signal for cases where tracking failed registering is useful.
socialauth_not_registered.send(sender=backend.__class__,
uid=uid,
response=response,
details=details)
return None
email = details.get('email')
if email:
user = User.objects.filter(email=email)
if user:
user = user[0]
else:
user = User.objects.create_user(username=username, email=email)
else:
user = User.objects.create_user(username=username, email=email)
return {
'user': user,
'is_new': True
}
开发者ID:autogestion,项目名称:project_template,代码行数:31,代码来源:pipeline.py
示例4: create_user
def create_user(backend, details, response, uid, username, user=None, *args,
**kwargs):
"""Create user. Depends on get_username pipeline."""
if user:
return {'user': user}
if not username:
return None
warn_setting('SOCIAL_AUTH_CREATE_USERS', 'create_user')
if not setting('SOCIAL_AUTH_CREATE_USERS', True):
# Send signal for cases where tracking failed registering is useful.
socialauth_not_registered.send(sender=backend.__class__,
uid=uid,
response=response,
details=details)
return None
email = details.get('email')
from lfsp.config.middleware import REQUEST_VARS
user = User(network=REQUEST_VARS.domain_config.network, username=username)
user.preferences.email = email
user.save()
return {
'user': user,
'is_new': True
}
开发者ID:Livefyre,项目名称:django-social-auth,代码行数:27,代码来源:user.py
示例5: load_extra_data
def load_extra_data(backend, details, response, social_user, uid, user,
*args, **kwargs):
"""Load extra data from provider and store it on current UserSocialAuth
extra_data field.
"""
warn_setting('SOCIAL_AUTH_EXTRA_DATA', 'load_extra_data')
if setting('SOCIAL_AUTH_EXTRA_DATA', True):
extra_data = backend.extra_data(user, uid, response, details)
if extra_data and social_user.extra_data != extra_data:
social_user.extra_data = extra_data
social_user.save()
开发者ID:Livefyre,项目名称:django-social-auth,代码行数:12,代码来源:social.py
示例6: associate_by_email
def associate_by_email(details, *args, **kwargs):
"""Return user entry with same email address as one returned on details."""
email = details.get('email')
warn_setting('SOCIAL_AUTH_ASSOCIATE_BY_MAIL', 'associate_by_email')
if email and setting('SOCIAL_AUTH_ASSOCIATE_BY_MAIL'):
# try to associate accounts registered with the same email address,
# only if it's a single object. ValueError is raised if multiple
# objects are returned
try:
return {'user': User.objects.get(email=email)}
except MultipleObjectsReturned:
raise ValueError('Not unique email address.')
except User.DoesNotExist:
pass
开发者ID:FrankBie,项目名称:django-social-auth,代码行数:16,代码来源:associate.py
示例7: create_user
def create_user(backend, details, response, uid, username, user=None, *args, **kwargs):
"""Create user. Depends on get_username pipeline."""
if user:
return {"user": user}
if not username:
return None
warn_setting("SOCIAL_AUTH_CREATE_USERS", "create_user")
if not getattr(settings, "SOCIAL_AUTH_CREATE_USERS", True):
# Send signal for cases where tracking failed registering is useful.
socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details)
return None
email = details.get("email")
return {"user": User.objects.create_user(username=username, email=email), "is_new": True}
开发者ID:sbarysiuk,项目名称:django-social-auth,代码行数:16,代码来源:user.py
示例8: associate_by_email
def associate_by_email(details, *args, **kwargs):
"""Return user entry with same email address as one returned on details."""
email = details.get('email')
warn_setting('SOCIAL_AUTH_ASSOCIATE_BY_MAIL', 'associate_by_email')
if email and setting('SOCIAL_AUTH_ASSOCIATE_BY_MAIL', True):
# try to associate accounts registered with the same email address,
# only if it's a single object. AuthException is raised if multiple
# objects are returned
try:
address = EmailAddress.objects.filter(email=email, verified=True).select_related("user").get()
return {"user": address.user}
except MultipleObjectsReturned:
raise AuthException(kwargs['backend'], 'Not unique email address.')
except EmailAddress.DoesNotExist:
pass
开发者ID:InQuant,项目名称:crate.web,代码行数:17,代码来源:associate.py
示例9: get_username
def get_username(details, user=None, *args, **kwargs):
"""Return an username for new user. Return current user username
if user was given.
"""
if user:
return {"username": user.username}
warn_setting("SOCIAL_AUTH_FORCE_RANDOM_USERNAME", "get_username")
warn_setting("SOCIAL_AUTH_DEFAULT_USERNAME", "get_username")
warn_setting("SOCIAL_AUTH_UUID_LENGTH", "get_username")
warn_setting("SOCIAL_AUTH_USERNAME_FIXER", "get_username")
warn_setting("SOCIAL_AUTH_USERNAME_STRICT", "get_username")
if getattr(settings, "SOCIAL_AUTH_FORCE_RANDOM_USERNAME", False):
username = uuid4().get_hex()
elif details.get(USERNAME):
username = details[USERNAME]
elif hasattr(settings, "SOCIAL_AUTH_DEFAULT_USERNAME"):
username = settings.SOCIAL_AUTH_DEFAULT_USERNAME
if callable(username):
username = username()
elif hasattr(settings, "SOCIAL_AUTH_USERNAME_STRICT", False):
username = uuid4().get_hex()
else:
raise ValueError("Invalid username.")
uuid_lenght = getattr(settings, "SOCIAL_AUTH_UUID_LENGTH", 16)
username_fixer = getattr(settings, "SOCIAL_AUTH_USERNAME_FIXER", lambda u: u)
short_username = username[: USERNAME_MAX_LENGTH - uuid_lenght]
final_username = None
while True:
final_username = username_fixer(username)[:USERNAME_MAX_LENGTH]
try:
User.objects.get(username=final_username)
except User.DoesNotExist:
break
else:
# User with same username already exists, generate a unique
# username for current user using username as base but adding
# a unique hash at the end. Original username is cut to avoid
# the field max_length.
username = short_username + uuid4().get_hex()[:uuid_lenght]
return {"username": final_username}
开发者ID:sbarysiuk,项目名称:django-social-auth,代码行数:46,代码来源:user.py
示例10: create_user
def create_user(backend, details, response, uid, username, user=None, *args,
**kwargs):
"""Create user. Depends on get_username pipeline."""
if user:
return {'user': user}
if not username:
return None
warn_setting('SOCIAL_AUTH_CREATE_USERS', 'create_user')
if not getattr(settings, 'SOCIAL_AUTH_CREATE_USERS', True):
################################################################
#Added by brianmckinney to allow us to only invite manly users
###############################################################
from invite.models import Invitation
invite_key = kwargs['request'].session.get('invite', "").strip()
if invite_key:
try:
invite = Invitation.objects.get(key=invite_key)
email = details.get('email')
from invite.views import notify_admins, update_invite
#Notify admins that we have a new user
#notify_admins(username)
#Update date accepted, invite status
user = User.objects.create_user(username=username, email=email)
update_invite(invite_key, username)
return {
'user': user,
'is_new': True
}
except Invitation.DoesNotExist:
pass
############## End edit ###################################
# Send signal for cases where tracking failed registering is useful.
socialauth_not_registered.send(sender=backend.__class__,
uid=uid,
response=response,
details=details)
return None
email = details.get('email')
return {
'user': User.objects.create_user(username=username, email=email),
'is_new': True
}
开发者ID:brianmckinneyrocks,项目名称:django-social-auth,代码行数:45,代码来源:user.py
示例11: associate_by_email
def associate_by_email(details, user=None, *args, **kwargs):
"""Return user entry with same email address as one returned on details."""
if user:
return None
email = details.get('email')
warn_setting('SOCIAL_AUTH_ASSOCIATE_BY_MAIL', 'associate_by_email')
if email and setting('SOCIAL_AUTH_ASSOCIATE_BY_MAIL', False):
# try to associate accounts registered with the same email address,
# only if it's a single object. AuthException is raised if multiple
# objects are returned
try:
return {'user': UserSocialAuth.get_user_by_email(email=email)}
except MultipleObjectsReturned:
raise AuthException(kwargs['backend'], 'Not unique email address.')
except ObjectDoesNotExist:
pass
开发者ID:arnaudbreton,项目名称:django-social-auth,代码行数:19,代码来源:associate.py
示例12: update_user_details
def update_user_details(backend, details, response, user, is_new=False, *args,
**kwargs):
"""Update user details using data from provider."""
changed = False # flag to track changes
warn_setting('SOCIAL_AUTH_CHANGE_SIGNAL_ONLY', 'update_user_details')
# check if values update should be left to signals handlers only
if not setting('SOCIAL_AUTH_CHANGE_SIGNAL_ONLY'):
do_not_update_email = setting('SOCIAL_AUTH_DO_NOT_UPDATE_EMAIL') == True
for name, value in details.iteritems():
# do not update username, it was already generated
if name in (USERNAME, 'id', 'pk'):
continue
if do_not_update_email and name == 'email' and not user.email:
continue
if value and value != getattr(user, name, None):
setattr(user, name, value)
changed = True
# Fire a pre-update signal sending current backend instance,
# user instance (created or retrieved from database), service
# response and processed details.
#
# Also fire socialauth_registered signal for newly registered
# users.
#
# Signal handlers must return True or False to signal instance
# changes. Send method returns a list of tuples with receiver
# and it's response.
signal_response = lambda (receiver, response): response
signal_kwargs = {'sender': backend.__class__, 'user': user,
'response': response, 'details': details}
changed |= any(filter(signal_response, pre_update.send(**signal_kwargs)))
# Fire socialauth_registered signal on new user registration
if is_new:
changed |= any(filter(signal_response,
socialauth_registered.send(**signal_kwargs)))
if changed:
user.save()
开发者ID:Quard,项目名称:django-social-auth,代码行数:43,代码来源:user.py
示例13: create_user
def create_user (backend, details, response, uid, username,
email, password, user = None, *args, **kwargs):
if user:
return {'user':user}
if not username or not email or not password:
return None
warn_setting ('SOCIAL_AUTH_CREATE_USERS', 'create_user')
if not setting('SOCIAL_AUTH_CREATE_USERS', True):
# Send signal for cases where tracking failed registering is useful.
socialauth_not_registered.send(sender=backend.__class__,
uid=uid,
response=response,
details=details)
return None
return {
'user': User.objects.create_user(username=username, email=email, password=password),
'is_new': True
}
开发者ID:boxrice007,项目名称:django-social-auth,代码行数:21,代码来源:pipeline.py
示例14: update_user_details
def update_user_details(backend, details, response, user, is_new=False, *args, **kwargs):
"""Update user details using data from provider."""
changed = False # flag to track changes
warn_setting("SOCIAL_AUTH_CHANGE_SIGNAL_ONLY", "update_user_details")
# check if values update should be left to signals handlers only
if not getattr(settings, "SOCIAL_AUTH_CHANGE_SIGNAL_ONLY", False):
for name, value in details.iteritems():
# do not update username, it was already generated
if name == USERNAME:
continue
if value and value != getattr(user, name, None):
setattr(user, name, value)
changed = True
# Fire a pre-update signal sending current backend instance,
# user instance (created or retrieved from database), service
# response and processed details.
#
# Also fire socialauth_registered signal for newly registered
# users.
#
# Signal handlers must return True or False to signal instance
# changes. Send method returns a list of tuples with receiver
# and it's response.
signal_response = lambda (receiver, response): response
signal_kwargs = {"sender": backend.__class__, "user": user, "response": response, "details": details}
changed |= any(filter(signal_response, pre_update.send(**signal_kwargs)))
# Fire socialauth_registered signal on new user registration
if is_new:
changed |= any(filter(signal_response, socialauth_registered.send(**signal_kwargs)))
if changed:
user.save()
开发者ID:sbarysiuk,项目名称:django-social-auth,代码行数:37,代码来源:user.py
示例15: __call__
def __call__(self, details, user=None, *args, **kwargs):
"""Get a new username.
We check for existing usernames in a case-insensitive way.
"""
if user:
return {'username': user.username}
warn_setting('SOCIAL_AUTH_FORCE_RANDOM_USERNAME', 'get_username')
warn_setting('SOCIAL_AUTH_DEFAULT_USERNAME', 'get_username')
warn_setting('SOCIAL_AUTH_UUID_LENGTH', 'get_username')
warn_setting('SOCIAL_AUTH_USERNAME_FIXER', 'get_username')
if getattr(settings, 'SOCIAL_AUTH_FORCE_RANDOM_USERNAME', False):
username = uuid4().get_hex()
elif details.get(USERNAME):
username = details[USERNAME]
elif settings.hasattr('SOCIAL_AUTH_DEFAULT_USERNAME'):
username = settings.SOCIAL_AUTH_DEFAULT_USERNAME
if callable(username):
username = username()
else:
username = uuid4().get_hex()
uuid_lenght = getattr(settings, 'SOCIAL_AUTH_UUID_LENGTH', 16)
username_fixer = getattr(settings, 'SOCIAL_AUTH_USERNAME_FIXER',
lambda u: u)
short_username = username[:USERNAME_MAX_LENGTH - uuid_lenght]
final_username = None
while True:
final_username = username_fixer(username)[:USERNAME_MAX_LENGTH]
try:
User.objects.get(username__iexact=final_username)
except User.DoesNotExist:
break
else:
# User with same username already exists, generate a unique
# username for current user using username as base but adding
# a unique hash at the end. Original username is cut to avoid
# the field max_length.
username = short_username + uuid4().get_hex()[:uuid_lenght]
return {'username': final_username}
开发者ID:593in,项目名称:transifex,代码行数:45,代码来源:user.py
示例16: get_username
def get_username(details, user=None, user_exists=simple_user_exists,
*args, **kwargs):
"""Return an username for new user. Return current user username
if user was given.
"""
if user:
return {'username': user.username}
warn_setting('SOCIAL_AUTH_FORCE_RANDOM_USERNAME', 'get_username')
warn_setting('SOCIAL_AUTH_DEFAULT_USERNAME', 'get_username')
warn_setting('SOCIAL_AUTH_UUID_LENGTH', 'get_username')
warn_setting('SOCIAL_AUTH_USERNAME_FIXER', 'get_username')
if setting('SOCIAL_AUTH_FORCE_RANDOM_USERNAME'):
username = uuid4().get_hex()
elif details.get(USERNAME):
username = details[USERNAME]
elif details.get("first_name"):
username = details["first_name"]
elif setting('SOCIAL_AUTH_DEFAULT_USERNAME'):
username = setting('SOCIAL_AUTH_DEFAULT_USERNAME')
if callable(username):
username = username()
else:
username = uuid4().get_hex()
uuid_lenght = setting('SOCIAL_AUTH_UUID_LENGTH', 16)
username_fixer = setting('SOCIAL_AUTH_USERNAME_FIXER', lambda u: u)
short_username = username[:USERNAME_MAX_LENGTH - uuid_lenght]
final_username = username_fixer(username)[:USERNAME_MAX_LENGTH]
# Generate a unique username for current user using username
# as base but adding a unique hash at the end. Original
# username is cut to avoid any field max_length.
while user_exists(username=final_username):
username = short_username + uuid4().get_hex()[:uuid_lenght]
final_username = username_fixer(username)[:USERNAME_MAX_LENGTH]
return {'username': final_username}
开发者ID:albertabello,项目名称:Dialogue.io,代码行数:40,代码来源:user.py
示例17: __call__
def __call__(self, details, user=None, *args, **kwargs):
"""Return an username for new user. Return current user username
if user was given.
"""
if user:
return {'username': user.username}
warn_setting('SOCIAL_AUTH_FORCE_RANDOM_USERNAME', 'get_username')
warn_setting('SOCIAL_AUTH_DEFAULT_USERNAME', 'get_username')
warn_setting('SOCIAL_AUTH_UUID_LENGTH', 'get_username')
warn_setting('SOCIAL_AUTH_USERNAME_FIXER', 'get_username')
if setting('SOCIAL_AUTH_FORCE_RANDOM_USERNAME'):
username = uuid4().get_hex()
elif details.get(USERNAME):
username = details[USERNAME]
elif setting('SOCIAL_AUTH_DEFAULT_USERNAME'):
username = setting('SOCIAL_AUTH_DEFAULT_USERNAME')
if callable(username):
username = username()
else:
username = uuid4().get_hex()
uuid_length = setting('SOCIAL_AUTH_UUID_LENGTH', 16)
username_fixer = setting('SOCIAL_AUTH_USERNAME_FIXER', lambda u: u)
short_username = username[:USERNAME_MAX_LENGTH - uuid_length]
final_username = None
while True:
final_username = username_fixer(username)[:USERNAME_MAX_LENGTH]
if self.username_exists(final_username):
# User with same username already exists, generate a unique
# username for current user using username as base but adding
# a unique hash at the end. Original username is cut to avoid
# the field max_length.
username = short_username + uuid4().get_hex()[:uuid_length]
else:
return {'username': final_username}
开发者ID:mpessas,项目名称:django-social-auth,代码行数:40,代码来源:user.py
注:本文中的social_auth.backends.pipeline.warn_setting函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论