会不会是错误的瓶子版本?
我查看了管理员提供的 sessionDAO 文件,他们的做法和我一样;
编码:
def __init__(self, db):
self.db = db
self.users = self.db.users
self.SECRET = 'verysecret'
说:
[1] 连接到blog
数据库 [2] 选择users
集合
在登录代码中我有:
def validate_login(self, username, password):
user = None
try:
# XXX HW 2.3 Students Work Here
# you will need to retrieve right document from the users collection.
password = self.make_pw_hash(password)
user = self.users.find({"_id":username,"password":password})
我知道自己、用户名和密码;正如我写的那样,它应该是一个简单的文档查找;我现在看到可能存在缩进问题,我只能在 stackoverflow 上看到它,在 notepad++ 中它不存在;
和:
def add_user(self, username, password, email):
password_hash = self.make_pw_hash(password)
user = {'_id': username, 'password': password_hash}
if email != "":
user['email'] = email
try:
# XXX HW 2.3 Students work here
# You need to insert the user into the users collection.
# Don't over think this one, it's a straight forward insert.
self.users.insert(user)
我知道自己、用户名、密码和电子邮件;
该文档是默认准备的:user = {'_id': username, 'password': password_hash}
它应该是一个简单的插入:self.users.insert(user)