1

could it be the wrong bottle version?

I lookeed in the sessionDAO file provided by the admins, and they do it the same as i do it;

the code:

def __init__(self, db):
        self.db = db
        self.users = self.db.users
        self.SECRET = 'verysecret'

says:

[1] connect to the blog db [2] select the users collection

and in the login code i have:

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})

I know self, username and password; it should be a simple find by document, as i wrote it; I now see that there might be a indentation problem, wich i can see it only on stackoverflow, in notepad++ it's not there;

and:

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)

I know self, username, password and email;

The document is prepared by default: user = {'_id': username, 'password': password_hash}

It should be a simple insert: self.users.insert(user)

14
  • Are you getting any errors? Commented Apr 10, 2013 at 19:34
  • no, none; this is strange Commented Apr 10, 2013 at 19:35
  • If you run the mongo shell and execute show dbs; then use blog; then show collections; then db.users.find();, does anything look goofy in that series of commands? Commented Apr 10, 2013 at 19:38
  • Where are you connecting to the blog db in your code? Commented Apr 10, 2013 at 19:39
  • strange, but, when i run them, everything is ok; they all exist Commented Apr 10, 2013 at 19:41

2 Answers 2

1

Whenever you make any change to the source code, you need to restart the server for those changes to take effect.

Sign up to request clarification or add additional context in comments.

1 Comment

NEVER EVER FOGET THIS. i knew that my initial code was perfect :)
0

Change the line

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.