本文整理汇总了Python中app.forms.LoginForm.validate_on_submit方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.validate_on_submit方法的具体用法?Python LoginForm.validate_on_submit怎么用?Python LoginForm.validate_on_submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.forms.LoginForm
的用法示例。
在下文中一共展示了LoginForm.validate_on_submit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import validate_on_submit [as 别名]
def login():
# if user is logged in, redirect them to index
if g.user is not None and g.user.is_authenticated():
return redirect(url_for('index'))
form = LoginForm()
# tries to login user
if form.validate_on_submit():
username = form.username.data
password = form.password.data
session['remember_me'] = form.remember_me.data
registered_user = User.query.filter_by(username=username).first()
if registered_user is not None:
if registered_user.check_password(password):
remember_me = False
if 'remember_me' in session:
remember_me = session['remember_me']
session.pop('remember_me', None)
login_user(registered_user, remember = remember_me)
flash('Logged in successfully')
return redirect(request.args.get('next') or url_for('index'))
else:
form.password.errors.append("Invalid password!")
else:
form.username.errors.append("Invalid username!")
return render_template('login.html', title = 'Sign In', form = form)
示例2: index
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import validate_on_submit [as 别名]
def index():
login = LoginForm()#login objekti
if request.method == 'GET':#29.1.2016 lisätty alla oleva
return render_template('template_index.html',form=login,isLogged=False)
else:
#check if form data is valid
if login.validate_on_submit():#tsekkaa onko formit valideja
#3.2.2016 Check if correct username or password
#user = Users.query.filter_by(email=login.email.data).filter_by(passw=login.passw.data)
#yllä oleva luo SQL-lauseen: Select email passw From User Where email="?" And passw="?"
#4.2.2016 passw on kryptattu
# Check if correct username
user = Users.query.filter_by(email=login.email.data)
print(user)
#if user.count() == 1:#3.2.2016 jos palautetun taulukon koko on yksi
#4.2.2016: user[0].passw = kryptattu salasana
if (user.count() == 1) and (check_password_hash(user[0].passw,login.passw.data)):
print(user[0])
session['user_id'] = user[0].id#tallennetaan käyttäjän ID
session['isLogged'] = True
print(session['user_id'])
#Haetaan ystävät
#tapa 1 listata ystävät
friends = Friends.query.filter_by(user_id =user[0].id)
print(friends)
return render_template('template_user.html',isLogged=True,friends=friends)
else:
flash('Wrong email or password')
return render_template('template_index.html',form=login,isLogged=False)
#form data was not valid
else:
flash('Give proper information to email and password fields!')#näyttö toteutettu base.html:ssä (kalvo s.56)
return render_template('template_index.html',form=login,isLogged=False)
示例3: login
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.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 request.method == 'POST':
if form.validate_on_submit():
from user_auth import get_user_auth_row
condition = {
'auth_type': 'email',
'auth_key': form.email.data,
'auth_secret': form.password.data
}
user_auth_info = get_user_auth_row(**condition)
if user_auth_info is None:
flash(u'%s, You were logged failed' % form.email.data, 'warning')
return render_template('login.html', title='login', form=form)
if user_auth_info.verified == 0:
flash(u'%s, Please verify email address in mailbox' % form.email.data, 'warning')
return render_template('login.html', title='login', form=form)
# session['logged_in'] = True
# 用户通过验证后,记录登入IP
from user import edit_user
edit_user(user_auth_info.user_id, {'last_ip': request.headers.get('X-Forwarded-For', request.remote_addr)})
# 用 login_user 函数来登入他们
from user import get_user_row_by_id
login_user(get_user_row_by_id(user_auth_info.user_id))
flash(u'%s, You were logged in' % form.email.data, 'success')
return redirect(request.args.get('next') or url_for('index'))
flash(form.errors, 'warning') # 调试打开
return render_template('login.html', title='login', form=form)
示例4: index
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import validate_on_submit [as 别名]
def index():
login = LoginForm()
#Check if get method
if request.method == 'GET':
return render_template('template_index.html',form=login,isLogged=False)
else:
#check if form data is valid
if login.validate_on_submit():
#Check id correct useranme and password
user = Users.query.filter_by(email=login.email.data)
print(user)
if user.count(user.count() == 1) and (check_password_hash(user[0].passw,login.passw.data)):
print(user[0])
session['user_id'] = user[0].id
session['isLogged'] = True
#tapa 1
friends = Friends.query.filter_by(user_id=user[0].id)
print(friends)
return render_template('template_user.html',isLogged=True,friends=friends)
else:
flash('Wrong email or password')
return render_template('template_index.html',form=login,isLogged=False)
#form data was not valid
else:
flash('Give proper information to email and password fields!')
return render_template('template_index.html',form=login,isLogged=False)
示例5: login
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import validate_on_submit [as 别名]
def login():
"""Show login page.
Unauthorized users will always be redirected to this view when attempting
to access a protected view. Upon successful authorization the user will
be redirected to the protected view the unauthorized user was trying to
access. Default redirection is to the admin overview page.
"""
form = LoginForm()
if form.validate_on_submit():
login_user(user=form.user, remember=form.remember_me.data)
at = datetime.utcnow()
ip = request.remote_addr or 'unknown'
current_user.last_login_at = current_user.current_login_at or at
current_user.last_login_ip = current_user.current_login_ip or ip
current_user.current_login_at = at
current_user.current_login_ip = ip
db.session.commit()
return redirect(url_for('admin.overview'))
return render_template('auth/login.html', form=form)
示例6: login
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import validate_on_submit [as 别名]
def login():
"""Logging in the user."""
form = LoginForm()
if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data).first()
# Do not allow user who registered with a social account to log
# via the login form. Use the social login buttons instead
if user is not None and user.register_with_provider:
flash('Please login with your social account')
return redirect(url_for('mod_auth.login'))
if user is not None and user.verify_password(form.password.data):
# The user must be activated
if not user.confirmed:
flash('You need to activate your account first')
return redirect(url_for('mod_auth.login'))
# Log the user in
login_user(user, remember=form.remember.data)
return redirect(request.referrer or url_for('mod_feed.index'))
# Redirect to login page with an error message
flash('Invalid email, password')
return render_template('auth/login.html', form=form)
示例7: login
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import validate_on_submit [as 别名]
def login():
if request.method == 'POST' and 'User-Agent' not in request.headers:
email = request.form['email']
password = request.form['password']
if email and password:
user = Users.query.filter_by(email=email).first()
if user and user.verify_password(password):
g.user = user
token = user.generate_auth_token(600)
return jsonify({'error':'null', 'data':{'token': token.decode('ascii'), 'expires': 600, 'user':{'id': user.id, 'email': user.email, 'name': user.name}, 'message':'success'}})
return jsonify({'error': '1', 'data':{}, 'message':'Bad user name or password'})
if g.user is not None and g.user.is_authenticated:
return redirect(url_for('home'))
form = LoginForm()
if request.method == 'POST' and 'User-Agent' in request.headers:
if form.validate_on_submit():
uname = request.form['username']
pword = request.form['password']
user = Users.query.filter_by(email=uname).first()
if user is None:
return redirect(url_for('login'))
login_user(user)
return redirect(request.args.get("next") or url_for('wishlist',id=g.user.id))
return render_template(
'login.html',
title='User Login',
year=datetime.now().year,
form=form,
user=g.user
)
示例8: home
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import validate_on_submit [as 别名]
def home():
"""
首页视图函数
1. 最近录入
2. 最近借阅
new_book_list: 最近录入新书列表(默认为6本, 依据时间[id]排序)
"""
form = LoginForm()
new_book_list = Book.query.order_by('-id').all()
get_book_list = Book.query.filter_by(status=True).order_by('start desc').all()[:2]
if form.validate_on_submit():
user = User.query.filter_by(username=form.username.data).first()
if user is not None and user.verify_password(form.password.data):
login_user(user)
return redirect(url_for('user', id=current_user.id))
flash('用户名或密码错误!')
range_book_count = range(len(new_book_list)/6 + 1)
return render_template('home.html', new_book_list=new_book_list,
get_book_list=get_book_list, form=form,
range_book_count=range_book_count)
示例9: index
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import validate_on_submit [as 别名]
def index():
login = LoginForm()
# Check if get method
if request.method == "GET":
return render_template("template_index.html", form=login, isLogged=False)
else:
# check if form data is valid
if login.validate_on_submit():
# Check if corret username and password
user = Users.query.filter_by(email=login.email.data)
if (user.count() == 1) and (check_password_hash(user[0].passw, login.passw.data)):
print(user[0])
session["user_id"] = user[0].id
session["isLogged"] = True
# Tapa 1
friends = Friends.query.filter_by(user_id=user[0].id)
print(friends)
return render_template("template_user.html", isLogged=True, friends=friends)
else:
flash("Wrong email or password")
return render_template("template_index.html", form=login, isLogged=False)
# form data was not valid
else:
flash("Give proper imformation to email and password fields!")
return render_template("template_index.html", form=login, isLogged=False)
示例10: login
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import validate_on_submit [as 别名]
def login():
form = LoginForm(login=request.args.get("login", None),
next=request.args.get("next", None))
# TBD: ensure "next" field is passed properly
if form.validate_on_submit():
user, authenticated = \
User.query.authenticate(form.login.data,
form.password.data)
if user and authenticated:
# Flask-Login
login_user(user, remember = form.remember.data)
# change identity
identity=Identity(user.username)
identity_changed.send(current_app._get_current_object(),
identity = identity)
# next_url
next_url = form.next.data
if not next_url or next_url == 'home.index':
next_url = url_for('user.jobs', username=user.username)
flash(u"登录成功", "successfully")
return redirect(next_url)
else:
flash(u"账号或密码错误", "error")
return render_template("account/login.html", form=form)
示例11: authenticate
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import validate_on_submit [as 别名]
def authenticate(project):
print "authenticate"
print current_user, current_user.is_authenticated()
if not current_user.is_authenticated():
print "logging in user"
user = User()
db.session.add(user)
db.session.commit()
login_user(user)
if project in current_user.projects:
print "p:", project
current_user.current_project = project
db.session.commit()
return redirect(url_for('.project', project=project))
form = LoginForm()
if form.validate_on_submit():
print "p:", project
current_user.current_project = project
current_user.projects.append(project)
db.session.commit()
return redirect(url_for('.project', project=project))
return render_template('authenticate.html',
project=project,
form=form)
示例12: login
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.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)
示例13: login
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.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()
login_user(user, remember=True)
return redirect(url_for("dashboard"))
return render_template('signup.html', signup_form=SignupForm(), login_form=form)
示例14: login
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import validate_on_submit [as 别名]
def login():
form = LoginForm()
if form.validate_on_submit():
if app.config['AUTH_TYPE'] == 'ldap':
user_obj = UserLDAP()
elif app.config['AUTH_TYPE'] == 'plain':
user_obj = UserPlain()
else:
flash(gettext('Unknown authentication type.'), 'warning')
return render_template('home.html', login_form=form)
# find user and check password
user, error = user_obj.get_by_username_w_password(form.username.data, form.password.data)
if user is None:
flash(error, 'warning')
else:
if login_user(user, remember=form.remember_me.data):
flash(gettext('Logged in successfully.'), 'success')
return redirect(url_for('search'))
else:
flash(gettext('Unable to log you in.'), 'warning')
return redirect(url_for('home'))
else:
flash_form_errors(form)
return render_template('home.html', login_form=form)
示例15: login
# 需要导入模块: from app.forms import LoginForm [as 别名]
# 或者: from app.forms.LoginForm import validate_on_submit [as 别名]
def login():
form = LoginForm()
if form.validate_on_submit():
j_ldap.ldap_login(form.username.data,form.password.data)
return render_template('login.html',
title = 'Sign In',
form = form )