Exemplo n.º 1
0
 def get_comments(t_key, from_id, to_id):
     objs = []
     for i in range(from_id, to_id+1):
         value = kv.get('%s-%d'%(t_key, i))
         if value:
             objs.append(decode_dict(value))
     return objs
Exemplo n.º 2
0
 def get_comments(t_key, from_id, to_id):
     objs = []
     for i in range(from_id, to_id + 1):
         value = kv.get('%s-%d' % (t_key, i))
         if value:
             objs.append(decode_dict(value))
     return objs
Exemplo n.º 3
0
    def set_node(id, name, imgurl, about):
        if id:
            n_obj_str = kv.get('n-' + id)
            ndict = decode_dict(n_obj_str)

            ndict['id'] = id
            ndict['name'] = name
            ndict['imgurl'] = imgurl
            ndict['about'] = about

            if kv.set('n-' + id, encode_dict(ndict)):
                clear_cache_multi(['newest_add_node'])
                return id  #True
            else:
                return False
        else:
            ndict = NODE_DICT.copy()
            #get node id
            cur_num = kv.get('node_auto_increment')
            if cur_num:
                id = str(cur_num)
            else:
                id = '1'
            ndict['id'] = id
            ndict['name'] = name
            ndict['imgurl'] = imgurl
            ndict['about'] = about

            if kv.set('n-' + id, encode_dict(ndict)):
                if kv.set('node_auto_increment', int(id) + 1):
                    clear_cache_multi(['newest_add_node'])
                    return id  #True
            return False
Exemplo n.º 4
0
 def set_node(id, name, imgurl, about):
     if id:
         n_obj_str = kv.get('n-' + id)
         ndict = decode_dict(n_obj_str)
         
         ndict['id'] = id
         ndict['name'] = name
         ndict['imgurl'] = imgurl
         ndict['about'] = about
             
         if kv.set('n-' + id, encode_dict(ndict)):
             clear_cache_multi(['newest_add_node'])
             return id #True
         else:
             return False
     else:
         ndict = NODE_DICT.copy()
         #get node id
         cur_num = kv.get('node_auto_increment')
         if cur_num:
             id = str(cur_num)
         else:
             id = '1'
         ndict['id'] = id
         ndict['name'] = name
         ndict['imgurl'] = imgurl
         ndict['about'] = about
         
         if kv.set('n-' + id, encode_dict(ndict)):
             if kv.set('node_auto_increment', int(id)+1):
                 clear_cache_multi(['newest_add_node'])
                 return id #True
         return False
Exemplo n.º 5
0
    def post(self):
        name = str(self.get_argument('name', '').lower().encode('utf-8'))
        pw = self.get_argument('pw', '')

        errors = []
        if name and pw:
            if len(name) < 20 or len(pw) < 20:
                if re.search('^[a-zA-Z0-9]+$', name):
                    pwmd5 = md5(pw.encode('utf-8')).hexdigest()
                    u_obj = kv.get('m-' + name)
                    if u_obj:
                        member_dict = decode_dict(u_obj)
                        if pwmd5 == member_dict['code'] and int(
                                member_dict['flag']) >= 1:
                            #set sr_code
                            code_list = [member_dict['code']]
                            u_topic_time = kv.get('u_topic_time:' + name)
                            if u_topic_time:
                                code_list.append(u_topic_time)
                            u_comment_time = kv.get('u_comment_time:' + name)
                            if u_comment_time:
                                code_list.append(u_comment_time)
                            #login
                            self.set_cookie('username',
                                            name,
                                            path="/",
                                            expires_days=365)
                            self.set_cookie(
                                'usercode',
                                md5(''.join(code_list)).hexdigest(),
                                path="/",
                                expires_days=365)
                            self.set_cookie('userflag',
                                            member_dict['flag'],
                                            path="/",
                                            expires_days=365)
                            if member_dict['flag'] == '1':
                                self.redirect('/setavatar')
                            else:
                                self.redirect('/')
                            return

                        else:
                            errors.append('用户名或密码不对或已被禁用')
                    else:
                        errors.append('用户名或密码不对')
                else:
                    errors.append('用户名只能包含字母和数字')
            else:
                errors.append('用户名或密码太长了')
        else:
            errors.append('用户名和密码必填')

        self.echo('login.html', {
            'title': "登录",
            'errors': errors,
            'name': name,
            'newest_node': Node.get_newest(),
        },
                  layout='_layout.html')
Exemplo n.º 6
0
 def set_flag(name, flag):
     u_obj_str = kv.get('m-' + name)
     if u_obj_str:
         u_obj = decode_dict(u_obj_str)
         if u_obj['flag'] != flag:
             u_obj['flag'] = flag
             return kv.set('m-' + name, encode_dict(u_obj))
     return False
Exemplo n.º 7
0
 def set_flag(name, flag):
     u_obj_str = kv.get('m-' + name)
     if u_obj_str:
         u_obj = decode_dict(u_obj_str)
         if u_obj['flag'] != flag:
             u_obj['flag'] = flag
             return kv.set('m-' + name, encode_dict(u_obj))
     return False
Exemplo n.º 8
0
 def get_page_topic(node_id, from_id, to_id):
     objs = []
     for i in range(from_id, to_id, -1):
         t_key = 't-%s-%d' % (node_id, i)
         #logging.error(t_key)
         value = kv.get(t_key)
         if value:
             objs.append((t_key, decode_dict(value)))
     return objs
Exemplo n.º 9
0
 def get_page_topic(node_id, from_id, to_id):
     objs = []
     for i in range(from_id, to_id, -1):
         t_key = 't-%s-%d' % (node_id, i)
         #logging.error(t_key)
         value = kv.get(t_key)
         if value:
             objs.append((t_key, decode_dict(value)))
     return objs
Exemplo n.º 10
0
 def get_notifications(username, keys_list_str):
     if keys_list_str:
         objs = []
         for key in keys_list_str.split(','):
             value = kv.get(key)
             if value:
                 objs.append((key, decode_dict(value)))
         return objs
     else:
         return []
Exemplo n.º 11
0
 def get_notifications(username, keys_list_str):
     if keys_list_str:
         objs = []
         for key in keys_list_str.split(','):
             value = kv.get(key)
             if value:
                 objs.append((key, decode_dict(value)))
         return objs
     else:
         return []
Exemplo n.º 12
0
 def get_comment_topic_by_keys(keys_list_key):
     obj = kv.get(keys_list_key)
     if obj:
         objs = []
         for key in obj.split(',')[:10]:
             value = kv.get(key)
             if value:
                 objs.append((key, decode_dict(value)['title']))
         return objs
     else:
         return []
Exemplo n.º 13
0
 def get_comment_topic_by_keys(keys_list_key):
     obj = kv.get(keys_list_key)
     if obj:
         objs = []
         for key in obj.split(',')[:10]:
             value = kv.get(key)
             if value:
                 objs.append((key, decode_dict(value)['title']))
         return objs
     else:
         return []
Exemplo n.º 14
0
 def get_recent_node():
     keys = kv.get('recent_view_node')
     if keys:
         objs = []
         for key in keys.split(','):
             value = kv.get(key)
             if value:
                 n_obj = decode_dict(value)
                 objs.append((key, n_obj['name']))
         return objs
     else:
         return None
Exemplo n.º 15
0
 def get_recent_node():
     keys = kv.get('recent_view_node')
     if keys:
         objs = []
         for key in keys.split(','):
             value = kv.get(key)
             if value:
                 n_obj = decode_dict(value)
                 objs.append((key, n_obj['name']))
         return objs
     else:
         return None
Exemplo n.º 16
0
 def get_hot_node():
     h_obj = kv.get('nodekey-topicnum')
     if h_obj:
         d = dict([x.split("\x1f")[0],int(x.split("\x1f")[1])] for x in h_obj.split("\x1e"))
         sorted_keys = sorted(d, key=d.__getitem__, reverse=True)[:10]
         objs = []
         for key in sorted_keys:
             value = kv.get(key)
             if value:
                 n_obj = decode_dict(value)
                 objs.append((key, n_obj['name']))
         return objs
     else:
         return None
Exemplo n.º 17
0
 def get_hot_node():
     h_obj = kv.get('nodekey-topicnum')
     if h_obj:
         d = dict([x.split("\x1f")[0],
                   int(x.split("\x1f")[1])] for x in h_obj.split("\x1e"))
         sorted_keys = sorted(d, key=d.__getitem__, reverse=True)[:10]
         objs = []
         for key in sorted_keys:
             value = kv.get(key)
             if value:
                 n_obj = decode_dict(value)
                 objs.append((key, n_obj['name']))
         return objs
     else:
         return None
Exemplo n.º 18
0
 def post(self):
     name = str(self.get_argument('name','').lower().encode('utf-8'))
     pw = self.get_argument('pw','')
     
     errors = []
     if name and pw:
         if len(name)<20 or len(pw)<20:
             if re.search('^[a-zA-Z0-9]+$', name):
                 pwmd5 = md5(pw.encode('utf-8')).hexdigest()
                 u_obj = kv.get('m-' + name)
                 if u_obj:
                     member_dict = decode_dict(u_obj)
                     if pwmd5 == member_dict['code'] and int(member_dict['flag']) >= 1:
                         #set sr_code
                         code_list = [member_dict['code']]
                         u_topic_time = kv.get('u_topic_time:'+name)
                         if u_topic_time:
                             code_list.append(u_topic_time)
                         u_comment_time = kv.get('u_comment_time:'+name)
                         if u_comment_time:
                             code_list.append(u_comment_time)
                         #login
                         self.set_cookie('username', name, path="/", expires_days = 365 )
                         self.set_cookie('usercode', md5(''.join(code_list)).hexdigest(), path="/", expires_days = 365 )
                         self.set_cookie('userflag', member_dict['flag'], path="/", expires_days = 365 )
                         if member_dict['flag'] == '1':
                             self.redirect('/setavatar')
                         else:
                             self.redirect('/')
                         return
                         
                     else:
                         errors.append('用户名或密码不对或已被禁用')
                 else:
                     errors.append('用户名或密码不对')
             else:
                 errors.append('用户名只能包含字母和数字')
         else:
             errors.append('用户名或密码太长了')
     else:
         errors.append('用户名和密码必填')
         
     self.echo('login.html', {
         'title': "登录",
         'errors':errors,
         'name':name,
         'newest_node': Node.get_newest(),
     }, layout='_layout.html')        
Exemplo n.º 19
0
 def get_newest():
     cur_num = kv.get('node_auto_increment')
     if cur_num:
         id = str(cur_num)
     else:
         id = '1'
     from_id = int(id) - 1
     to_id = from_id - 10
     if to_id < 0:
         to_id = 0
     objs = []
     for x in range(from_id, to_id, -1):
         value = kv.get('n-' + str(x))
         if value:
             n_obj = decode_dict(value)
             objs.append(('n-' + str(x), n_obj['name']))
     return objs
Exemplo n.º 20
0
 def get_newest():
     cur_num = kv.get('node_auto_increment')
     if cur_num:
         id = str(cur_num)
     else:
         id = '1'
     from_id = int(id)-1
     to_id = from_id - 10
     if to_id <0:
         to_id = 0
     objs = []
     for x in range(from_id, to_id, -1):
         value = kv.get('n-'+str(x))
         if value:
             n_obj = decode_dict(value)
             objs.append(('n-'+str(x), n_obj['name']))
     return objs
Exemplo n.º 21
0
 def check_loged_user(name, sr_code, flag=1):
     u_obj = kv.get('m-' + name)
     if u_obj:
         member_dict = decode_dict(u_obj)
         if int(member_dict['flag']) >= flag:
             code_list = [member_dict['code']]
             u_topic_time = kv.get('u_topic_time:' + name)
             if u_topic_time:
                 code_list.append(u_topic_time)
             u_comment_time = kv.get('u_comment_time:' + name)
             if u_comment_time:
                 code_list.append(u_comment_time)
             #code_md5 = md5(''.join(code_list)).hexdigest()
             if md5(''.join(code_list)).hexdigest() == sr_code:
                 return member_dict
             else:
                 return None
         else:
             return None
     else:
         return None
Exemplo n.º 22
0
 def check_loged_user(name, sr_code, flag=1):
     u_obj = kv.get('m-' + name)
     if u_obj:
         member_dict = decode_dict(u_obj)
         if int(member_dict['flag']) >= flag:
             code_list = [member_dict['code']]
             u_topic_time = kv.get('u_topic_time:'+name)
             if u_topic_time:
                 code_list.append(u_topic_time)
             u_comment_time = kv.get('u_comment_time:'+name)
             if u_comment_time:
                 code_list.append(u_comment_time)
             #code_md5 = md5(''.join(code_list)).hexdigest()
             if md5(''.join(code_list)).hexdigest() == sr_code:
                 return member_dict
             else:
                 return None
         else:
             return None
     else:
         return None
Exemplo n.º 23
0
 def get_by_name_for_edit(name):
     if name:
         m_obj_str = kv.get('m-' + name)
         return decode_dict(m_obj_str)
     else:
         return MEMBER_DICT.copy()
Exemplo n.º 24
0
 def get_by_name(name):
     u_obj = kv.get('m-' + name)
     if u_obj:
         return decode_dict(u_obj)
     else:
         return None
Exemplo n.º 25
0
 def get_by_id_for_edit(id):
     if id:
         n_obj_str = kv.get('n-' + id)
         return  decode_dict(n_obj_str)
     else:
         return NODE_DICT.copy()
Exemplo n.º 26
0
 def get_by_key(key):
     t_obj_str = kv.get(key)
     if t_obj_str:
         return decode_dict(t_obj_str)
     else:
         return None
Exemplo n.º 27
0
 def get_by_key(key):
     t_obj_str = kv.get(key)
     if t_obj_str:
         return decode_dict(t_obj_str)
     else:
         return None
Exemplo n.º 28
0
 def get_by_name(name):
     u_obj = kv.get('m-' + name)
     if u_obj:
         return decode_dict(u_obj)
     else:
         return None
Exemplo n.º 29
0
 def get_by_id_for_edit(id):
     if id:
         n_obj_str = kv.get('n-' + id)
         return decode_dict(n_obj_str)
     else:
         return NODE_DICT.copy()
Exemplo n.º 30
0
 def get_by_name_for_edit(name):
     if name:
         m_obj_str = kv.get('m-' + name)
         return  decode_dict(m_obj_str)
     else:
         return MEMBER_DICT.copy()