本文整理汇总了Python中social_auth.models.UserSocialAuth.user_username方法的典型用法代码示例。如果您正苦于以下问题:Python UserSocialAuth.user_username方法的具体用法?Python UserSocialAuth.user_username怎么用?Python UserSocialAuth.user_username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类social_auth.models.UserSocialAuth
的用法示例。
在下文中一共展示了UserSocialAuth.user_username方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_username
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import user_username [as 别名]
def get_username(user=None, user_exists=UserSocialAuth.simple_user_exists,
*args, **kwargs):
if user:
return {'username': UserSocialAuth.user_username(user)}
prefix = setting('ACCOUNT_USERNAME_PREFIX', 'user')
max_length = UserSocialAuth.username_max_length()
uuid_length = setting('SOCIAL_AUTH_UUID_LENGTH', 16)
username = None
while username is None or user_exists(username=username):
username = prefix + uuid4().get_hex()[:uuid_length]
username = username[:max_length]
return {'username': username}
示例2: get_username
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import user_username [as 别名]
def get_username(details, user=None,
user_exists=UserSocialAuth.simple_user_exists,
*args, **kwargs):
"""Return an username for new user. Return current user username
if user was given.
"""
if user:
return {'username': UserSocialAuth.user_username(user)}
email_as_username = setting('SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL', False)
uuid_length = setting('SOCIAL_AUTH_UUID_LENGTH', 16)
do_slugify = setting('SOCIAL_AUTH_SLUGIFY_USERNAMES', False)
old_user = User.objects.filter(email=details.get('email')).first()
if old_user:
final_username = old_user.username
return {'username': final_username,
'user': old_user}
if email_as_username and details.get('email'):
username = details['email']
elif details.get('username'):
username = unicode(details['username'])
else:
username = uuid4().get_hex()
max_length = UserSocialAuth.username_max_length()
short_username = username[:max_length - uuid_length]
final_username = UserSocialAuth.clean_username(username[:max_length])
if do_slugify:
final_username = slugify(final_username)
# 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_length]
username = username[:max_length]
final_username = UserSocialAuth.clean_username(username)
if do_slugify:
final_username = slugify(final_username)
return {'username': final_username}
示例3: get_username
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import user_username [as 别名]
def get_username(details, user=None, *args, **kwargs):
if user:
return {'username': UserSocialAuth.user_username(user)}
else:
return {'username': details['username']}