1

会不会是错误的瓶子版本?

我查看了管理员提供的 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)

4

2 回答 2

1

每当您对源代码进行任何更改时,您都需要重新启动服务器以使这些更改生效。

于 2013-04-10T20:07:47.297 回答
0

Change the line

user = self.users.find({"_id":username,"password":password}) to

user = self.users.find_one({"_id":username})

于 2015-08-17T02:02:27.947 回答