【发布时间】:2015-12-19 15:50:51
【问题描述】:
我有一个 5 个月前开始的烧瓶项目,并在注册和身份验证后停止。我现在想继续,在全新安装后,我现在收到标题为登录/身份验证的错误。下面
账户表格
class LoginForm(Form):
email = StringField('Enter email', validators=[DataRequired(),Email()])
password = PasswordField('Password', validators=[DataRequired()])
remember = BooleanField('Remember Password')
在路由文件中
@app.route('/',methods=['GET', 'POST'])
@app.route('/index', methods=['GET', 'POST'])
def index():
formLogin = AccountForm.LoginForm()
if request.method == 'GET' :
return render_template('index.html',formLogin=formLogin)
if request.method == 'POST' :
if request.form.get('login', None) == 'Login' :
return AccountController.authenticatePopUpLogin(formLogin,'index')
在我的帐户控制器中
def authenticatePopUpLogin(formLogin,route):
if formLogin.validate_on_submit():
try:
user = session.query(User).filter(User.email == formLogin.email.data).first()
except :# models.DoesNotExist:
flash("Your email or password does not match !", "error")
return render_template('login.html',form=formLogin,formLogin = formLogin)
else :
if check_password_hash(user.password,formLogin.password.data):
我的用户是从我的模型类中导入的
class User(UserMixin , Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
title = Column(CHAR(3), nullable = False)
firstname = Column(String(100), nullable = False)
lastname = Column(String(100), nullable = False)
DateOfBirth = Column(ArrowType, default = arrow.utcnow())
username = Column(String(100), nullable = False, unique = True)
email = Column (String(50), nullable =False, unique = True)
password = Column(String(100), nullable = False)
...
然后它会抛出上面的错误。我怀疑错误发生在这里check_password_hash(user.password,formLogin.password.data):。但是,我的表单验证有效,当它为空时会引发错误等。
我确认密码字段也存在于我的数据库中。请问我哪里出错了?
【问题讨论】:
-
我这一行
if check_password_hash(user.password,formLogin.password.data):,user是小写,而之前是大写。 -
嗨,
User中的session.query(User).filter(User.email == formLogin.email.data).first()来自我的用户类。但是,user来自变量user(即user = session.query(User).filter(User.email == formLogin.email.data).first()。我认为它们都是小写的先生。