Ejemplo n.º 1
0
 def get(self, fid):
     uid = self.get_secure_cookie('user')
     if fid == uid:
         self.write('F')
     else:
         res = db.follow(int(uid), int(fid))
         if res == 1:
             self.write('T')
         else:
             self.write('F')
Ejemplo n.º 2
0
    def POST(self, action):
        if action == "upload_photo":
            # this is to prevent IE from downloading the JSON.
            web.header("Content-Type", "text/plain")
        else:
            web.header("Content-Type", "application/json")
        set_no_cache()

        # check if we have the action
        if action not in self.POST_ACTIONS:
            return error.wrong_action()

        # get the input data if we have the spec
        if action in self.VALIDATE_SPECS:
            d = get_input(self.VALIDATE_SPECS[action])

        # act
        if action == "register":
            return jsond(db.register(d.uid, d.email, d.password))
        elif action == "login":
            u = db.checkLogin(d.uid, d.password)
            if u:
                session.uuid = str(u["_id"])
                return jsond({"uid": u["uid"]})
            else:
                return error.wrong_login()

        # check login
        uuid = session.get("uuid", None)
        if not uuid:
            return error.not_logged_in()

        if action == "follow":
            return jsond(db.follow(uuid, d.uid))

        elif action == "unfollow":
            return jsond(db.unfollow(uuid, d.uid))

        elif action == "publish":
            req = spec.extract(self.EXTRACT_SPECS["publish_request"], d)
            return jsond(db.publish(uuid, **req))

        elif action == "remove":
            req = spec.extract(self.EXTRACT_SPECS["remove_request"], d)
            return jsond(db.remove(uuid, **req))

        elif action == "update_profile":
            u = db.update_profile(uuid, d)
            return jsond(spec.extract(self.EXTRACT_SPECS["current_user"], u))

        elif action == "upload_photo":
            try:
                d = web.input(photo={})
                if "photo" in d:
                    u = db.get_user(uuid)
                    photo.resize_save(u["uid"], d.photo.file)
                    if db.update_photo(uuid, True).has_key("success"):
                        return jsond({"success": 1})
                return error.photo_upload_failed()
            except Exception, e:
                traceback.print_exc()
                return error.photo_upload_failed()
Ejemplo n.º 3
0
	def event_stream():
		for data in db.follow( 'term' ):
			for line in data.split( '\n' ):
				yield 'data: {0}\n'.format( line )
			yield '\n'
Ejemplo n.º 4
0
    def POST(self, action):
        if action == 'upload_photo':
            # this is to prevent IE from downloading the JSON.
            web.header('Content-Type', 'text/plain')
        else:
            web.header('Content-Type', 'application/json')
        set_no_cache()

        # check if we have the action
        if action not in self.POST_ACTIONS:
            return error.wrong_action()

        # get the input data if we have the spec
        if action in self.VALIDATE_SPECS:
            d = get_input(self.VALIDATE_SPECS[action])

        # act
        if action == 'register':
            return jsond(db.register(d.uid, d.email, d.password))
        elif action == 'login':
            u = db.checkLogin(d.uid, d.password)
            if u:
                session.uuid = str(u['_id'])
                return jsond({'uid': u['uid']})
            else:
                return error.wrong_login()

        # check login
        uuid = session.get('uuid', None)
        if not uuid:
            return error.not_logged_in()

        if action == 'follow':
            return jsond(db.follow(uuid, d.uid))

        elif action == 'unfollow':
            return jsond(db.unfollow(uuid, d.uid))

        elif action == 'publish':
            req = spec.extract(self.EXTRACT_SPECS['publish_request'], d)
            return jsond(db.publish(uuid, **req))

        elif action == 'remove':
            req = spec.extract(self.EXTRACT_SPECS['remove_request'], d)
            return jsond(db.remove(uuid, **req))

        elif action == 'update_profile':
            u = db.update_profile(uuid, d)
            return jsond(spec.extract(self.EXTRACT_SPECS['current_user'], u))

        elif action == 'upload_photo':
            try:
                d = web.input(photo={})
                if 'photo' in d:
                    u = db.get_user(uuid)
                    photo.resize_save(u['uid'], d.photo.file)
                    if db.update_photo(uuid, True).has_key('success'):
                        return jsond({'success': 1})
                return error.photo_upload_failed()
            except Exception, e:
                traceback.print_exc()
                return error.photo_upload_failed()