Esempio n. 1
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...'
         })
Esempio n. 2
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')
Esempio n. 3
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...'
             })
Esempio n. 4
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')
Esempio n. 5
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 失败,请返回再试')
Esempio n. 6
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 失败,请返回再试')