修改密码中旧密码不能成功验证
来源:7-14 .修改密码-
Jarrott
2017-08-10
老师,在修改密码部分,旧密码提交后,并不能验证,是怎么回事?
写回答
3回答
-
同学,你好,注意一下旧密码命名是old_pwd不是pwd,表单的代码如下:
class PwdForm(FlaskForm): old_pwd = PasswordField( label="旧密码", validators=[ DataRequired("请输入旧密码!") ], description="旧密码", render_kw={ "class": "form-control", "placeholder": "请输入旧密码!", } ) new_pwd = PasswordField( label="新密码", validators=[ DataRequired("请输入新密码!") ], description="新密码", render_kw={ "class": "form-control", "placeholder": "请输入新密码!", } ) submit = SubmitField( '编辑', render_kw={ "class": "btn btn-primary", } ) def validate_old_pwd(self, field): from flask import session pwd = field.data name = session["admin"] admin = Admin.query.filter_by( name=name ).first() if not admin.check_pwd(pwd): raise ValidationError("旧密码错误!")
html代码如下:
<form role="form" method="post"> <div class="box-body"> <div class="form-group"> <label for="input_pwd">{{ form.old_pwd.label }}</label> {{ form.old_pwd }} {% for err in form.old_pwd.errors %} <div class="col-md-12"> <font style="color:red">{{ err }}</font> </div> {% endfor %} </div> <div class="form-group"> <label for="input_newpwd">{{ form.new_pwd.label }}</label> {{ form.new_pwd }} {% for err in form.new_pwd.errors %} <div class="col-md-12"> <font style="color:red">{{ err }}</font> </div> {% endfor %} </div> </div> <div class="box-footer"> {{ form.csrf_token }} {{ form.submit }} </div> </form>
022017-08-10 -
Jarrott
提问者
2017-08-10
@admin.route('/pwd/', methods=["GET", "POST"]) @admin_login_req def pwd(): form = PwdForm() if form.validate_on_submit(): form = form.data return render_template("admin/pwd.html", form=form)
{% extends "admin/home.html" %} {% block content %} <!--内容--> <section class="content-header"> <h1>微电影管理系统</h1> <ol class="breadcrumb"> <li><a href="#"><i class="fa fa-dashboard"></i> 个人资料</a></li> <li class="active">修改密码</li> </ol> </section> <section class="content" id="showcontent"> <div class="row"> <div class="col-md-12"> <div class="box box-primary"> <div class="box-header with-border"> <h3 class="box-title">修改密码</h3> </div> <form role="form" method="post"> <div class="box-body"> <div class="form-group"> <label for="input_pwd">{{ form.pwd.label }}</label> {{ form.pwd }} {% for err in form.pwd.errors %} <div class="col-md-12" style="color: red">{{ err }}</div> {% endfor %} </div> <div class="form-group"> <label for="input_newpwd">{{ form.new_pwd.label }}</label> {{ form.new_pwd }} {% for err in form.new_pwd.errors %} <div class="col-md-12" style="color: red">{{ err }}</div> {% endfor %} </div> </div> <div class="box-footer"> {{ form.csrf_token }} {{ form.submit }} </div> </form> </div> </div> </div> </section> <!--内容--> {% endblock %}
00 -
rustgopy
2017-08-10
同学,你好,你检测old_pwd是否提交到服务器端,你截取一下修改密码的视图代码以及html代码给我!
012017-08-10
相似问题