コード例 #1
0
ファイル: views.py プロジェクト: ajamaica/InstantRetro
    def current_user(self):
        self.session = Session()
        if 'username' in self.session:
            userkey = self.session.get('username')
            user = User.get_by_key_name(userkey)
            user.put()
            return user

        if not hasattr(self, "_current_user"):
            self._current_user = None
            cookie = facebook.get_user_from_cookie(
                self.request.cookies, FACEBOOK_APP_ID, FACEBOOK_APP_SECRET)
            if cookie:
                # Store a local instance of the user data so we don't need
                # a round-trip to Facebook on every request
                user = User.get_by_key_name(cookie["uid"])
                if not user:
                    graph = facebook.GraphAPI(cookie["access_token"])
                    profile = graph.get_object("me")
                    user = User(key_name=str(profile["id"]),
                                id=str(profile["id"]),
                                name=profile["name"],
                                profile_url=profile["link"],
                                access_token=cookie["access_token"],
                                email=profile["email"],
                                source="facebook",
                                avatar= "http://graph.facebook.com/"+str(profile["id"]) +"/picture"
                                )

                    user.put()
                elif user.access_token != cookie["access_token"]:
                    graph = facebook.GraphAPI(cookie["access_token"])
                    profile = graph.get_object("me")

                    user.access_token = cookie["access_token"]
                    user.avatar = "http://graph.facebook.com/"+str(user.id) +"/picture"
                    #user.email=profile["email"]
                    user.put()
                self._current_user = user
        return self._current_user
コード例 #2
0
ファイル: views.py プロジェクト: ajamaica/InstantRetro
    def post(self):
        foto = Foto()
        imgdata = base64.b64decode(self.request.get("imageData").replace('data:image/png;base64,', ''))
        img = Image(image_data=imgdata)

        foto.hint = 0

        import random

        name = 'blob_' + str(random.randrange(0, 100000))
        if(BLOBAPI):
            img = images.resize(imgdata, width=600, output_encoding=images.PNG)
            file_name = files.blobstore.create(mime_type='image/jpg', _blobinfo_uploaded_filename=name)
            with files.open(file_name, 'a') as f:
                f.write(str(img))
                # Finalize the file. Do this before attempting to read it.
            files.finalize(file_name)

            # Get the file's blob key
            blob_key = files.blobstore.get_blob_key(file_name)

            foto.imageblob = blob_key



        else:
            foto.image = images.resize(imgdata, width=500, output_encoding=images.PNG)

        foto.title = self.request.get('title')
        if not self.request.get('privacy'):
            foto.shared = False

        if self.current_user:
            try:
                foto.owner = self.current_user.key()
                cookie = facebook.get_user_from_cookie(
                    self.request.cookies, FACEBOOK_APP_ID, FACEBOOK_APP_SECRET)
                graph = facebook.GraphAPI(cookie["access_token"])
            except:
                pass
        published = conn.create_container('saved_pictures')
        published.make_public(2592000)
        try:
            name = str(time()) + '_saved_' + str(random.randrange(0, 100000))
            test_object = published.create_object(name)
            test_object.content_type = 'image/png'
            test_object.write(foto.image, verify=False)
            foto.published = test_object.public_uri()
        except:
            pass
        foto.put()

        if self.request.get('privacy'):
            mail.send_mail(sender="*****@*****.**",
                           to="*****@*****.**",
                           subject="New Photo : [ %s ] " % CompressURL(
                               ('http://www.instantretro.com/view/' + str(foto.key()))),
                           body="New Photo",
                           attachments=[('Uploaded.jpg', (foto.image))])

            mail.send_mail(sender="*****@*****.**",
                           to="*****@*****.**",
                           subject="New Photo : %s" % CompressURL(
                               ('http://www.instantretro.com/view/' + str(foto.key()))),
                           body="New Photo",
                           attachments=[('Uploaded.jpg', (foto.image))])

        self.response.out.write('{"key" : "' + str(foto.key()) + '" }')