Beispiel #1
0
    def post(self):

        
  #      curr_enclave=self.request.uri.split("/")[1][1:] \
   #             if self.request.uri[0:2] == "/~" else None

        valid_identities = [i.handle for i in self.get_identities()]

        #protect against identity spoofing
        if self.get_argument("identity") not in valid_identities:
            self.forbidden()
       
        #retrieve actual identity object (this seems kludgy)
        for i in self.get_identities():
            if self.get_argument("identity") == i.handle:
                ident_to_post_with = i
                break
        
        temp = self.get_argument("enclave")
        if temp == "":
            temp = "all"

        post_to = self.graph.enclaves.index.lookup(name=temp)
        if post_to is None:
            print ("post_to is none")
            self.render_template("new_post.html",\
                    error_message="That enclave does \
                    not exist. Please post to an existing \
                    enclave or leave the field blank.",\
                    identities=valid_identities)
            return

        post_type = self.get_argument("post_type")
        if ( post_type == "link" or post_type == "image" ):
            newpost = self.graph.posts.create(
                                    title=escape(self.get_argument("title")),
                                    url=quoteattr(self.get_argument("url")),
                                    post_type=post_type)
        elif (post_type == "text"):
            newpost = self.graph.posts.create(
                                    title=escape(self.get_argument("title")),
                                    body_text=escape(
                                        self.get_argument("body")),
                                    post_type=post_type)
        else:
            # hopefully we won't ever see this :)
            print(post_type)
            self.render_template("new_post.html",\
                    error_message="Invalid post type",\
                    identities=valid_identities)
            return

        if newpost:
            post_to = post_to.next()
            self.graph.posted_by.create(newpost,ident_to_post_with)   
            self.graph.posted_to.create(newpost,post_to) 

            self.redirect("/")
Beispiel #2
0
def markdown(content, escape=escape):
    if escape:
        content = escape(content)
    content = RE_LINK.sub(replace_link, content)
    content = RE_SPACE.sub(replace_space, content)
    content = RE_ENTER.sub(replace_enter, content)
    return content
Beispiel #3
0
def sync_check_customer_exist(name):
    response = requests.get(base_url + '/Camera/CustomerInfor?name=' +
                            tornado.escape(name),
                            verify=False)
    if response != None and response != '':
        return True
    else:
        return False
Beispiel #4
0
    def safe(self, content):
        if content is None:
            return None

        user = self.current_user
        if user.type >= user.ROOT:
            return content

        return escape(content)
Beispiel #5
0
    def post(self):
        _user_id = self.get_current_user()['id']
        _user_name = self.get_current_user()['name']
        _name = escape(self.get_argument('name'))
        _url = escape(self.get_argument('url'))
        _address = escape(self.get_argument('address'))
        _city = escape(self.get_argument('city'))
        _event_id = escape(self.get_argument('event_id'))
        self.db.execute("""INSERT INTO willbeout_suggest (user_id,
                                                    user_name,
                                                    event_id,
                                                    name,
                                                    city,
                                                    address,
                                                    url) VALUES (
                                                        %s, %s, %s, %s, %s, %s, %s)""",
                        int(_user_id), _user_name, int(
                            _event_id), _name, _city, _address,
                        _url)

        self.write('OK')
Beispiel #6
0
	def on_message(self, message):
		bucket = json.loads(message)
		if (bucket['state'] == 'open'):
			if (bucket.get('value') == None):
				cone[self] = random.randint(1000, 9999)
			else:
				cone[self] = long(bucket['value'])
			for connection, id in cone.iteritems():
				out = {'state':1, 'clients':len(cone), 'id':id}
				connection.write_message(json.dumps(out))
		elif (bucket['state'] == 'message'):
			db.execute("insert into myTable values (null, %d, '%s')" % (cone[self], bucket['value']))
			db.commit()
			for connection, id in cone.iteritems():
				out = {'state':2, 'message':escape(bucket['value']), 'id':cone[self]}
				connection.write_message(json.dumps(out))
Beispiel #7
0
     #         gender = 1
     #     else:
     #         gender = 0
     # RedisHandler.f_hset(GENDERKEY, uid_tmp, gender)
     # RedisHandler.f_hset(SCHOOLKEY, uid_tmp, cursor["school"])
 elif json_data["type"] == 2:
     #print message
     #{"type":2,"recv":who,"sender":who,"msg":content,"time":time}
     try:
         token = str(json_data["token"])
         uid_tmp = str(json_data["sender"])
         if check_token(uid_tmp, token):
             u = SocketHandler.client_uid_user[str(
                 json_data["recv"])]
             #u = util.RedisHandle.f_hget(CLIENT_UID_USER, str(json_data["recv"]))
             json_data['msg'] = escape(json_data['msg'])
             SocketHandler.send_to_one(u, json.dumps(json_data))
         else:
             #print "token param error"
             return
     except ValueError:
         self.write_message(
             json.dumps({
                 "type": 0,
                 "err": "uid error"
             }))
         return
 elif json_data["type"] == 3:
     #print message
     #{"type":3,"recv":"","sender":who,"msg":content,"time":time}
     try:
Beispiel #8
0
     #     if cursor["gender"] == u"男":
     #         gender = 1
     #     else:
     #         gender = 0
     # RedisHandler.f_hset(GENDERKEY, uid_tmp, gender)
     # RedisHandler.f_hset(SCHOOLKEY, uid_tmp, cursor["school"])
 elif json_data["type"] == 2:
     #print message
     #{"type":2,"recv":who,"sender":who,"msg":content,"time":time}
     try:
         token = str(json_data["token"])
         uid_tmp = str(json_data["sender"])
         if check_token(uid_tmp, token):
             u = SocketHandler.client_uid_user[str(json_data["recv"])]
             #u = util.RedisHandle.f_hget(CLIENT_UID_USER, str(json_data["recv"]))
             json_data['msg'] = escape(json_data['msg'])
             SocketHandler.send_to_one(u, json.dumps(json_data))
         else:
             #print "token param error"
             return
     except ValueError:
         self.write_message(json.dumps({"type":0, "err": "uid error"}))
         return
 elif json_data["type"] == 3:
     #print message
     #{"type":3,"recv":"","sender":who,"msg":content,"time":time}
     try:
         token = str(json_data["token"])
         uid_tmp = str(json_data["uid"])
         if check_token(uid_tmp, token):
             json_data["sender"] = util.decrypt(15, json_data["sender"])