本文整理汇总了Python中form.LoginForm.validate_on_submit方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.validate_on_submit方法的具体用法?Python LoginForm.validate_on_submit怎么用?Python LoginForm.validate_on_submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类form.LoginForm
的用法示例。
在下文中一共展示了LoginForm.validate_on_submit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: home
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate_on_submit [as 别名]
def home():
"""HOMEPAGE"""
# if user hasn't logged out redirect won't reload login page
if current_user is not None and current_user.is_authenticated():
return render_template("main.html")
message = ""
message3 = ""
form = LoginForm()
# following occurs if form conditions are met
if form.validate_on_submit():
# query for the user in the database by email. If the user exists then the hashed password
# is verified. If this password matches the email the user is logged in
user = model.session.query(model.User).filter_by(email = form.email.data).first()
if user:
# salt_unicode = user.salt
# salt = salt_unicode.encode('utf-8')
password_unicode = form.password.data
password = password_unicode.encode('utf-8')
# hashed = bcrypt.hashpw(password, salt)
if password == user.password_hash:
# if hashed == user.password_hash:
login_user(user)
else:
message3 = "Incorrect password"
return render_template("main.html", form=form, message3=message3)
message = "welcome back %s" % current_user.nickname
return render_template("main.html", message=message)
message3 = "It appears we don't have that account on file"
return render_template("main.html", form=form, message3=message3)
示例2: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate_on_submit [as 别名]
def login():
form = LoginForm()
error = None
if request.method == 'GET' and request.args.get('next'):
session['next'] = request.args.get('next', None)
if form.validate_on_submit():
user = User.query.filter_by(
username=form.username.data
).first()
if user:
if bcrypt.hashpw(form.password.data.encode('utf8'), salt) == user.password:
session['username'] = user.username
if 'next' in session:
next = session.get('next')
session.pop('next')
return redirect(next)
else:
return redirect(url_for('index'))
else:
error = "Incorrect password"
else:
error = "User not found"
return render_template('user/login.html', form=form, error=error)
示例3: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate_on_submit [as 别名]
def login():
form = LoginForm()
if form.validate_on_submit():
login_user(form.admin)
flash("Logged in successfully.")
return redirect(request.args.get("next") or url_for("index"))
return render_template("login.html", form=form)
示例4: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate_on_submit [as 别名]
def login():
form = LoginForm()
if form.validate_on_submit():
flash('Login requested for OpenID="%s", remember_me=%s'%
(form.openid.data, str(form.remember_me.data)))
return redirect('/index')
return render_template('login.html', title = 'Sign In', form = form)
示例5: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate_on_submit [as 别名]
def login():
error = None
form = LoginForm(request.form)
if request.method == 'POST':
# if valid_login(
# request.form['username'],
# request.form['password']):
# return "Welcome Back, %s" % request.form.get('username')
# else:
# error = "Incorrent username and password"
if form.validate_on_submit():
user = User.query.filter_by(username=form.username.data).first()
if user:
if bcrypt.check_password_hash(user.password, form.password.data):
session['username'] = form.username.data
session['is_author'] = user.is_author
return redirect('/login_success')
error ='Incorrect password'
# user = User.query.filter_by(
# username=form.username.data,
# password=form.password.data).limit(1)
return render_template("user/login.html", error=error, form=form)
示例6: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate_on_submit [as 别名]
def login():
errors = []
form = LoginForm()
if request.method == 'POST':
if form.validate_on_submit() == False:
flash('All fields are required')
return render_template('login.html', form = form)
else:
email = request.form['email']
password = request.form['password']
print email , password
db = connect_db()
try:
user_info = auth.authenticate_using_password(email, password, db)
print user_info
except BadPasswordError:
flash("InValid Password")
response = make_response(redirect(url_for('login')))
return response
except NoUserExistsError:
flash("No User Exists")
response = make_response(redirect(url_for('login')))
return response
session['access_token']= user_info['access_token']
print "this is sesssion info: %s" %(dir(session))
response = make_response(redirect(url_for('users')))
return no_cache(response)
else:
return render_template('login.html', form = form)
示例7: user_login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate_on_submit [as 别名]
def user_login():
form = LoginForm()
if form.validate_on_submit():
user = users.get_user(form.name.data)
login_user(user)
user.set('authenticated', True)
flash('Login successful.', 'success')
return redirect(request.args.get("next") or url_for('index'))
return render_template('login.html', form=form)
示例8: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate_on_submit [as 别名]
def login():
form = LoginForm()
if form.validate_on_submit():
flash('Login requested for OpenID="' + form.openid.data + '", remember_me=' + str(form.remember_me.data))
return redirect('/index')
return render_template('login.html',
title = 'Sign In',
form = form,
providers = app.config['OPENID_PROVIDERS'])
示例9: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate_on_submit [as 别名]
def login():
form = LoginForm()
if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data).first()
if user is not None and user.verify_password(form.password.data):
login_user(user, form.remember_me.data)
return redirect(url_for('main.index'))
flash("Invalid username or password")
return render_template('auth/login.html', form=form)
示例10: user_register
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate_on_submit [as 别名]
def user_register():
name=None
form = LoginForm(request.form)
if request.method=='POST':
if form.validate_on_submit():
session['name'] = request.form['username']
session['logged_in'] = True
return redirect(url_for('newgame'))
return render_template('login.html', form=form)
示例11: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate_on_submit [as 别名]
def login():
form = LoginForm(csrf_enabled=False)
if form.validate_on_submit():
user = User.query.filter_by(username = form.username.data).first()
if user is not None and User.query.filter_by(password = form.password.data).first():
login_user(user)
return redirect(url_for('admin'))
else:
return redirect(url_for('login'))
return render_template('login.html', form = form)
示例12: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate_on_submit [as 别名]
def login():
if g.user is not None and g.user.is_authenticated():
return redirect(url_for('index'))
form = LoginForm()
if form.validate_on_submit():
session['remember_me'] = form.remember_me.data
return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
return render_template('login.html',
title='Sign In',
form=form,
providers=settings.OPENID_PROVIDERS)
示例13: login_in
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate_on_submit [as 别名]
def login_in():
form=LoginForm()
user=form.name.data
password=form.password.data
if form.validate_on_submit():
if user=="ioiogoo" and password=="1":
session["name"]=form.name.data
return redirect(url_for("index"))
flash("password false!")
return redirect(url_for("login_in"))
return render_template("login.html",form=form)
示例14: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate_on_submit [as 别名]
def login():
form = LoginForm()
if form.validate_on_submit():
m_usr = User.get_by_username(form.username.data)
# app.logger.debug(m_usr)
if m_usr is not None and m_usr.check_password(form.password.data):
# set flask-login to remember the user's ID in HTTP session
login_user(m_usr, form.remember_me.data)
flash("{} login successfully!".format(m_usr.username))
# after login successfully it can direct back add view
return redirect(request.args.get('next') or url_for('index'))
flash('User Inputs are not match!')
return render_template("login.html", form= form)
示例15: login
# 需要导入模块: from form import LoginForm [as 别名]
# 或者: from form.LoginForm import validate_on_submit [as 别名]
def login():
form = LoginForm()
if form.validate_on_submit():
user = UserModel.query.filter_by(email = form.email.data).first()
if user is not None and user.verify_password(form.password.data):
login_user(user, form.remember_me.data) #记录登录IP和时间
db.session.add(UserLoginInfoModel(uid=current_user.id, ip=request.remote_addr, ltime=datetime.now()))
db.session.commit()
return redirect(request.args.get('next') or url_for('main.index'))
else:
flash_errors(form)
return render_template('/login.html', form=form)