示例#1
0
class UserInfo(Base):
    _user_data = None

    def initialize(self):
        self._user_data = UserData()
        self._user_data.open_connection()

    def _get_from_service(self, _id):
        try:
            app_log.debug("UserInfo,get_from_service,_id=%s", _id)
            user_info = self._user_data.get(_id)
            data = {}
            if user_info is not None and "facebook_user_data" in user_info and "picture" in user_info[
                "facebook_user_data"] and "data" in user_info["facebook_user_data"]["picture"] and "url" in \
                    user_info["facebook_user_data"]["picture"]["data"]:

                data["profile_photo_url"] = user_info["facebook_user_data"][
                    "picture"]["data"]["url"]

                return data
            else:
                return None

        except:
            app_log.error("get_from_service,_id=%s", _id)
            return None
示例#2
0
文件: user_info.py 项目: rdefeo/api
class UserInfo(Base):
    _user_data = None

    def initialize(self):
        self._user_data = UserData()
        self._user_data.open_connection()

    def _get_from_service(self, _id):
        try:
            app_log.debug("UserInfo,get_from_service,_id=%s", _id)
            user_info = self._user_data.get(_id)
            data = {}
            if user_info is not None and "facebook_user_data" in user_info and "picture" in user_info[
                "facebook_user_data"] and "data" in user_info["facebook_user_data"]["picture"] and "url" in \
                    user_info["facebook_user_data"]["picture"]["data"]:

                data["profile_photo_url"] = user_info["facebook_user_data"]["picture"]["data"]["url"]

                return data
            else:
                return None

        except:
            app_log.error("get_from_service,_id=%s", _id)
            return None
示例#3
0
class Facebook(RequestHandler):
    _body_extractor = None
    _user_data = None

    def set_default_headers(self):
        if ADD_CORS_HEADERS:
            self.set_header("Access-Control-Allow-Origin", "*")
            self.set_header('Access-Control-Allow-Methods',
                            'GET, POST, OPTIONS')
            self.set_header('Access-Control-Allow-Headers',
                            'Origin, X-Requested-With, Content-Type, Accept')

    def initialize(self):
        self._body_extractor = BodyExtractor(self)
        self._user_data = UserData()
        self._user_data.open_connection()

    @asynchronous
    @engine
    def options(self, *args, **kwargs):
        self.finish()

    @asynchronous
    @engine
    def post(self, *args, **kwargs):
        access_token = self._body_extractor.access_token()
        graph = GraphAPI(access_token)
        facebook_user_id = self._body_extractor.user_id()
        user = self._user_data.upsert_facebook(
            facebook_user_id=facebook_user_id)
        self.set_status(201)
        self.set_header("Location", "/user/%s/" % (user["_id"]))
        self.set_header("_id", str(user["_id"]))
        self.finish(json_encode({"_id": str(user["_id"])}))

        if "facebook_user_data" not in user:
            facebook_user_data = graph.get(
                "me/?fields=id,name,picture,first_name,last_name,age_range,link,locale,timezone,verified,email"
            )
            self._user_data.upsert_facebook(
                _id=user["_id"],
                facebook_user_data=facebook_user_data,
                upsert=False)
示例#4
0
文件: root.py 项目: rdefeo/api
class Facebook(RequestHandler):
    _body_extractor = None
    _user_data = None

    def set_default_headers(self):
        if ADD_CORS_HEADERS:
            self.set_header("Access-Control-Allow-Origin", "*")
            self.set_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
            self.set_header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')

    def initialize(self):
        self._body_extractor = BodyExtractor(self)
        self._user_data = UserData()
        self._user_data.open_connection()

    @asynchronous
    @engine
    def options(self, *args, **kwargs):
        self.finish()

    @asynchronous
    @engine
    def post(self, *args, **kwargs):
        access_token = self._body_extractor.access_token()
        graph = GraphAPI(access_token)
        facebook_user_id = self._body_extractor.user_id()
        user = self._user_data.upsert_facebook(facebook_user_id=facebook_user_id)
        self.set_status(201)
        self.set_header("Location", "/user/%s/" % (user["_id"]))
        self.set_header("_id", str(user["_id"]))
        self.finish(
            json_encode(
                {
                    "_id": str(user["_id"])
                }
            )
        )

        if "facebook_user_data" not in user:
            facebook_user_data = graph.get("me/?fields=id,name,picture,first_name,last_name,age_range,link,locale,timezone,verified,email")
            self._user_data.upsert_facebook(_id=user["_id"],facebook_user_data=facebook_user_data, upsert=False)
示例#5
0
文件: user_info.py 项目: rdefeo/api
 def initialize(self):
     self._user_data = UserData()
     self._user_data.open_connection()
示例#6
0
 def initialize(self):
     self._user_data = UserData()
     self._user_data.open_connection()
示例#7
0
文件: root.py 项目: rdefeo/api
 def initialize(self):
     self._body_extractor = BodyExtractor(self)
     self._user_data = UserData()
     self._user_data.open_connection()
示例#8
0
 def initialize(self):
     self._body_extractor = BodyExtractor(self)
     self._user_data = UserData()
     self._user_data.open_connection()