请原谅我的无知!
我使用MongoEngine遵循了烧瓶安全性教程,当我尝试使用注册的用户帐户登录时,在下面始终出现以下错误。
NameError:全局名称'verify_and_update_password'未定义
我已经浏览了Flask-Security utils文件,无法弄清楚我在做什么错。我的代码如下:
import datetime
from flask import Flask, url_for, render_template, request, redirect, session, flash
from flask_mongoengine import MongoEngine
from mongoengine.document import Document
from mongoengine.fields import *
import bcrypt
import flask_security
from flask_security import Security, MongoEngineUserDatastore, UserMixin, RoleMixin, login_required, ConfirmRegisterForm
from flask_login import LoginManager, UserMixin, current_user, login_user, logout_user
# Create app
app = Flask(__name__)
# MongoDB Configuration
app.config['MONGODB_DB'] = 'testdb'
app.config['MONGODB_HOST'] = 'localhost'
app.config['MONGODB_PORT'] = 27017
app.config['SECURITY_PASSWORD_SALT'] = 'bcrypt'
app.config['SECURITY_CONFIRMABLE'] = True
app.config['SECURITY_REGISTERABLE'] = True
app.config['SECURITY_RECOVERABLE'] = True
app.config['SECURITY_TRACKABLE'] = True
app.config['SECURITY_CHANGEABLE'] = True
app.config['SECURITY_SEND_REGISTER_EMAIL'] = True
# Flask Mail Configuration
app.config['MAIL_SERVER'] = 'my.secureserver.net'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USE_SSL'] = True
app.config['MAIL_USERNAME'] = 'noreply@mymail.com'
app.config['MAIL_PASSWORD'] = '3nj8$5jd#9n834'
db = MongoEngine(app)
mail = Mail(app)
login = LoginManager(app)
class Role(db.Document, RoleMixin):
name = db.StringField(max_length=80, unique=True)
class User(db.Document, UserMixin):
email = db.EmailField(max_length=255, unique=True)
password = db.StringField(max_length=255)
active = db.BooleanField(default=True)
joined_at = db.DateTimeField(default=datetime.datetime.now)
confirmed_at = db.DateTimeField()
roles = db.ListField(db.StringField(), default=['admin'])
# Setup Flask-Security
user_datastore = MongoEngineUserDatastore(db, User, Role)
security = Security(app, user_datastore)
if __name__ == '__main__':
app.run(host='0.0.0.0')