本文整理汇总了Python中forms.ChangePasswordForm.validate_on_submit方法的典型用法代码示例。如果您正苦于以下问题:Python ChangePasswordForm.validate_on_submit方法的具体用法?Python ChangePasswordForm.validate_on_submit怎么用?Python ChangePasswordForm.validate_on_submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.ChangePasswordForm
的用法示例。
在下文中一共展示了ChangePasswordForm.validate_on_submit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: change_password
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import validate_on_submit [as 别名]
def change_password():
user = None
if current_user.is_authenticated:
if not login_fresh():
return login_manager.needs_refresh()
user = current_user
elif 'activation_key' in request.values and 'email' in request.values:
activation_key = request.values['activation_key']
email = request.values['email']
user = User.query.filter_by(activation_key=activation_key) \
.filter_by(email=email).first()
if user is None:
abort(403)
form = ChangePasswordForm(activation_key=user.activation_key)
if form.validate_on_submit():
user.password = form.password.data
user.activation_key = None
db.session.add(user)
db.session.commit()
flash("Your password has been changed, please log in again", "success")
return redirect(url_for("frontend.login"))
return render_template("frontend/change_password.html", form=form)
示例2: account_settings
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import validate_on_submit [as 别名]
def account_settings():
form = AccountForm()
formpass = ChangePasswordForm()
error = ''
sel_tab = 1
user = UserAccount.query.filter(UserAccount.id==g.user.id).one()
if form.validate_on_submit():
user.username = form.username.data
user.email = form.email.data
db.session.add(user)
db.session.commit()
flash ('Changes saved.')
form.username.data = user.username
form.email.data = user.email
if request.method == 'POST' and formpass.submit_pass:
sel_tab = 2
if formpass.validate_on_submit():
password = md5.md5(formpass.password.data).hexdigest()
user1 = UserAccount.query.filter(and_(UserAccount.id==g.user.id, UserAccount.password==password)).first()
if not user1:
error = 'Invalid password.'
else:
newpassword = md5.md5(formpass.newpassword.data).hexdigest()
user1.password = newpassword
db.session.add(user1)
db.session.commit()
flash ('New password saved.')
return render_template('account.html', form=form, formpass=formpass, site_data=site_data(), navigation=return_navigation(), error=error, sel_tab=sel_tab)
示例3: change_password
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import validate_on_submit [as 别名]
def change_password():
form = ChangePasswordForm()
if form.validate_on_submit():
current_user.password = form.new_password.data
db.session.add(current_user)
db.session.commit()
flash('your password change successful.')
return redirect(url_for('main.index'))
return render_template('auth/change_password.html', form=form)
示例4: index
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import validate_on_submit [as 别名]
def index():
form = ChangePasswordForm()
if form.validate_on_submit():
user = models.User.query.filter_by(name="Admin").first()
if user.check_password(form.current_password.data):
user.set_password(form.new_password.data)
db.session.commit()
else:
flash('Verify your password', 'error')
return render_template('index.html', form=form)
示例5: change_password
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import validate_on_submit [as 别名]
def change_password():
form = ChangePasswordForm()
if form.validate_on_submit():
current_user.password = form.password.data
db.session.add(current_user)
db.session.commit()
send_mail(current_user.email, 'Password was change', 'mail/change_password_mail', user = current_user)
flash('Email about changing password has been sent to you by email.')
return redirect(url_for('login'))
return render_template('change_password.html', form = form)
示例6: change_password
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import validate_on_submit [as 别名]
def change_password():
changePass = ChangePasswordForm()
if changePass.validate_on_submit():
if login_db.verify(session["username"], changePass.oldPassword.data):
login_db.update(session["username"], changePass.newPassword.data)
flash("pass-updated")
else:
flash("bad-old")
return render_template("change_pass.html", subheading="Account Settings", message=None, changePass=changePass,
page="settings")
示例7: change_password
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import validate_on_submit [as 别名]
def change_password():
form = ChangePasswordForm()
if form.validate_on_submit():
if current_user.verify_password(form.old_password.data):
current_user.password = form.password.data
db.session.add(current_user)
flash('You password have been update','success')
return redirect(url_for('main.index'))
else:
flash('Invalid password')
return render_template('auth/change_password.html',form = form)
示例8: change_password
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import validate_on_submit [as 别名]
def change_password():
form = ChangePasswordForm()
if form.validate_on_submit():
if check_password_hash(current_user.password, form.old_password.data):
current_user.update_password(form.new_password.data)
db.session.commit()
message = "Your password has been changed."
return render_template("message.html", active_page='none', message=message)
else:
form.old_password.errors = ["Old password incorrect."]
return render_template('change_password.html', active_page='none', form=form)
示例9: change_password
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import validate_on_submit [as 别名]
def change_password():
form = ChangePasswordForm()
if form.validate_on_submit():
if current_user.check_password(form.old_password.data):
current_user.password = form.password.data
current_user.save()
flash('Your password has been updated.')
return redirect(url_for('main.index'))
else:
flash('Invalid password.')
return render_template("auth/change_password.html", form=form)
示例10: profile
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import validate_on_submit [as 别名]
def profile():
form = ChangePasswordForm()
if form.validate_on_submit():
g.user.set_password(form.new_password.data)
db.session.add(g.user)
db.session.commit()
flash('password has been changed')
return redirect(url_for('index'))
return render_template('profile.html',
title='Profile',
form=form)
示例11: changepassword
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import validate_on_submit [as 别名]
def changepassword():
form= ChangePasswordForm()
if form.validate_on_submit():
user = User.query.filter_by(user_name = form.username.data).first()
user.password=form.password.data
db.session.merge(user)
db.session.commit()
return redirect(url_for('home'))
return render_template('changepassword.html', form=form)
示例12: change_password
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import validate_on_submit [as 别名]
def change_password():
form = ChangePasswordForm()
if form.validate_on_submit():
if current_user.check_password(form.current_password.data):
current_user.password = form.new_password.data
db.session.add(current_user)
db.session.commit()
flash(u'新密码已设置。', 'success')
return redirect(url_for('.index'))
else:
flash(u'原密码有误,请重新输入。', 'warning')
return render_template('settings/change-password.html', form=form)
示例13: change_password
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import validate_on_submit [as 别名]
def change_password():
"""Changing password """
form = ChangePasswordForm()
if form.validate_on_submit():
if form.password.data != form.retype_password.data:
flash('Passwords are not same')
else:
user = current_user
user.password = bcrypt.generate_password_hash(form.password.data)
db.session.add(user)
db.session.commit()
return redirect(url_for("logout"))
return render_template("change_password.html", form=form)
示例14: accessrights
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import validate_on_submit [as 别名]
def accessrights():
form = ChangePasswordForm(request.form)
if form.validate_on_submit():
user = User.query.filter_by(email=g.user.email).first()
if user:
user.password = bcrypt.generate_password_hash(form.password.data)
db.session.commit()
flash('Password successfully changed.', 'success')
return redirect(url_for('edit'))
else:
flash('Password change was unsuccessful.', 'danger')
return redirect(url_for('edit'))
return redirect(url_for('edit'))
示例15: changepassword
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import validate_on_submit [as 别名]
def changepassword():
form = ChangePasswordForm()
title="Change Password"
user = User.query.get_or_404(g.user.id)
if form.validate_on_submit():
if check_password_hash(g.user.password, form.oldpassword.data):
g.user.password = generate_password_hash(form.password.data)
db.session.add(g.user)
db.session.commit()
flash('Your password was successfully changed!', category='success')
return redirect(url_for('changepassword'))
else:
flash("Your old password is incorrect!", category='danger')
return redirect(url_for('changepassword'))
return render_template('changepassword.html',title=title,form=form,user=user)