Пример #1
0
 def GET(self, key):
     web.debug(str(dir(web)))
     try:
         if web.input().login:
             return web.seeother(users.create_login_url("/welcome?profile=%s" % key))
     except:
         pass
     profile = Profile.get(key)
     nonce = uuid.uuid4().hex
     goog = users.get_current_user()
     if profile:
         return render.profile(profile, nonce, goog)
     else:
         return web.seeother('/')
Пример #2
0
    def POST(self, key):
        goog = users.get_current_user()
        if not goog:
            return web.seeother('/')

        profile = Profile.get(key)
        if not profile:
            web.debug("no such profile")
            return web.seeother('/')
        challenge = web.input().challenge
        response = web.input().response
        secret = profile.secret
        expected_response = md5.new(challenge + secret).hexdigest()
        web.debug("response = " + response + ", expected = " + expected_response)
        user = db.GqlQuery("SELECT * FROM User WHERE goog = :1", goog).get()
        if (expected_response == response) and user:
            web.debug("own the profile")
            profile.user = user
            profile.put()
            return web.seeother("/users/%s" % user.name)
        else:
            web.debug("unauthorized")
            web.ctx.status = "401 unauthorized"
            return web.seeother('/')
Пример #3
0
    def POST(self, key=None):
        web.debug("hi: %s" % key)
        send_welcome = False
        json = simplejson.loads(web.input().data)

        if key and key != '':
            profile = Profile.get(key)

            if profile:
                sig = web.input().sig
                data = web.data()
                expected = md5.new(data + profile.secret).hexdigest()
                if sig != expected:
                    web.ctx.status = "401 Unauthorized"
                    return "Invalid Signature"
            else:
                send_welcome = 410

        else:
            send_welcome = 200

        if send_welcome:
            secret_uuid = uuid.uuid4()
            profile = Profile(secret=secret_uuid.hex)

        profile.version = json['system']['version']
        profile.os = json['system']['OS']
        profile.platform = json['system']['name']
        profile.put()

        web.debug("profile: %s" % profile)

        # Build a dictionary of the current extensions
        profile_extensions = profile.profileextension_set.fetch(100)

        px_dict = {}
        for e in profile_extensions:
            px_dict[e.extension.mid] = e
        web.debug(px_dict)

        local_extensions = json['extensions']
        for mid in local_extensions:
            local_extension = local_extensions[mid]
            web.debug("processing " + mid)
            key = db.Key.from_path('Extension', mid)
            extension = Extension.get(key)
            if not extension:
                web.debug("new extension: " + mid)
                extension = Extension(key_name=mid)
                extension.mid = mid
                extension.name = local_extension['name']
                extension.updateRDF = local_extension['updateRDF']
                extension.description = local_extension['description']
                extension.creator = local_extension['creator']
                extension.homepageURL = local_extension['homepageURL']
                extension.developers = local_extension['developers']
                extension.translators = local_extension['translators']
                extension.contributors = local_extension['contributors']
                extension.put()
            if px_dict.has_key(mid):
                web.debug("user had extension " + mid)
                px_dict[mid].version = local_extension['version']
                px_dict[mid].put()
                del px_dict[mid]
            else:
                web.debug("user did not have extension " + mid)
                px = ProfileExtension()
                px.extension = extension
                px.version = local_extension['version']
                px.profile = profile
                px.put()

        # Delete any user extensions from the database that weren't in the update
        for px in px_dict:
            web.debug("user no longer has extension " + mid)
            px_dict[px].delete()

        web.debug("profile key: %s" % profile.key())

        if send_welcome:
            web.ctx.status = "%s New Profile" % send_welcome
            web.header('Content-Type', 'text/x-json')
            return simplejson.dumps({'profile': str(profile.key()), 'secret': profile.secret})
        else:
            web.ctx.status = "200 OK"
            return "KTHXBAI"
Пример #4
0
    def POST(self):
        if not users.get_current_user():
            web.ctx.status = "401 Unauthorized"
            return

        user = db.GqlQuery("SELECT * FROM User WHERE goog = :1", users.get_current_user()).get()

        if not user:
            web.ctx.status = "401 Unauthorized"
            return

        # Build a dictionary of the user's current extensions
        user_extensions = db.GqlQuery("SELECT * FROM UserExtension WHERE user = :1", user)
        ux_dict = {}
        for e in user_extensions:
            ux_dict[e.extension.mid] = e
        web.debug(ux_dict)

        i = web.input()
        json = simplejson.loads(i.data)
        for mid in json:
            web.debug("processing " + mid)
            key = db.Key.from_path("Extension", mid)
            extension = Extension.get(key)
            if not extension:
                web.debug("new extension: " + mid)
                extension = Extension(key_name=mid)
                extension.mid = mid
                extension.name = json[mid]["name"]
                extension.icon_url = json[mid]["icon"]
                extension.put()
            if ux_dict.has_key(mid):
                web.debug("user had extension " + mid)
                ux_dict[mid].version = json[mid]["version"]
                ux_dict[mid].put()
                del ux_dict[mid]
            else:
                web.debug("user did not have extension " + mid)
                ux = UserExtension()
                ux.extension = extension
                ux.version = json[mid]["version"]
                ux.user = user
                ux.put()
        # Delete any user extensions from the database that weren't in the update
        for ux in ux_dict:
            web.debug("user no longer has extension " + mid)
            ux_dict[ux].delete()
        web.ctx.status = "200 OK"
        return