def change_password(): form = ChangePasswordForm(request.form) if request.method == 'POST' and form.validate(): current_user.password = form.new_password1.data db.session.commit() flash('密码已更新成功') return redirect(url_for('web.personal')) return render_template('auth/change_password.html', form=form)
def change_password(): '''处理修改密码页面。''' form = ChangePasswordForm(request.form) if request.method == 'POST' and form.validate(): with db.auto_commit(): current_user.password = form.new_password1.data flash('密码已更新成功') return redirect(url_for('web.personal_center')) return render_template('auth/change_password.html', form=form)
def change_password(): wtform = ChangePasswordForm(request.form) if request.method == 'POST' and wtform.validate(): user = User.query.get_or_404(current_user.id) if user.check_password(wtform.old_password.data): user.change_password(wtform.new_password1.data) return redirect(url_for('web.login')) return render_template('auth/change_password.html')
def change_password(): form = ChangePasswordForm(request.form) if request.method == 'POST' and form.validate(): if current_user.check_password(form.old_password.data): current_user.change_password(form.password1.data) flash('您的密码已重置,请使用新密码登录') return redirect(url_for('web.login')) flash('密码更改失败') return render_template('auth/change_password.html')
def change_password(): form = ChangePasswordForm(request.form) if request.method == 'POST' and form.validate(): if current_user.check_password(form.old_password.data): with db.auto_commit(): current_user.password = form.new_password1.data return redirect(url_for('web.login')) else: flash('您的原密码输入错误,请重新输入') return render_template('auth/change_password.html', form=form)
def change_password(): # 只能由root用户修改密码 form = ChangePasswordForm(request) if request.method == 'POST' and form.validate() and current_user.username == 'root': with db.auto_commit(): user = User.query.filter_by(username=form.username.data).first() user.password = form.new_password1.data flash('密码已更新成功,请联系管理员重新激活账户') return redirect(url_for('web.login')) return render_template('auth/change_password.html', form=form)
def change_password(): form = ChangePasswordForm(request.form) if request.method == 'POST' and form.validate(): if current_user.check_password(form.old_password.data): with db.auto_commit(): current_user.password = form.new_password1.data flash('密码修改成功') return redirect(url_for('web.personal_center')) else: flash('原密码有误') return render_template('auth/change_password.html', form=form)
def change_password(): form = ChangePasswordForm(request.form) if request.method == 'POST' and form.validate(): current_user.password = form.new_password1.data db.session.commit() # 查看 flash 和 get_flashed_messages 你就会发现, # 其实 flask message flashing 功能是基于一个名字叫做 session 的 cookie 实现的 # 无状态 HTTP 请求如何解决 上次请求和本次请求的关联: # 就是把上次请求产生的结果回传到用户 cookie 中, # 然后下次用户请求是带上这个 cookie,从而实现两个请求的关联 flash('密码已更新成功') return redirect(url_for('web.personal_center')) return render_template('auth/change_password.html', form=form)
def change_password(): form = ChangePasswordForm(request.form) if request.method == "POST" and form.validate(): user = User.query.get(current_user.id) isSuccess = False if user and user.check_password(form.data["oldPassword"]): isSuccess = user.change_password(form.data["password1"]) if isSuccess: flash("密码已经更新,请使用新密码登录") logout_user() return redirect(url_for("web.login")) else: flash("重置密码失败,请重新尝试") return render_template("auth/change_password.html", form=form)
def change_password(): form = ChangePasswordForm(request.form) if form.old_password.data == form.new_password1.data: flash('新密码与旧密码一致, 请确认后重新输入') else: if request.method == 'POST' and form.validate(): success = current_user.check_password(form.old_password.data) if success: with db.auto_commit(): current_user.password = form.new_password1.data flash('你的密码已修改, 请使用新密码登录') return redirect(url_for('web.login')) else: flash('原密码输入有误') return render_template('auth/change_password.html', form=form)
def change_password(): form = ChangePasswordForm(request.form) if request.method == 'POST': if form.validate(): user = User.query.filter_by(id=current_user.id).first_or_404() # old_password = form.old_password.data success = user.check_password(form.old_password.data) if success: with db.auto_commit(): user.password = form.new_password1.data db.session.add(user) flash('你的密码已修改, 请使用新密码登录') return redirect(url_for('web.login')) else: flash('密码修改失败, 原密码输入有误') return render_template('auth/change_password.html')
def change_password(): '''auth.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) db.session.commit() flash('修改密码成功', category='success') add_user_log(user=current_user._get_current_object(), event='修改密码', category='auth') return redirect(current_user.index_url) flash('密码有误', category='error') return redirect(url_for('auth.change_password')) return minify(render_template( 'auth/change_password.html', form=form ))
def change_password(id): form = ChangePasswordForm() user = User.query.filter_by(id = id).first_or_404() print("form=",form) if form.validate_on_submit() and request.method == "POST": #若勾选更改密码,则修改密码后退出到登录界面 if form.changepwd.data == True: if current_user.validate_password(form.oldpassword.data): current_user.set_password(form.password.data) user.email = form.email.data db.session.commit() return redirect(url_for('auth.logout')) else: flash(u"旧密码错误!") else: #不勾选更改密码,当前输入邮箱与从数据库查询的密码不一致时,修改邮箱 if user.email != form.email.data: user.email = form.email.data db.session.commit() return redirect(url_for('main.index')) form.name.data = user.name form.username.data = user.username form.email.data= user.email return render_template('auth/change_password.html',form=form)
from flask import render_template, request, redirect, url_for, flash, current_app