Пример #1
0
 def get(self, nodeid):
     n_obj = Node.get_by_key('n-'+str(nodeid))
     if not n_obj:
         self.set_status(404)
         self.write('404')
         return
     
     from_id = int(self.get_argument('id', '0'))
     if from_id<=0 and n_obj['count']:
         from_id = int(n_obj['count'])
     
     to_id = from_id - EACH_PAGE_POST_NUM
     if to_id<0:
         to_id = 0
     
     self.echo('nodedetail.html', {
         'title': n_obj['name'],
         'n_obj': n_obj,
         'from_id': from_id,
         'to_id': to_id,
         'topic_objs': Node.get_page_topic(str(nodeid), from_id, to_id),
         'newest_node': Node.get_newest(),
         'recent_node': Node.get_recent_node(),
         'hot_node': Node.get_hot_node(),
         'recent_topic_objs': Commomkvdb.get_comment_topic_by_keys('recent-topic-home'),
         'comment_topic_objs': Commomkvdb.get_comment_topic_by_keys('recent-comment-topic-home'),            
     }, layout='_layout.html')
     Node.add_node_key('n-'+str(nodeid))
Пример #2
0
 def get(self, nodekey, topicnum):
     nodekey = str(nodekey)
     topicnum = str(topicnum)
     h_obj = Commomkvdb.get_by_key('nodekey-topicnum')
     if h_obj:
         h_obj[nodekey] = topicnum
         Commomkvdb.save('nodekey-topicnum', h_obj)
         clear_cache_multi(['get_hot_node'])
     else:
         Commomkvdb.save('nodekey-topicnum', {nodekey: topicnum})
Пример #3
0
 def get(self, nodekey, topicnum):
     nodekey = str(nodekey)
     topicnum = str(topicnum)
     h_obj = Commomkvdb.get_by_key('nodekey-topicnum')
     if h_obj:
         h_obj[nodekey] = topicnum
         Commomkvdb.save('nodekey-topicnum', h_obj)
         clear_cache_multi(['get_hot_node'])
     else:
         Commomkvdb.save('nodekey-topicnum', {nodekey:topicnum})
Пример #4
0
    def get(self, nodeid, topicid):
        t_key = 't-%s-%s' % (str(nodeid), str(topicid))
        t_obj = Topic.get_by_key(t_key)
        if not t_obj or t_obj.has_key('hide'):
            self.set_status(404)
            self.echo(
                'error.html', {
                    'page': '404',
                    'title': "Can't find out this URL",
                    'h2': 'Oh, my god!',
                    'msg': 'Something seems to be lost...'
                })

            return
        if t_obj['cnum']:
            cnum = int(t_obj['cnum'])
            from_id = int(self.get_argument('id', '1'))
            if from_id > 1 and from_id % EACH_PAGE_COMMENT_NUM != 1:
                self.redirect('/' + t_key)
                return
            to_id = from_id + EACH_PAGE_COMMENT_NUM - 1
            if to_id > cnum:
                to_id = cnum
            c_objs = Comment.get_comments(t_key, from_id, to_id)
        else:
            c_objs = None
            from_id = to_id = cnum = 0

        self.echo('topicdetail.html', {
            'title':
            t_obj['title'] + ' - ' + t_obj['nodename'],
            'description':
            'description',
            't_obj':
            t_obj,
            'c_objs':
            c_objs,
            'from_id':
            from_id,
            'to_id':
            to_id,
            'cnum':
            cnum,
            'newest_node':
            Node.get_newest(),
            'recent_node':
            Node.get_recent_node(),
            'hot_node':
            Node.get_hot_node(),
            'recent_topic_objs':
            Commomkvdb.get_comment_topic_by_keys('recent-topic-home'),
            'comment_topic_objs':
            Commomkvdb.get_comment_topic_by_keys('recent-comment-topic-home'),
        },
                  layout='_layout.html')
Пример #5
0
 def get(self):
     self.echo('home.html', {
         'title': "首页",
         'topic_objs': Commomkvdb.get_topic_by_keys('recent-topic-home'),
         'site_counts': Count.get_site_counts(),
         'newest_node': Node.get_newest(),
         'recent_node': Node.get_recent_node(),
         'hot_node': Node.get_hot_node(),
         #'recent_topic_objs': Commomkvdb.get_comment_topic_by_keys('recent-topic-home'),
         'comment_topic_objs': Commomkvdb.get_comment_topic_by_keys('recent-comment-topic-home'),
     }, layout='_layout.html')
Пример #6
0
 def get(self):
     cur_user = self.cur_user()
     
     self.echo('notifications.html', {
         'title': "站内提醒",
         'topic_objs': Commomkvdb.get_notifications(cur_user['name'], cur_user.get('notic', '')),
         'newest_node': Node.get_newest(),
         'recent_node': Node.get_recent_node(),
         'recent_topic_objs': Commomkvdb.get_comment_topic_by_keys('recent-topic-home'),
         'comment_topic_objs': Commomkvdb.get_comment_topic_by_keys('recent-comment-topic-home'),                
     }, layout='_layout.html')        
Пример #7
0
 def get(self):
     posts = Commomkvdb.get_topic_by_keys('recent-topic-home')[:10]
     output = self.render('index.xml', {
                 'posts':posts,
                 'site_updated':int(time()),
             })
     self.set_header('Content-Type','application/atom+xml')
     self.write(output)
Пример #8
0
 def get(self):
     posts = Commomkvdb.get_topic_by_keys('recent-topic-home')[:10]
     output = self.render('index.xml', {
         'posts': posts,
         'site_updated': int(time()),
     })
     self.set_header('Content-Type', 'application/atom+xml')
     self.write(output)
Пример #9
0
    def get(self):
        cur_user = self.cur_user()

        self.echo('notifications.html', {
            'title':
            "站内提醒",
            'topic_objs':
            Commomkvdb.get_notifications(cur_user['name'],
                                         cur_user.get('notic', '')),
            'newest_node':
            Node.get_newest(),
            'recent_node':
            Node.get_recent_node(),
            'recent_topic_objs':
            Commomkvdb.get_comment_topic_by_keys('recent-topic-home'),
            'comment_topic_objs':
            Commomkvdb.get_comment_topic_by_keys('recent-comment-topic-home'),
        },
                  layout='_layout.html')
Пример #10
0
 def get(self, t_key):
     t_key = str(t_key)
     m_obj = self.cur_user()
     if m_obj.get('notic', ''):
         klist = m_obj['notic'].split(',')
         if t_key in klist:
             klist.remove(t_key)
             m_obj['notic'] = ','.join(klist)
             if Commomkvdb.save('m-'+str(m_obj['name']), m_obj):
                 clear_cache_multi(['cur_user:'******'name'])])
     self.redirect('/'+t_key)
Пример #11
0
 def get(self, t_key):
     t_key = str(t_key)
     m_obj = self.cur_user()
     if m_obj.get('notic', ''):
         klist = m_obj['notic'].split(',')
         if t_key in klist:
             klist.remove(t_key)
             m_obj['notic'] = ','.join(klist)
             if Commomkvdb.save('m-' + str(m_obj['name']), m_obj):
                 clear_cache_multi(['cur_user:'******'name'])])
     self.redirect('/' + t_key)
Пример #12
0
 def get(self, nodeid, topicid):
     t_key = 't-%s-%s' % (str(nodeid), str(topicid))
     t_obj = Topic.get_by_key(t_key)
     if not t_obj or t_obj.has_key('hide'):
         self.set_status(404)
         self.echo('error.html', {
             'page': '404',
             'title': "Can't find out this URL",
             'h2': 'Oh, my god!',
             'msg': 'Something seems to be lost...'
         })
         
         return
     if t_obj['cnum']:
         cnum = int(t_obj['cnum'])
         from_id = int(self.get_argument('id', '1'))
         if from_id>1 and from_id%EACH_PAGE_COMMENT_NUM!=1:
             self.redirect('/'+t_key)
             return
         to_id = from_id + EACH_PAGE_COMMENT_NUM - 1
         if to_id > cnum:
             to_id = cnum
         c_objs = Comment.get_comments(t_key, from_id, to_id)
     else:
         c_objs = None
         from_id = to_id = cnum = 0
         
     self.echo('topicdetail.html', {
         'title': t_obj['title'] + ' - ' + t_obj['nodename'],
         'description':'description',
         't_obj': t_obj,
         'c_objs': c_objs,
         'from_id': from_id,
         'to_id': to_id,
         'cnum': cnum,
         'newest_node': Node.get_newest(),
         'recent_node': Node.get_recent_node(),
         'hot_node': Node.get_hot_node(),
         'recent_topic_objs': Commomkvdb.get_comment_topic_by_keys('recent-topic-home'),
         'comment_topic_objs': Commomkvdb.get_comment_topic_by_keys('recent-comment-topic-home'),            
     }, layout='_layout.html')
Пример #13
0
 def get(self):
     self.echo(
         'home.html',
         {
             'title':
             "首页",
             'topic_objs':
             Commomkvdb.get_topic_by_keys('recent-topic-home'),
             'site_counts':
             Count.get_site_counts(),
             'newest_node':
             Node.get_newest(),
             'recent_node':
             Node.get_recent_node(),
             'hot_node':
             Node.get_hot_node(),
             #'recent_topic_objs': Commomkvdb.get_comment_topic_by_keys('recent-topic-home'),
             'comment_topic_objs':
             Commomkvdb.get_comment_topic_by_keys(
                 'recent-comment-topic-home'),
         },
         layout='_layout.html')
Пример #14
0
    def post(self):
        t_key = str(self.get_argument('key', ''))
        content = self.get_argument('content', '')

        if t_key and content:
            t_obj = Comment.get_by_key(t_key)
            if t_obj:
                t_obj['content'] = textilize(content)
                if Commomkvdb.save(t_key, t_obj):
                    self.redirect('/edit-comment?key=%s' % t_key)
                    return

        self.redirect('/edit-comment?key=%s' % t_key)
Пример #15
0
 def post(self):
     t_key = str(self.get_argument('key',''))
     content = self.get_argument('content','')
     
     if t_key and content:
         t_obj = Comment.get_by_key(t_key)
         if t_obj:
             t_obj['content'] = textilize(content)
             if Commomkvdb.save(t_key, t_obj):
                 self.redirect('/edit-comment?key=%s'%t_key)
                 return
     
     self.redirect('/edit-comment?key=%s'%t_key)
Пример #16
0
    def get(self, nodeid):
        n_obj = Node.get_by_key('n-' + str(nodeid))
        if not n_obj:
            self.set_status(404)
            self.write('404')
            return

        from_id = int(self.get_argument('id', '0'))
        if from_id <= 0 and n_obj['count']:
            from_id = int(n_obj['count'])

        to_id = from_id - EACH_PAGE_POST_NUM
        if to_id < 0:
            to_id = 0

        self.echo('nodedetail.html', {
            'title':
            n_obj['name'],
            'n_obj':
            n_obj,
            'from_id':
            from_id,
            'to_id':
            to_id,
            'topic_objs':
            Node.get_page_topic(str(nodeid), from_id, to_id),
            'newest_node':
            Node.get_newest(),
            'recent_node':
            Node.get_recent_node(),
            'hot_node':
            Node.get_hot_node(),
            'recent_topic_objs':
            Commomkvdb.get_comment_topic_by_keys('recent-topic-home'),
            'comment_topic_objs':
            Commomkvdb.get_comment_topic_by_keys('recent-comment-topic-home'),
        },
                  layout='_layout.html')
        Node.add_node_key('n-' + str(nodeid))
Пример #17
0
 def get(self, name): 
     name = name.lower()
     m_obj = Member.get_by_name(str(name))
     if m_obj:
         self.echo('member.html', {
             'title': m_obj['name'],
             'm_obj': m_obj,
             'topic_objs': Commomkvdb.get_topic_by_keys('topic-'+str(m_obj['name'])),
             'member_comment_topic_objs': Commomkvdb.get_topic_by_keys('comment-topic-'+str(m_obj['name'])),
             'newest_node': Node.get_newest(),
             'recent_node': Node.get_recent_node(),
             'hot_node': Node.get_hot_node(),
             'recent_topic_objs': Commomkvdb.get_comment_topic_by_keys('recent-topic-home'),
             'comment_topic_objs': Commomkvdb.get_comment_topic_by_keys('recent-comment-topic-home'),                
         }, layout='_layout.html')
     else:
         self.set_status(404)
         self.echo('error.html', {
             'page': '404',
             'title': "Can't find out this URL",
             'h2': 'Oh, my god!',
             'msg': 'Something seems to be lost...'
         })
Пример #18
0
 def get(self, name):
     name = name.lower()
     m_obj = Member.get_by_name(str(name))
     if m_obj:
         self.echo('member.html', {
             'title':
             m_obj['name'],
             'm_obj':
             m_obj,
             'topic_objs':
             Commomkvdb.get_topic_by_keys('topic-' + str(m_obj['name'])),
             'member_comment_topic_objs':
             Commomkvdb.get_topic_by_keys('comment-topic-' +
                                          str(m_obj['name'])),
             'newest_node':
             Node.get_newest(),
             'recent_node':
             Node.get_recent_node(),
             'hot_node':
             Node.get_hot_node(),
             'recent_topic_objs':
             Commomkvdb.get_comment_topic_by_keys('recent-topic-home'),
             'comment_topic_objs':
             Commomkvdb.get_comment_topic_by_keys(
                 'recent-comment-topic-home'),
         },
                   layout='_layout.html')
     else:
         self.set_status(404)
         self.echo(
             'error.html', {
                 'page': '404',
                 'title': "Can't find out this URL",
                 'h2': 'Oh, my god!',
                 'msg': 'Something seems to be lost...'
             })
Пример #19
0
    def post(self):
        t_key = str(self.get_argument('key', ''))
        title = self.get_argument('title', '')
        content = self.get_argument('content', '')
        hide = self.get_argument('hide', '')

        if t_key and title and content:
            t_obj = Topic.get_by_key(t_key)
            if t_obj:
                t_obj['title'] = title
                t_obj['content'] = textilize(content)
                if hide:
                    t_obj['hide'] = hide
                else:
                    if t_obj.has_key('hide'):
                        del t_obj['hide']
                if Commomkvdb.save(t_key, t_obj):
                    self.redirect('/edit-post?key=%s' % t_key)
                    return

        self.redirect('/edit-post?key=%s' % t_key)
Пример #20
0
 def post(self):
     t_key = str(self.get_argument('key',''))
     title = self.get_argument('title','')
     content = self.get_argument('content','')
     hide = self.get_argument('hide','')
     
     if t_key and title and content:
         t_obj = Topic.get_by_key(t_key)
         if t_obj:
             t_obj['title'] = title
             t_obj['content'] = textilize(content)
             if hide:
                 t_obj['hide'] = hide
             else:
                 if t_obj.has_key('hide'):
                     del t_obj['hide']
             if Commomkvdb.save(t_key, t_obj):
                 self.redirect('/edit-post?key=%s'%t_key)
                 return
     
     self.redirect('/edit-post?key=%s'%t_key)
Пример #21
0
 def post(self, t_key):
     t_key = str(t_key)
     member = self.get_argument('member', '')
     if member:
         clearkeys = []
         for m in member.split(','):
             logging.error(m)
             m_obj = Member.get_by_name(str(m))
             if m_obj:
                 if m_obj.get('notic', ''):
                     klist = m_obj['notic'].split(',')
                 else:
                     klist = []
                 if t_key not in klist:
                     klist.insert(0, t_key)
                     m_obj['notic'] = ','.join(klist[:NOTIFY_NUM])
                     try:
                         if Commomkvdb.save('m-' + str(m), m_obj):
                             clearkeys.append('cur_user:'******'test task')
Пример #22
0
 def post(self, t_key):
     t_key = str(t_key)
     member = self.get_argument('member','')
     if member:
         clearkeys = []
         for m in member.split(','):
             logging.error(m)
             m_obj = Member.get_by_name(str(m))
             if m_obj:
                 if m_obj.get('notic', ''):
                     klist = m_obj['notic'].split(',')
                 else:
                     klist = []
                 if t_key not in klist:
                     klist.insert(0, t_key)
                     m_obj['notic'] = ','.join(klist[:NOTIFY_NUM])
                     try:
                         if Commomkvdb.save('m-'+str(m), m_obj):
                             clearkeys.append('cur_user:'******'test task')
Пример #23
0
    def post(self, nodeid='1'):
        n_obj = Node.get_by_key('n-' + str(nodeid))
        if not n_obj:
            self.set_status(404)
            self.write('404')
            return

        errors = []
        author = str(self.get_cookie('username', ''))
        title = self.get_argument('title', '')
        content = self.get_argument('content', '')

        t_obj = TOPIC_DICT.copy()
        if title and content:
            if len(title) <= TITLE_MAX_S and len(content) <= CONTENT_MAX_S:
                int_time = int(time())
                #check spam
                u_topic_time = kv.get('u_topic_time:' + author)
                if u_topic_time:
                    tlist = u_topic_time.split(',')
                    if len(tlist) == MEMBER_RECENT_TOPIC and (
                            int_time - int(tlist[-1])) < 3600:
                        self.write(
                            u'403:不要发帖太频繁了 <a href="/newpost/%s">请返回</a>' %
                            nodeid)
                        return

                #check repeat
                content = textilize(content)
                #content = safe_encode(content)
                con_md5 = md5(content.encode('utf-8')).hexdigest()
                if mc.get('c_' + con_md5):
                    self.write(u'403:请勿灌水 <a href="/newpost/%s">请返回</a>' %
                               nodeid)
                    return
                else:
                    mc.set('c_' + con_md5, '1', 36000)

                t_obj['title'] = title
                t_obj['nodeid'] = str(nodeid)
                t_obj['nodename'] = n_obj['name']
                t_obj['author'] = author
                t_obj['add'] = int_time
                t_obj['content'] = content

                if n_obj['count']:
                    topic_id = int(n_obj['count']) + 1
                else:
                    topic_id = 1
                if Topic.add(topic_id, t_obj):
                    topic_key = 't-%s-%s' % (str(nodeid), str(topic_id))
                    #node count +1
                    n_obj['count'] = str(topic_id)
                    Commomkvdb.save('n-' + str(nodeid), n_obj)

                    #member recent +key
                    #Member.add_key_rencent_topic(author, topic_key)
                    rt_obj = kv.get('topic-' + author)
                    if rt_obj:
                        olist = rt_obj.split(',')
                        if topic_key not in olist:
                            olist.insert(0, topic_key)
                            rt_obj = ','.join(olist[:MEMBER_RECENT_TOPIC])
                            kv.set('topic-' + author, rt_obj)
                    else:
                        rt_obj = topic_key
                        kv.set('topic-' + author, topic_key)

                    #recent in home +key
                    Commomkvdb.add_key_rencent_topic('recent-topic-home',
                                                     topic_key)
                    #all topic counter +1
                    Count.key_incr('all-topic-num')
                    #hot node
                    tqueue = TaskQueue('default')
                    tqueue.add(
                        Task('/task/hotnode/%s/%s' %
                             ('n-' + str(nodeid), str(topic_id)),
                             delay=5))
                    #notifications
                    mentions = findall_mentions(t_obj['content'], author)
                    if mentions:
                        tqueue.add(
                            Task('/task/mentions/' + topic_key,
                                 'member=' + ','.join(mentions),
                                 delay=8))

                    #set for check spam
                    #u_topic_time = kv.get('u_topic_time:'+author)
                    if u_topic_time:
                        tlist = u_topic_time.split(',')
                        if str(int_time) not in tlist:
                            tlist.insert(0, str(int_time))
                            u_topic_time = ','.join(
                                tlist[:MEMBER_RECENT_TOPIC])
                            kv.set('u_topic_time:' + author, u_topic_time)
                    else:
                        u_topic_time = str(int_time)
                        kv.set('u_topic_time:' + author, u_topic_time)

                    ##set new sr_code
                    cur_user = self.cur_user()
                    code_list = [cur_user['code'], u_topic_time]
                    u_comment_time = kv.get('u_comment_time:' + author)
                    if u_comment_time:
                        code_list.append(u_comment_time)
                    self.set_cookie('usercode',
                                    md5(''.join(code_list)).hexdigest(),
                                    path="/",
                                    expires_days=365)

                    #del cache
                    clear_cache_multi([
                        'get_topic_by_keys:recent-topic-home',
                        'get_topic_by_keys:topic-' + author,
                        'get_comment_topic_by_keys:recent-topic-home',
                        'get_comment_topic_by_keys:recent-comment-topic-home',
                        'cur_user:'******'/' + topic_key)
                    return
                else:
                    errors.append("服务器出现错误,请稍后再试")
            else:
                t_obj['title'] = title
                t_obj['content'] = content
                errors.append(u"注意标题和内容的最大字数:%s %d" %
                              (len(title), len(content)))
        else:
            errors.append("标题和内容必填")
        self.echo('newpost.html', {
            'title': "发新帖子",
            'errors': errors,
            'n_obj': n_obj,
            't_obj': t_obj,
        },
                  layout='_layout.html')
Пример #24
0
    def get(self):
        if USER_MODEL == 2:
            self.redirect('/sigin')
            return

        code = self.get_argument('code', '')
        if code:
            access_token = qqclient.request_access_token(code).get(
                'access_token', '')
            if access_token:
                #获取当前成功登录的 OpenID
                open_id = qqclient.get_open_id(access_token)
                if open_id:
                    #判断是否已存在
                    k = 'qq_' + str(open_id)
                    self.set_cookie('open_id',
                                    str(open_id),
                                    path="/",
                                    expires_days=1)
                    self.set_cookie('access_token',
                                    str(access_token),
                                    path="/",
                                    expires_days=1)
                    kv_member = kv.get(k)

                    if kv_member and len(kv_member) < 20:
                        #直接登录
                        #get member info
                        name = str(kv_member)
                        m_obj = Member.get_by_name(name)
                        if m_obj:
                            if m_obj['code'] != str(access_token):
                                m_obj['code'] = str(access_token)
                                Commomkvdb.save('m-' + str(kv_member), m_obj)
                                clear_cache_multi(['cur_user:'******'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()

                            #
                            self.set_cookie('username',
                                            str(kv_member),
                                            path="/",
                                            expires_days=365)
                            self.set_cookie(
                                'usercode',
                                str(md5(''.join(code_list)).hexdigest()),
                                path="/",
                                expires_days=365)
                            self.set_cookie('userflag',
                                            m_obj['flag'],
                                            path="/",
                                            expires_days=365)
                            if m_obj['flag'] == '1':
                                self.redirect('/setavatar')
                            else:
                                self.redirect('/')
                            return

                        else:
                            #设置用户名
                            kv.set('qq_' + str(open_id), str(access_token))
                            self.redirect('/setname')
                            return

                    else:
                        #注册新用户
                        kv.set('qq_' + str(open_id), str(access_token))
                        self.redirect('/setname')
                        return
                else:
                    self.write('获取open_id 失败,请返回再试')
            else:
                self.write('获取access_token 失败,请返回再试')
        else:
            self.write('获取code 失败,请返回再试')
Пример #25
0
 def post(self, nodeid, topicid):
     author = str(self.get_cookie('username',''))
     content = self.get_argument('content','')
     
     if author and content and len(content)<=COMMENT_MAX_S:
         int_time = int(time())
         #check spam
         u_comment_time = kv.get('u_comment_time:'+author)
         if u_comment_time:
             tlist = u_comment_time.split(',')
             if len(tlist)== MEMBER_RECENT_TOPIC and (int_time-int(tlist[-1])) < 3600:
                 self.write(u'403:不要回复太频繁了 <a href="/t-%s-%s">请返回</a>' % (nodeid, topicid))
                 return
         
         #check repeat
         content = textilize(content)
         #content = safe_encode(content)
         con_md5 = md5(content.encode('utf-8')).hexdigest()
         if mc.get('c_'+con_md5):
             self.write(u'403:请勿灌水 <a href="/t-%s-%s">请返回</a>' % (nodeid, topicid))
             return
         else:
             mc.set('c_'+con_md5, '1', 36000)
         
         ##
         t_key = 't-%s-%s' % (str(nodeid), str(topicid))
         t_obj = Topic.get_by_key(t_key)
         
         if t_obj['cnum']:
             id_num = int(t_obj['cnum']) + 1
         else:
             id_num = 1
         
         c_key = 't-%s-%s-%d' % (str(nodeid), str(topicid), id_num)
         c_obj = COMMENT_DICT.copy()
         c_obj['author'] = author
         c_obj['add'] = int_time
         c_obj['content'] = content
         
         if Commomkvdb.save(c_key, c_obj):
             #topic commont count +1
             t_obj['cnum'] = id_num
             t_obj['reply'] = author
             t_obj['edit'] = int_time
             Commomkvdb.save(t_key, t_obj)
             
             #member recent +key
             #Member.add_key_rencent_comment_topic(author, t_key)
             rt_obj = kv.get('comment-topic-'+author)
             if rt_obj:
                 olist = rt_obj.split(',')
                 if t_key in olist:
                     olist.remove(t_key)
                 olist.insert(0, t_key)
                 kv.set('comment-topic-'+author, ','.join(olist[:MEMBER_RECENT_TOPIC]))
             else:
                 kv.set('comment-topic-'+author, t_key)
             
             #recent comment in home +key
             Commomkvdb.add_key_rencent_topic('recent-comment-topic-home', t_key)
             #all comment counter +1
             Count.key_incr('all-comment-num')
             #notifications
             if t_obj['author'] != author:
                 mentions = findall_mentions(c_obj['content']+' @%s '%t_obj['author'], author)
             else:
                 mentions = findall_mentions(c_obj['content'], author)
             if mentions:
                 tqueue = TaskQueue('default')
                 tqueue.add(Task('/task/mentions/'+t_key, 'member='+','.join(mentions), delay=5))
             
             #set for check spam
             #u_comment_time = kv.get('u_comment_time:'+author)
             if u_comment_time:
                 tlist = u_comment_time.split(',')
                 if str(int_time) not in tlist:
                     tlist.insert(0, str(int_time))
                     u_comment_time = ','.join(tlist[:MEMBER_RECENT_TOPIC])
                     kv.set('u_comment_time:'+author, u_comment_time)
             else:
                 u_comment_time = str(int_time)
                 kv.set('u_comment_time:'+author, u_comment_time)
             
             ##set new sr_code
             cur_user = self.cur_user()
             code_list = [cur_user['code']]
             u_topic_time = kv.get('u_topic_time:'+author)
             if u_topic_time:
                 code_list.append(u_topic_time)
             if u_comment_time:
                 code_list.append(u_comment_time)
             self.set_cookie('usercode', md5(''.join(code_list)).hexdigest(), path="/", expires_days = 365 )
             
                 
             #del cache
             cachekeys = ['get_topic_by_keys:recent-comment-topic-home', 'get_topic_by_keys:comment-topic-'+author, 'get_comment_topic_by_keys:recent-topic-home', 'get_comment_topic_by_keys:recent-comment-topic-home','cur_user:'******'recent-topic-home')
             if tks and t_key in tks.split(','):
                 cachekeys.append('get_topic_by_keys:recent-topic-home')
             if id_num<EACH_PAGE_COMMENT_NUM:
                 cachekeys.append('get_comments:%s:1' % t_key)
             else:
                 cachekeys.append('get_comments:%s:%d' % (t_key, [i for i in range(1,id_num,EACH_PAGE_COMMENT_NUM)][-1]))
             clear_cache_multi(cachekeys)
             
             self.redirect('/'+t_key)
             return
     else:
         self.set_status(403)
         self.write('错误: 403 (请返回填写内容 或 内容太长了)')
Пример #26
0
 def get(self):
     if USER_MODEL==2:
         self.redirect('/sigin')
         return
     
     code = self.get_argument('code', '')
     if code:
         access_token = qqclient.request_access_token(code).get('access_token','')
         if access_token:
             #获取当前成功登录的 OpenID
             open_id = qqclient.get_open_id(access_token)
             if open_id:
                 #判断是否已存在
                 k = 'qq_' +str(open_id)
                 self.set_cookie('open_id', str(open_id), path="/", expires_days = 1 )
                 self.set_cookie('access_token', str(access_token), path="/", expires_days = 1 )
                 kv_member = kv.get(k)
                 
                 if kv_member and len(kv_member)<20:
                     #直接登录
                     #get member info
                     name = str(kv_member)
                     m_obj = Member.get_by_name(name)
                     if m_obj:
                         if m_obj['code'] != str(access_token):
                             m_obj['code'] = str(access_token)
                             Commomkvdb.save('m-'+str(kv_member), m_obj)
                             clear_cache_multi(['cur_user:'******'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()
                         
                         #
                         self.set_cookie('username', str(kv_member), path="/", expires_days = 365 )
                         self.set_cookie('usercode', str(md5(''.join(code_list)).hexdigest()), path="/", expires_days = 365 )
                         self.set_cookie('userflag', m_obj['flag'], path="/", expires_days = 365 )
                         if m_obj['flag'] == '1':
                             self.redirect('/setavatar')
                         else:
                             self.redirect('/')
                         return
                         
                     else:
                         #设置用户名
                         kv.set('qq_' +str(open_id), str(access_token))
                         self.redirect('/setname')
                         return
                     
                 else:
                     #注册新用户
                     kv.set('qq_' +str(open_id), str(access_token))
                     self.redirect('/setname')
                     return
             else:
                 self.write('获取open_id 失败,请返回再试')
         else:
             self.write('获取access_token 失败,请返回再试')
     else:
         self.write('获取code 失败,请返回再试')
Пример #27
0
    def post(self, nodeid, topicid):
        author = str(self.get_cookie('username', ''))
        content = self.get_argument('content', '')

        if author and content and len(content) <= COMMENT_MAX_S:
            int_time = int(time())
            #check spam
            u_comment_time = kv.get('u_comment_time:' + author)
            if u_comment_time:
                tlist = u_comment_time.split(',')
                if len(tlist) == MEMBER_RECENT_TOPIC and (
                        int_time - int(tlist[-1])) < 3600:
                    self.write(u'403:不要回复太频繁了 <a href="/t-%s-%s">请返回</a>' %
                               (nodeid, topicid))
                    return

            #check repeat
            content = textilize(content)
            #content = safe_encode(content)
            con_md5 = md5(content.encode('utf-8')).hexdigest()
            if mc.get('c_' + con_md5):
                self.write(u'403:请勿灌水 <a href="/t-%s-%s">请返回</a>' %
                           (nodeid, topicid))
                return
            else:
                mc.set('c_' + con_md5, '1', 36000)

            ##
            t_key = 't-%s-%s' % (str(nodeid), str(topicid))
            t_obj = Topic.get_by_key(t_key)

            if t_obj['cnum']:
                id_num = int(t_obj['cnum']) + 1
            else:
                id_num = 1

            c_key = 't-%s-%s-%d' % (str(nodeid), str(topicid), id_num)
            c_obj = COMMENT_DICT.copy()
            c_obj['author'] = author
            c_obj['add'] = int_time
            c_obj['content'] = content

            if Commomkvdb.save(c_key, c_obj):
                #topic commont count +1
                t_obj['cnum'] = id_num
                t_obj['reply'] = author
                t_obj['edit'] = int_time
                Commomkvdb.save(t_key, t_obj)

                #member recent +key
                #Member.add_key_rencent_comment_topic(author, t_key)
                rt_obj = kv.get('comment-topic-' + author)
                if rt_obj:
                    olist = rt_obj.split(',')
                    if t_key in olist:
                        olist.remove(t_key)
                    olist.insert(0, t_key)
                    kv.set('comment-topic-' + author,
                           ','.join(olist[:MEMBER_RECENT_TOPIC]))
                else:
                    kv.set('comment-topic-' + author, t_key)

                #recent comment in home +key
                Commomkvdb.add_key_rencent_topic('recent-comment-topic-home',
                                                 t_key)
                #all comment counter +1
                Count.key_incr('all-comment-num')
                #notifications
                if t_obj['author'] != author:
                    mentions = findall_mentions(
                        c_obj['content'] + ' @%s ' % t_obj['author'], author)
                else:
                    mentions = findall_mentions(c_obj['content'], author)
                if mentions:
                    tqueue = TaskQueue('default')
                    tqueue.add(
                        Task('/task/mentions/' + t_key,
                             'member=' + ','.join(mentions),
                             delay=5))

                #set for check spam
                #u_comment_time = kv.get('u_comment_time:'+author)
                if u_comment_time:
                    tlist = u_comment_time.split(',')
                    if str(int_time) not in tlist:
                        tlist.insert(0, str(int_time))
                        u_comment_time = ','.join(tlist[:MEMBER_RECENT_TOPIC])
                        kv.set('u_comment_time:' + author, u_comment_time)
                else:
                    u_comment_time = str(int_time)
                    kv.set('u_comment_time:' + author, u_comment_time)

                ##set new sr_code
                cur_user = self.cur_user()
                code_list = [cur_user['code']]
                u_topic_time = kv.get('u_topic_time:' + author)
                if u_topic_time:
                    code_list.append(u_topic_time)
                if u_comment_time:
                    code_list.append(u_comment_time)
                self.set_cookie('usercode',
                                md5(''.join(code_list)).hexdigest(),
                                path="/",
                                expires_days=365)

                #del cache
                cachekeys = [
                    'get_topic_by_keys:recent-comment-topic-home',
                    'get_topic_by_keys:comment-topic-' + author,
                    'get_comment_topic_by_keys:recent-topic-home',
                    'get_comment_topic_by_keys:recent-comment-topic-home',
                    'cur_user:'******'recent-topic-home')
                if tks and t_key in tks.split(','):
                    cachekeys.append('get_topic_by_keys:recent-topic-home')
                if id_num < EACH_PAGE_COMMENT_NUM:
                    cachekeys.append('get_comments:%s:1' % t_key)
                else:
                    cachekeys.append('get_comments:%s:%d' % (t_key, [
                        i for i in range(1, id_num, EACH_PAGE_COMMENT_NUM)
                    ][-1]))
                clear_cache_multi(cachekeys)

                self.redirect('/' + t_key)
                return
        else:
            self.set_status(403)
            self.write('错误: 403 (请返回填写内容 或 内容太长了)')
Пример #28
0
 def post(self, nodeid='1'):
     n_obj = Node.get_by_key('n-'+str(nodeid))
     if not n_obj:
         self.set_status(404)
         self.write('404')
         return
     
     errors = []
     author = str(self.get_cookie('username',''))
     title = self.get_argument('title','')
     content = self.get_argument('content','')
     
     t_obj = TOPIC_DICT.copy()
     if title and content:
         if len(title)<=TITLE_MAX_S and len(content)<=CONTENT_MAX_S:
             int_time = int(time())
             #check spam
             u_topic_time = kv.get('u_topic_time:'+author)
             if u_topic_time:
                 tlist = u_topic_time.split(',')
                 if len(tlist)== MEMBER_RECENT_TOPIC and (int_time-int(tlist[-1])) < 3600:
                     self.write(u'403:不要发帖太频繁了 <a href="/newpost/%s">请返回</a>' % nodeid)
                     return
             
             #check repeat
             content = textilize(content)
             #content = safe_encode(content)
             con_md5 = md5(content.encode('utf-8')).hexdigest()
             if mc.get('c_'+con_md5):
                 self.write(u'403:请勿灌水 <a href="/newpost/%s">请返回</a>' % nodeid)
                 return
             else:
                 mc.set('c_'+con_md5, '1', 36000)
             
             t_obj['title'] = title
             t_obj['nodeid'] = str(nodeid)
             t_obj['nodename'] = n_obj['name']
             t_obj['author'] = author
             t_obj['add'] = int_time
             t_obj['content'] = content
             
             if n_obj['count']:
                 topic_id = int(n_obj['count']) + 1
             else:
                 topic_id = 1
             if Topic.add(topic_id, t_obj):
                 topic_key = 't-%s-%s' % (str(nodeid), str(topic_id))
                 #node count +1
                 n_obj['count'] = str(topic_id)
                 Commomkvdb.save('n-'+str(nodeid), n_obj)
                 
                 #member recent +key
                 #Member.add_key_rencent_topic(author, topic_key)
                 rt_obj = kv.get('topic-'+author)
                 if rt_obj:
                     olist = rt_obj.split(',')
                     if topic_key not in olist:
                         olist.insert(0, topic_key)
                         rt_obj = ','.join(olist[:MEMBER_RECENT_TOPIC])
                         kv.set('topic-'+author, rt_obj)
                 else:
                     rt_obj = topic_key
                     kv.set('topic-'+author, topic_key)
                 
                 #recent in home +key
                 Commomkvdb.add_key_rencent_topic('recent-topic-home', topic_key)
                 #all topic counter +1
                 Count.key_incr('all-topic-num')
                 #hot node
                 tqueue = TaskQueue('default')
                 tqueue.add(Task('/task/hotnode/%s/%s' % ('n-'+str(nodeid), str(topic_id)), delay=5))
                 #notifications
                 mentions = findall_mentions(t_obj['content'], author)
                 if mentions:
                     tqueue.add(Task('/task/mentions/'+topic_key, 'member='+','.join(mentions), delay=8))
                 
                 #set for check spam
                 #u_topic_time = kv.get('u_topic_time:'+author)
                 if u_topic_time:
                     tlist = u_topic_time.split(',')
                     if str(int_time) not in tlist:
                         tlist.insert(0, str(int_time))
                         u_topic_time = ','.join(tlist[:MEMBER_RECENT_TOPIC])
                         kv.set('u_topic_time:'+author, u_topic_time)
                 else:
                     u_topic_time = str(int_time)
                     kv.set('u_topic_time:'+author, u_topic_time)
                 
                 
                 ##set new sr_code
                 cur_user = self.cur_user()
                 code_list = [cur_user['code'],u_topic_time]
                 u_comment_time = kv.get('u_comment_time:'+author)
                 if u_comment_time:
                     code_list.append(u_comment_time)
                 self.set_cookie('usercode', md5(''.join(code_list)).hexdigest(), path="/", expires_days = 365 )
                 
                 
                 #del cache
                 clear_cache_multi(['get_topic_by_keys:recent-topic-home','get_topic_by_keys:topic-' + author, 'get_comment_topic_by_keys:recent-topic-home', 'get_comment_topic_by_keys:recent-comment-topic-home','cur_user:'******'/'+topic_key)
                 return
             else:
                 errors.append("服务器出现错误,请稍后再试")
         else:
             t_obj['title'] = title
             t_obj['content'] = content
             errors.append(u"注意标题和内容的最大字数:%s %d" % (len(title), len(content)))
     else:
         errors.append("标题和内容必填")
     self.echo('newpost.html', {
         'title': "发新帖子",
         'errors':errors,
         'n_obj': n_obj,
         't_obj': t_obj,
     }, layout='_layout.html')