开发者

AppEngine DB get user by email address

开发者 https://www.devze.com 2023-02-14 14:44 出处:网络
I\'ve got a simple appengine app which holds some data in the datastore where one field is a UserProperty as created from the logged in user.

I've got a simple appengine app which holds some data in the datastore where one field is a UserProperty as created from the logged in user.

I need to be able to get that data back when the user sends an XMPP message, I have their email address from the XMPP sender but when I try to query the datastore for the object I get no results returned. Code is below:

class Users(db.Model):
user = db.Use开发者_JS百科rProperty()
accesstoken = db.StringProperty()
refreshtoken = db.StringProperty()
expires = db.IntegerProperty()
created = db.DateTimeProperty(auto_now_add=True)



class XmppHandler(webapp.RequestHandler):
def post(self):
    message = xmpp.Message(self.request.POST)
    rcpt = self.request.get('to').split("@")[0]
    orig = self.request.get('from').split("/")[0]
    text = self.request.get('body')
    query = Users.all()
    query.filter("user =", orig)
    r = query.get()
    authheader = "OAuth " + r.accesstoken


Solved it, to create the user object I used

 u = users.User(email=orig)

then I can filter by that user object:

class XmppHandler(webapp.RequestHandler):
    def post(self):
        message = xmpp.Message(self.request.POST)
        rcpt = self.request.get('to').split("@")[0]
        orig = self.request.get('from').split("/")[0]
        text = self.request.get('body')
        u = users.User(email=orig)
        query = Users.all()
        query.filter("user =", u)
        r = query.get()
        authheader = "OAuth " + r.accesstoken
0

精彩评论

暂无评论...
验证码 换一张
取 消