def _get_random_username_from_email(email):
localpart = email.split('@')[0]
cleaned_localpart = re.sub(r'[^\w]', '-', localpart).lower()
# if we can't create a unique user name within this many attempts
# then something else is probably wrong and we should give up
max_name_creation_attempts = 100
for i in range(max_name_creation_attempts):
random_number = random.SystemRandom().random() * 10000
name = '%s-%d' % (cleaned_localpart, random_number)
if not ckan.model.User.get(name):
return name
return cleaned_localpart
## Modifications for rest api
评论列表
文章目录