本文整理汇总了Python中users.Users.is_valid_user方法的典型用法代码示例。如果您正苦于以下问题:Python Users.is_valid_user方法的具体用法?Python Users.is_valid_user怎么用?Python Users.is_valid_user使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类users.Users
的用法示例。
在下文中一共展示了Users.is_valid_user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from users import Users [as 别名]
# 或者: from users.Users import is_valid_user [as 别名]
def register():
"""
Sending a GET request returns the register.html page.
Sending a POST request validates, then registers the user.
If successful, the user is immediately brought to the sticky note page.
"""
if request.method == 'GET':
return render_template('register.html')
else:
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 len(password) == 0:
return fail_registration("Passwords can not be blank.")
if ' ' in password:
return fail_registration("Passwords can not have spaces")
with closing(shelve.open(users_file)) as user_shelf:
users = Users(user_shelf)
if not users.is_valid_user(username):
flash("Username %s is not valid." % (username))
flash("Either it's taken, it has a space, or it's blank")
return render_template('register.html')
users.register_user(username, password)
session['username'] = username
return redirect(url_for('notes'))