0

I am trying to setup an email confirmation where a link (below) is sent the email address of a recipient. They click on the link to get to a process that will take the 'post_id' and compare it to the key from the User record associated with the parameter 'i'.

If they are equal the connection url is valid. I just can't get the test to work.

link = http://letshudder.appspot.com/email/confirmation/5662278724616192?i=MichaelClay

Code

    def get(self, post_id):
        logging.debug("In email confirmation for userid %s" % post_id)

        linkid = self.request.GET.get("i")
        uid = User.by_id_name(linkid)
        logging.debug("The uid of the inviter is %s" % uid)
        logging.debug("with a length of %s" % len(str(uid)))
        logging.debug("This should match the id value from the link: %s" % post_id)
        logging.debug("with a length of %s" % len(str(post_id)))

        if uid >= post_id:
            logging.debug("UID wins")

        if post_id >= uid:
            logging.debug("post_id wins")

        if uid != post_id:
            logging.debug("UID and LINKID did not match")
            self.redirect('/invalid_url')
            return

. . .

Debug output:

D 2013-08-29 19:18:28.871 In email confirmation for userid 5662278724616192

I 2013-08-29 19:18:28.887 the userid is: MichaelClay

D 2013-08-29 19:18:28.887 The uid of the inviter is 5662278724616192

D 2013-08-29 19:18:28.887 with a length of 16

D 2013-08-29 19:18:28.887 This should match the id value from the link: 5662278724616192

D 2013-08-29 19:18:28.887 with a length of 16

D 2013-08-29 19:18:28.887 post_id wins

I am running Python 2.7 on Google Apps Engine. Any ideas?

4

1 回答 1

0

您的问题将uid = User.by_id_name(linkid) 不是 Userid 而是 User 对象的结果。它的str方法意味着当你记录东西时它看起来像一个 uid 但它不是这意味着比较将失败。

你应该比较str(uid) == linkid 你的代码才能工作。

为了证明这一点,请尝试记录 repr(uid) 而不是 str(uid)

于 2013-08-30T08:47:53.513 回答