def get_current_user(self):
cookies = dict((n, self.cookies[n].value) for n in self.cookies.keys())
cookie = facebook.get_user_from_cookie(
cookies, options.facebook_app_id, options.facebook_app_secret)
if not cookie:
return None
user = self.db.get(
"SELECT * FROM users WHERE id = %s", cookie["uid"])
if not user:
# TODO: Make this fetch async rather than blocking
graph = facebook.GraphAPI(cookie["access_token"])
profile = graph.get_object("me")
self.db.execute(
"REPLACE INTO users (id, name, profile_url, access_token) "
"VALUES (%s,%s,%s,%s)", profile["id"], profile["name"],
profile["link"], cookie["access_token"])
user = self.db.get(
"SELECT * FROM users WHERE id = %s", profile["id"])
elif user.access_token != cookie["access_token"]:
self.db.execute(
"UPDATE users SET access_token = %s WHERE id = %s",
cookie["access_token"], user.id)
return user
评论列表
文章目录