def create_or_get_user_db(auth_id, name, username, email='', **kwargs):
"""This function will first lookup if user with given email already exists.
If yes then it will append auth_id for his record and saves it.
If not we'll make sure to find unique username for this user (for the case of signing up via social account)
and then store it into datastore"""
user_db = model.User.get_by('email', email.lower())
if user_db:
user_db.auth_ids.append(auth_id)
user_db.put()
return user_db
if isinstance(username, str):
username = username.decode('utf-8')
username = unidecode.unidecode(username.split('@')[0].lower()).strip()
username = re.sub(r'[\W_]+', '.', username)
new_username = username
suffix = 1
while not model.User.is_username_available(new_username):
new_username = '%s%d' % (username, suffix)
suffix += 1
return create_user_db(auth_id, name, new_username, email=email, **kwargs)
评论列表
文章目录