本文整理汇总了Python中users.Users.is_valid_username方法的典型用法代码示例。如果您正苦于以下问题:Python Users.is_valid_username方法的具体用法?Python Users.is_valid_username怎么用?Python Users.is_valid_username使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类users.Users
的用法示例。
在下文中一共展示了Users.is_valid_username方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_user
# 需要导入模块: from users import Users [as 别名]
# 或者: from users.Users import is_valid_username [as 别名]
def add_user():
"""
Register a user, looking up username and password in request.form.
Validates the username and password.
Returns:
A JSON string about the registration status.
"""
username = request.form['username']
password = request.form['password']
confirmation = request.form['confirmPassword']
if not confirmed_password_valid(password, confirmation):
return fail_registration(
"Your password and confirmation didn't match up.")
if password.strip() == '':
return fail_registration("Passwords can not be blank.")
if ' ' in password:
return fail_registration("Passwords can not have spaces")
users = Users(g.database_service)
if not users.is_valid_username(username):
error = """
Username %s is not valid.
Either it's taken, it has a space, or it's blank.
""" % (username)
return fail_registration(error)
new_user = users.register_user(username, password)
session['user_id'] = new_user.get_id()
return success_registration()