def user_pwd(): form = PwdForm() if form.validate_on_submit(): old_pwd = form.old_pwd.data new_pwd = form.data["new_pwd"] user = query_user_by_name(session.get("user_name")) if str(old_pwd) == str(user.pwd): user.pwd = new_pwd update_user_by_name(user.name, user) session.pop("user_name", None) flash(message="修改密码成功,请重新登录!", category='ok') return redirect(url_for("user_login", username=user.name)) else: flash(message="旧密码输入错误!", category='err') return render_template("user_pwd.html", form=form) return render_template("user_pwd.html", form=form)
def user_pwd(): # 修改个人密码 form = PwdForm() if form.validate_on_submit(): old_pwd = request.form["old_pwd"] new_pwd = request.form["new_pwd"] user = query_user_by_name(session.get("user_name")) if str(old_pwd) == str(user.pwd): user.pwd = new_pwd update_user_by_name(user.name, user) session.pop("user_name", None) # 修改密码后需要重新登录,然后清除session中的数据 flash(message="密码修改成功!请重新登录!", category="ok") return redirect(url_for("user_login", username=user.name)) else: flash(message="旧密码输入错误!", category="err") return render_template("user_pwd.html", form=form) return render_template("user_pwd.html", form=form)
def user_pwd(): form = PwdForm() if form.validate_on_submit(): old_pwd = form.old_pwd.data new_pwd = form.data["new_pwd"] user = User.query.get_or_404(int(session.get("user_id"))) if user.check_pwd(old_pwd): user.pwd = generate_password_hash(new_pwd) db.session.add(user) db.session.commit() session.pop("user_name", None) session.pop('user_id', None) flash(message="修改密码成功,请重新登录!", category='ok') return redirect(url_for("user_login", username=user.name)) else: flash(message="旧密码输入错误!", category='err') return render_template("user_pwd.html", form=form) return render_template("user_pwd.html", form=form)
def user_pwd(): form = PwdForm() if form.validate_on_submit(): old_pwd = form.data['old_pwd'] new_pwd = form.data['new_pwd'] user = Database(g.db).sql_select(session.get('user_name')) if str(old_pwd) == user[-1]: db = Database(g.db) db.sql_update(user[1], new_pwd) session.pop('user_name', None) flash('修改密码成功') return redirect(url_for('user_login')) else: flash('旧密码输入错误') return render_template('user_pwd2.html', form=form) return render_template('user_pwd2.html', form=form)
def user_pwd(): # 修改个人密码 form = PwdForm() if form.validate_on_submit(): old_pwd = request.form["old_pwd"] new_pwd = request.form["new_pwd"] user = User.query.get_or_404(int( session.get('user_id'))) # 如果查找不到就抛出404错误 if user.check_pwd(old_pwd): user.pwd = generate_password_hash(new_pwd) # 更新原数据 db.session.add(user) # 当插入数据时,检测到插入的数据主键(id) 已存在 则更新原数据 db.session.commit() session.pop("user_name", None) # 修改密码后需要重新登录,然后清除session中的数据 session.pop("user_id", None) flash(message="密码修改成功!请重新登录!", category="ok") return redirect(url_for("user_login", username=user.name)) else: flash(message="旧密码输入错误!", category="err") return render_template("user_pwd.html", form=form) return render_template("user_pwd.html", form=form)