本文整理汇总了Python中forms.LoginForm.check_user方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.check_user方法的具体用法?Python LoginForm.check_user怎么用?Python LoginForm.check_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.LoginForm
的用法示例。
在下文中一共展示了LoginForm.check_user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import check_user [as 别名]
def login():
if g.user is not None and g.user.is_authenticated():
return redirect(url_for('index'))
loginform = LoginForm(prefix='loginform')
registerform = RegisterForm(prefix='registerform')
if loginform.validate_on_submit():
try:
loginform.check_user(loginform.username.data, loginform.password.data)
except ValidationError:
return render_template('login.html', loginform = loginform, registerform = registerform)
else:
if User.query.filter_by(username=loginform.username.data).first() is not None:
user = User.query.filter_by(username=loginform.username.data).first()
else:
user = User.query.filter_by(email=loginform.username.data).first()
login_user(user)
session['remember_me'] = loginform.remember_me.data
flash('Successful login')
return redirect('/index')
elif registerform.validate_on_submit():
username = registerform.username.data
email = registerform.email.data
password = registerform.password.data
try:
registerform.check(username, email)
except ValidationError:
return render_template('login.html', loginform = loginform, registerform = registerform, registererror=True)
else:
newuser = User(username=username, email=email)
newuser.set_password(password)
db.session.add(newuser)
db.session.commit()
usr=User.query.filter_by(username=username).first()
login_user(usr)
flash('Successful registration')
return redirect('/index')
return render_template('login.html', loginform = loginform, registerform = registerform)