本文整理汇总了Python中form.LoginForm类的典型用法代码示例。如果您正苦于以下问题:Python LoginForm类的具体用法?Python LoginForm怎么用?Python LoginForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LoginForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
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)
示例2: login
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: home
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)
示例4: login
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)
示例5: login
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)
示例6: login
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)
示例7: login
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")
示例8: usLogin
def usLogin(request):
context = {}
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
us = form.cleaned_data['us']
pwd = form.cleaned_data['pwd']
if r.exists('us:%s:id' %us): # 检查是否存在该用户关系键值
uid = r.get('us:%s:id' %us) # 获取该用户在user表中对应的id
if r.exists('user:%s' %uid): # 检查是否存在该用户键值(如user:1)
us_, pwd_ = r.hmget('user:%s' %uid, 'username', 'pwd') # 获取该用户的用户名密码
if us_ == us and pwd_ == pwd: # 校验成功
r.hincrby('user:%s' %uid, 'login_count', 1) # 登陆次数累加
r.hset('user:%s' %uid, 'last_login_date', datetime.datetime.now()) # 添加最近登陆
# set Cookies
res = HttpResponseRedirect('/')
ussys = usSystem(request, res, uid)
if ussys.testCookie() and ussys.setCookieAndSession():
return res
context['msg'] = u'账号或密码错误'
context['form'] = form
request.session.set_test_cookie()
form = LoginForm()
context['form'] = form
return render(request, 'login.html', context)
示例9: login
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)
示例10: login
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()
示例11: login
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)
示例12: login
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'])
示例13: user_register
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)
示例14: user_login
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)
示例15: login
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)