Exemple #1
0
 def get(self, device_secret_id):
     access_token = self.request.get("access_token")
     session = social.fetch_temporary_data(access_token)
     log.info("search for session id: "+ access_token)
     user = social.get_user(session)
     if user is None:
         self.response.set_status(403, "forbidden")
         return
     auths = user.authmethod_set
     d = [auth.to_dict() for auth in auths]
     serialization.plist_dump(self.response, d)
Exemple #2
0
    def post(self, device_secret_id):
        if not self.validate_request("type device_name device_model device_version app_name app_version".split()):
            return None
        connection_type = self.request.get('type')
        auth = None
        if connection_type == "facebook":
            auth = social.connect_facebook(self.request.get("service_access_token"), source="device")
        elif connection_type == "google":
            auth = social.connect_custom_oauth(self.request.get("service_access_token"), source="device")
        else:
            self.response.out.write("<!-- unknown type = "+connection_type+" -->")
            self.response.set_status(400, "bad request")
            return

        if auth is not None:
            access_token = social.login(auth)
            device = self.add_or_update_device(auth.user_profile, device_secret_id)
            response = self.response_after_connect(device, access_token)
            serialization.plist_dump(self.response, response)
        else:
            self.response.out.write("<!-- secure_access_token is unusable -->")
            self.response.set_status(403, "forbidden")
Exemple #3
0
    def output_device(self, device, since):
        urls = model.Url.all().filter("email =", device.email)
        if since:
            urls = urls.filter("created >", since)
        urls = urls.order("-created")
        urls = urls.fetch(100)
        urls_list = [url.to_ios_dict() for url in urls if not url.is_deleted]

        deleted_urls = (model.Url.all().filter("email =", device.email)
                                       .filter("is_deleted =", True))
        if since:
            deleted_urls = deleted_urls.filter("updated >", since)
        urls_list += [url.to_ios_dict() for url in deleted_urls.fetch(100)]

        self.add_auto_open_header(urls)
        d = {
             "id": device.key().id(),
             "created": device.created.isoformat(),
             "updated": device.updated.isoformat(),
             "name": device.name,
             "default": device.default,
             "urls": urls_list,
        }
        serialization.plist_dump(self.response, d)