Esempio n. 1
0
    def get(self):
        data = self.get_data()

        if data['pw1'] != data['pw2']:
            self.send_faild('PW_NOT_SAME')
            return

        if data['invite_token'] == '':
            self.send_faild('NO_TOKEN')
            return
        # 需要传入邀请者token作为参数

        res = Data.find('user', [('user_name', '=', data['username'])])
        if res != None:
            self.send_faild('ACCOUNT_HAD')
            return

        inviter = Data.find('user', [('token', '=', data['invite_token'])])
        if inviter == None:
            self.send_faild('NO_TOKEN')
            return

        params = {
            'user_name': data['username'],
            'passwd': common.get_md5(data['pw2']),
            'join_time': int(time.time()),
            'uuid': self.create_uuid(),
            'invite_id': inviter['id'],
            'nickname': json.dumps(data['nickname'])
        }

        Data.insert('user', params)
        Data.update('user', [('id', '=', inviter['id'])], {'token': ''})
        # 插入新的数据,为了安全,更新一次token

        conditions = [('user_name', '=', data['username']),
                      ('passwd', '=', common.get_md5(data['pw2']))]

        res = Data.find('user', conditions)
        token = self.get_token(res)

        result = {'token': token}

        Data.update('user', conditions, result)
        # 插入token

        self.send_ok(result)
        return
    def get_user_base(self):
        '''
        获取用户基本信息
        :return:
        '''
        token = self.get_argument('token')
        print(token)
        conditions = []
        conditions.append(('token', '=', token))

        user_data = Data.find(Data.USER, conditions)

        return user_data
Esempio n. 3
0
    def get_user_base(self):
        '''
        获取用户基本信息
        :return:
        '''
        token = self.get_argument('token')
        # print(token)
        conditions = []
        if token == '':
            # 如果不存在token
            return None

        conditions.append(('token', '=', token))

        user_data = Data.find('user', conditions)

        return user_data
Esempio n. 4
0
    def get(self):
        data = self.get_data()
        pw_md5 = common.get_md5(data['pw'])
        condition = [('user_name', '=', data['username']),
                     ('passwd', '=', pw_md5)]

        res = Data.find('user', condition)
        if res == None:
            self.send_faild('LOGIN_PSW_ERROR')
            return
        else:
            token = self.get_token(res)
            result = {'token': token}
            Data.update('user', condition, result)

            self.send_ok(result)
            return
Esempio n. 5
0
    def post(self):
        data = self.get_post_data()
        user_base = self.get_user_base()

        content = json.dumps(data['content'])
        # content = content.replace('\\','\\\\') # 不确定是否需要
        content_md5 = common.get_md5(content)

        user_id = user_base['id']
        ctime = int(time.time())
        event_time = common.str_to_time(data['event_time'] + ' 00:00:00')
        title = data['title']

        # Data.find('case_info',[('content_md5','=',content_md5)])

        params = {
            'user_id': user_id,
            'ctime': ctime,
            'content': content,
            'content_md5': content_md5,
            'event_time': event_time,
            'title': title,
        }

        Data.insert('case_info', params)
        # self.write_event_post_item()

        cond = [('user_id', '=', user_id), ('ctime', '=', ctime),
                ('content_md5', '=', content_md5)]

        res = Data.find('case_info', cond)
        self.split_case_info(res)
        # 创建关键词索引

        # self.write_event_post_item(data,res)

        if res != None:
            self.send_ok({})
            self.write_event_post_item(data, res)
            print('download_done!')
            return
        else:
            self.send_faild({'INSERT_FAIL'})
            return
Esempio n. 6
0
    def update(self,table,conditions,params):
        if table in self.data_all:
            table_content = self.data_all[table]

            table_id_list = []
            tmp = []
            if conditions == []:
                for line in table_content:
                    table_id_list.append(line['id'])
                    tmp.append(line)

            else:
                for line in table_content:
                    if judge(line,conditions) == True:
                        table_id_list.append(line['id'])
                        tmp.append(line)

            Data.update(table,conditions,params)

            for line in tmp:
                self.data_all[table].remove(line)

            for i in table_id_list:
                res = Data.find(table,[('id','=',i)])
                for line in table_content:
                    if line['id'] > res['id']:
                        line_index = table_content.index(line)
                        if line_index == 0:
                            tail = [res]+table_content
                        else:
                            tail = table_content[:line_index] + [res] + table_content[line_index:]
                        break
                table_content = tail

            self.data_all[table] = table_content


        else:
            Data.update(table,conditions,params)
            self.data_all[table] = Data.select(table,[])

        return
Esempio n. 7
0
    def get(self):
        data = self.get_data()
        keyword_list = data['keyword_list']

        if keyword_list == []:
            self.send_faild('NEED_WORD')
            return

        case_id_list = []

        for keyword in keyword_list:
            keyword_md5 = common.get_md5(keyword)
            res = Data.select('case_search_index',
                              [('keyword_md5', '=', keyword_md5)])
            if res == None:
                continue
            else:
                for case in res:
                    case_id_list.append(case['case_id'])
                continue

        case_id_list = list(set(case_id_list))
        print(case_id_list)

        title_list = []

        for case_id in case_id_list:
            res = Data.find('case_info', [('id', '=', case_id)])
            if res == None:
                continue
            else:
                case_info = {'case_id': res['id'], 'title': res['title']}
                title_list.append(case_info)
                continue

        result = {'keyword_list': keyword_list, 'result': title_list}
        # 关键词搜索

        self.send_ok(result)
        return
    def get(self):
        data = self.get_data()
        case_id = data['case_id']
        line = Data.find('case_info', [('id', '=', case_id),
                                       ('is_show', '=', 1)])
        if line == None:
            self.send_faild('NO_RECORD')
            return

        info_line = {
            'case_id': line['id'],
            'content': json.loads(line['content']),
            'ctime': common.time_to_str(line['ctime']).split()[0],
            'title': line['title'],
            'uploader_info': self.get_uploader_info(line['user_id']),
            'post_items': self.get_post_items(line['id']),
        }

        result = info_line

        # print(result)

        self.send_ok(result)
        return
Esempio n. 9
0
 def get(self):
     res = Data.find('test', [('id', '!=', 0)])
     self.send_ok(res)
Esempio n. 10
0
 def get_uploader_info(self, user_id):
     # 获取上传者信息
     res = Data.find('user', [('id', '=', user_id)])
     result = {'nickname': json.loads(res['nickname']), 'uuid': res['uuid']}
     return result