本文整理汇总了Python中forms.LoginForm.validate_on_submit方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.validate_on_submit方法的具体用法?Python LoginForm.validate_on_submit怎么用?Python LoginForm.validate_on_submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.LoginForm
的用法示例。
在下文中一共展示了LoginForm.validate_on_submit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate_on_submit [as 别名]
def login():
form = LoginForm()
if request.method == "POST":
# change this to actually validate the entire form submission
# and not just one field
if form.validate_on_submit():
# Get the username and password values from the form.
u_name= form.username.data
password = form.password.data
user = UserProfile.query.filter_by(username=u_name,password= password).first()
# using your model, query database for a user based on the username
# and password submitted
# store the result of that query to a `user` variable so it can be
# passed to the login_user() method.
# get user id, load into session
if user:
login_user(user)
flash("Successful Login","success")
return redirect(url_for("secure_page"))
# remember to flash a message to the user
return redirect(url_for("home")) # they should be redirected to a secure-page route instead
return render_template("login.html", form=form)
示例2: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate_on_submit [as 别名]
def login():
error = None
form = LoginForm(request.form)
if request.method == 'POST':
if form.validate_on_submit():
u = User.query.filter_by(
name=request.form['name'],
password=request.form['password']
).first()
if u is None:
error = 'Invalid username or password.'
return render_template(
"login.html",
form=form,
error=error
)
else:
session['logged_in'] = True
session['user_id'] = u.id
session['role'] = u.role
flash('You are logged in. Go Crazy.')
return redirect(url_for('tasks.tasks'))
else:
return render_template(
"login.html",
form=form,
error=error
)
if request.method == 'GET':
return render_template('login.html', form=form)
示例3: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate_on_submit [as 别名]
def login():
form = LoginForm(request.form)
if request.method == 'POST' and form.validate_on_submit():
user = form.get_user()
login_user(user, remember=True)
return redirect(url_for('main'))
return render_template('login.jade', form=form)
示例4: refresh
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate_on_submit [as 别名]
def refresh():
form = LoginForm()
if form.validate_on_submit():
confirm_login()
flash("Authentication refreshed", "success")
return redirect(request.args.get("next") or url_for("index"))
return render_template("login.html", login_form=form)
示例5: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from 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_l = LoginForm()
form_s = SignUpForm()
if form_l.validate_on_submit() and (len(form_l.openid.data) < 100) and (len(form_l.password.data) < 100):
session['remember_me'] = form_l.remember_me.data
user = db.session.query(User).filter(User.email == form_l.openid.data).filter(User.password == md5(form_l.password.data).hexdigest()).first()
if user is not None:
login_user(user, remember = form_l.remember_me.data)
return redirect(url_for('index'))
else:
print("NOT FOUND")
if form_s.validate_on_submit() and (len(form_s.email.data) < 100) and (len(form_s.login.data) < 50) and (len(form_s.password.data) < 100):
k = False
user = db.session.query(User).filter(User.email == form_s.email.data or User.nickname == form_s.login.data).first()
if user is None:
u = User(nickname=form_s.login.data, email=form_s.email.data, password=md5(form_s.password.data).hexdigest())
db.session.add(u)
db.session.commit()
db.session.add(u.follow(u))
db.session.commit()
login_user(u)
return redirect(url_for('index'))
else:
print("EXISTS")
return render_template('login1.html',
form_l = form_l,
form_s = form_s)
示例6: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate_on_submit [as 别名]
def login():
'''
form is imported from froms.py
session["logged_in"] is a boolean wether or not someone is logged in
if you are already logged in you dont need to login, so you are redirected
to index
session['alias'] is the alias of the user that is currently logged in
session['allowTracking'] is wether or not the user is to be tracked
session['isMod'] is wether or not user is a moderator/advanced permission
flash returns a string to be delayed
'''
form = LoginForm()
if session.get('logged_in'):
return redirect(url_for('index'))
if form.validate_on_submit():
try:
user = User.objects(email=form.email.data)[0]
if check_password_hash(user.password, form.password.data):
session['logged_in'] = True
session['alias'] = user.alias
session['allowTracking'] = user.allowTracking
session['isMod'] = user.isMod
return redirect(url_for('index'))
else:
flash('Wrong password')
except:
flash('Wrong email, silly!')
return render_template('login.html', form = form)
示例7: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate_on_submit [as 别名]
def login():
error = None
form = LoginForm()
next = get_redirect_target()
next = retain_before_auth_page(next)
print request.method
if request.method == 'POST':
if request.form['submit'] == 'cancel':
return redirect_back('index')
else:
if form.validate_on_submit():
session['remember_me'] = True
user = User.query.filter_by(username=form.username.data).first()
if user:
if bcrypt.check_password_hash(str(user.password), str(form.password.data)):
login_user(user)
flash('You were logged in. ', 'success')
return redirect_back('index')
else:
flash('Invalid email or password.', 'danger')
return render_template('login.html', form=form, error=error)
else:
flash('Invalid email or password.', 'danger')
return render_template('login.html', form=form, error=error, next=next)
else:
flash('Invalid email or password.', 'danger')
return render_template('login.html', form=form, error=error, next=next)
else:
return render_template('login.html', form=form, error=error, next=next)
示例8: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate_on_submit [as 别名]
def login():
error = None
form = LoginForm()
if request.method == 'POST':
if request.form.get('submit') == 'Register':
return redirect(url_for('UsersFiles.register'))
elif form.validate_on_submit():
session.permanent = True
Log("LOGIN")
# compare hash
addCompHash(str(current_user))
flash('You are just login!')
try:
if isHack(str(current_user)):
flash('!!!!! YOU GOT HACK !!!!!!')
except:
flash('First time login')
return redirect(url_for('HomeFiles.home'))
else:
error = 'Invalid username or password. Please try again.'
Log("LOGIN FAIL")
return render_template('login.html', form=form, error=error)
elif request.method == 'GET':
return render_template('login.html', form=form)
示例9: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate_on_submit [as 别名]
def login():
form = LoginForm()
if 'user' in session:
print session['user']
return redirect('/')
if form.validate_on_submit():
userExists = Professor.query.filter_by(username=form.username.data).first()
passwordExists = Professor.query.filter_by(password=form.password.data).first()
print passwordExists
print userExists
if userExists and passwordExists:
print 'exists! login successful!'
session['user'] = form.username.data
print 'THIS IS THE COOKIE-->'
print session['user']
flash('Login Successful for user "%s"' % (form.username.data))
# flash('Login Successful for user "%s" with password "%s"' % (form.username.data, str(form.password.data)))
return redirect('/index')
else:
print type(form.password.errors)
print form.password.errors.append("Please enter valid credentials")
return render_template('login.html', title='Sign In', form=form)
示例10: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate_on_submit [as 别名]
def login():
form = LoginForm(request.form)
if request.method == 'GET':
return render_template("login.html", form=form)
elif request.method == 'POST':
form_is_valid = form.validate_on_submit()
if form_is_valid:
username = form.username.data
password = form.password.data
registered_user = User.query.\
filter_by(username=username).first()
remember_me = False
if 'remember_me' in request.form:
remember_me = True
if registered_user is not None and \
bcrypt.check_password_hash(
registered_user.password, password):
login_user(registered_user, remember=remember_me)
flash('Login successful')
return redirect(request.args.get('next') or url_for('index'))
else:
flash('Username or password is invalid', 'error')
return render_template('login.html', form=form)
else:
return render_template('login.html', form=form)
示例11: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate_on_submit [as 别名]
def login():
'''
Handle login functions
This function handles both the initial login page and the results
'''
#if the user is already logged, redirect them to the homepage
if g.user is not None and g.user.is_authenticated() and \
len(g.user.username) > 0:
return redirect(url_for('home'))
else:
form = LoginForm(request.form)
#if they've submitted it with valid credentials, try to log in the user
#whether or not we can log them in, redirect them home
if form.validate_on_submit():
user = User.query.filter(User.username == form.username.data).first()
hashed_password = hash_password(form.password.data)
if user is not None and user.hashed_password == hashed_password:
login_user(user)
return redirect(url_for('home'))
#otherwise, show them the form
else:
return render_template('login.html', form = form)
示例12: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate_on_submit [as 别名]
def login():
if current_user.is_authenticated():
return redirect('index')
form = LoginForm()
if form.validate_on_submit():
user = User.login_check(request.form.get('user_name'))
if user:
login_user(user)
user.last_seen = datetime.datetime.now()
try:
db.session.add(user)
db.session.commit()
except:
flash("The Database error!")
return redirect('/login')
flash('Your name: ' + request.form.get('user_name'))
flash('remember me? ' + str(request.form.get('remember_me')))
return redirect(url_for("users", user_id=current_user.id))
else:
flash('Login failed, Your name is not exist!')
return redirect('/login')
return render_template(
"login.html",
title="Sign In",
form=form)
示例13: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate_on_submit [as 别名]
def login(page = 1):
form = LoginForm()
user = g.user
if user is not None and user.is_authenticated():
return redirect(url_for('index'))
if form.validate_on_submit():
#checks if form is left empty
if form.username.data == None or form.password.data == None:
return redirect(url_for('index'))
#allows user to login with email
if form.username.data.find('@') != -1:
username = form.username.data.split('@')[0]
else:
username = form.username.data
user = models.User.query.filter_by(username=username).first()
#if username cannot be found
if user == None:
flash('User not found.')
return redirect(url_for('index'))
#checks if passwords match
if check_password_hash(user.password,form.password.data):
login_user(user)
if form.password.data and form.username.data and check_password_hash(user.password,form.password.data):
return render_template('yourposts.html',
title = user.username,
user = user,
posts = user.posts.order_by("timestamp desc").paginate(page, POSTS_PER_PAGE, False),
)
else:
flash('Incorrect password')
return render_template('index.html',
loginform = form,
registerform = RegisterForm()
)
示例14: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate_on_submit [as 别名]
def login():
if g.user is not None and g.user.is_authenticated():
return redirect(url_for('intro'))
form = LoginForm()
error = None
if form.validate_on_submit():
session['remember_me'] = form.remember_me.data
email = form.email.data
password = form.password.data
user = User.query.filter_by(email=email).first()
if user is None:
flash('You are not registered. Please register first.')
elif not user.check_password(password):
flash('Incorrect password. Please check again.')
elif user.activated() == False:
service.send_activate(user)
return render_template('welcome.html')
else:
session['user_id'] = user.uid
remember_me = False
if 'remember_me' in session:
remember_me = session['remember_me']
session.pop('remember_me', None)
login_user(user, remember = remember_me)
form = PostForm()
return redirect(request.args.get('next') or url_for('intro'))
return render_template('login.html', title='Register', error=error, form=form)
示例15: index
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import validate_on_submit [as 别名]
def index():
if g.user is None:
login_form = LoginForm(prefix="login")
registration_form = RegistrationForm(prefix="register")
button = request.form.get('button')
if button == 'login' and login_form.validate_on_submit():
user = login_form.user
user.touch()
session['username'] = user.username
return redirect(request.args.get('next', url_for('index')))
elif button == 'register' and registration_form.validate_on_submit():
count = User.query.count()
user = User(
registration_form.username.data,
generate_password_hash(registration_form.password.data),
registration_form.email.data,
False,
True,
bool(count == 0),
)
db.session.add(user)
db.session.flush()
email.send_account_created_email(user)
db.session.commit()
session['username'] = user.username
flash('Registration successful! Please check your e-mail so we can verify your address.')
return redirect(url_for('index'))
else:
return render_template('index.html',
login_form=login_form,
registration_form=registration_form)
else:
identity_tokens = list(g.user.identity_tokens.filter_by(enabled=True))
return render_template('index.html', identity_tokens=identity_tokens)