def authenticate(self, username, password): userInfo = User.query.filter_by(username=username).first() if userInfo is None: return jsonify(common.falseReturn('', '找不到用户')) else: if (User.check_password(userInfo.password, password)): login_time = int(time.time()) userInfo.login_time = login_time userInfo.update() token = self.encode_auth_token(userInfo.id, login_time) return jsonify(common.trueReturn(token.decode(), '登录成功')) else: return jsonify(common.falseReturn('', '密码不正确'))
def test_check_password(client): """ Test password validation """ user = User(email='*****@*****.**', password='******') user.save() assert user.check_password('foobarbaz123')