本文整理汇总了Python中form.LoginForm.validate方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.validate方法的具体用法?Python LoginForm.validate怎么用?Python LoginForm.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类form.LoginForm
的用法示例。
在下文中一共展示了LoginForm.validate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate [as 别名]
def login():
form = LoginForm(request.form)
if request.method == "POST" and form.validate():
if form.username.data == "bsspirit" and form.password.data == "85831923":
session["login"] = True
return redirect(url_for("admin"))
return render_template("login.html")
示例2: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate [as 别名]
def login():
form = LoginForm(request.form)
if request.method == 'POST' and form.validate():
user_id = form.get_user().user_id
session['user_id'] = user_id
return redirect(url_for('user_index', user_id=user_id))
return render_template('login.html', form=form)
示例3: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate [as 别名]
def login(self):
form = LoginForm(request.form)
if request.method == 'POST' and form.validate():
user = form.get_user()
login_user(user)
redirect(url_for('.index'))
self._template_args['form']=form
return super(MyIndexView,self).index()
示例4: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate [as 别名]
def login():
form = LoginForm(request.form)
result = '';
if request.method == 'POST' and form.validate():
u = User.query.filter_by(email=form.email.data).first()
if u == None:
flash('User not exists.', 'warning')
else:
user = User(u.email, '', u.nick_name)
user.id = u.id
user.password_hash = u.password_hash
if user.verify_password(form.password.data):
login_user(user, remember=form.remember.data)
# flash('Hi~ %s, you just login success.' % user.getDisplayName(), 'warning')
return redirect(url_for('main.index'))
else:
flash('password incorrect', 'error')
return render_template('login.html', title='login', form=form);
示例5: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate [as 别名]
def login():
"""Render the website's login page."""
try:
form = LoginForm(csrf_enabled=False)
if request.method == "POST":
if form.validate()==False:
flash('All fields are required.')
return render_template('login.html',form=form)
else:
c, conn = connection()
data = c.execute("SELECT * FROM user WHERE email = '"+thwart(form.Email.data)+"'")
data = c.fetchone()[2]
user_id = c.fetchone()[0]
if bcrypt.check_password_hash(data,form.password.data):
session['logged_in'] = True
session['email'] = form.Email.data
session['user_id'] = str(user_id)
flash("You are now logged in")
return render_template("home.html")
else:
error = "Invalid credentials, try again."
return render_template("login.html", form=form ,error = error)
gc.collect()
elif request.method=='GET':
return render_template('login.html', form=form)
except Exception as e:
#flash(e)
error = "Invalid credentials, try again."
return render_template("login.html", form=form ,error = error)