本文整理汇总了Python中social_auth.backends.pipeline.warn_setting函数的典型用法代码示例。如果您正苦于以下问题:Python warn_setting函数的具体用法?Python warn_setting怎么用?Python warn_setting使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了warn_setting函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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
}
示例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
}
示例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
}
示例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()
示例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
示例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}
示例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
示例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}
示例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
}
示例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
示例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()
示例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
}
示例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()
示例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}