本文整理汇总了Python中app.forms.LoginForm.has_been_submitted方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.has_been_submitted方法的具体用法?Python LoginForm.has_been_submitted怎么用?Python LoginForm.has_been_submitted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.forms.LoginForm
的用法示例。
在下文中一共展示了LoginForm.has_been_submitted方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import has_been_submitted [as 别名]
def index():
"""
TODO: Handle if user is connected
start_div is the div displayed on page load. Useful for forms with errors
"""
# Uncomment to force https on that page (maybe just for user login ?)
# if not app.config['DEBUG']: # and current_user.is_anonymous()
# if request.scheme == "http":
# return redirect(url_for("index", _scheme="https"))
if current_user.is_authenticated():
return render_template("blog/blog_explore.html", **explore_context())
start_div = "home-div"
login_form = LoginForm(request.form, prefix="login")
register_form = RegisterForm(request.form, prefix="register")
if login_form.has_been_submitted(request):
if login_form.validate_on_submit():
user = User.query.filter_by(username=login_form.username.data).first()
login_user(user, remember=login_form.rememberme.data)
user.last_login = datetime.now()
user.save()
flash("Your are now logged in.", category="info")
return redirect(url_for('index'))
else:
start_div = "login-div"
if register_form.has_been_submitted(request):
if register_form.validate_on_submit():
new_user = User(username=register_form.username.data, password=register_form.password.data, active=True,
superuser=False)
new_user.save()
return redirect(url_for('index'))
else:
start_div = "registration-div"
return render_template("index.html", login_form=login_form, register_form=register_form, start_div=start_div)