예제 #1
0
파일: post.py 프로젝트: susnmos/torweb
    def post(self, *args, **kwargs):
        post_data = get_cleaned_post_data(self, ['post', 'title', 'content', 'topic'])
        try:
            post = Post.get(Post.id == post_data['post'], Post.is_delete == False)
        except Post.DoesNotExist:
            self.write(json_result(1, '请选择正确主题'))
            return

        if not post.check_auth(self.current_user):
            self.redirect404_json()
            return

        try:
            topic = PostTopic.get(PostTopic.str == post_data['topic'])
        except PostTopic.DoesNotExist:
            self.write(json_result(1, '请选择正确主题'))
            return

        post.topic = topic
        post.title = post_data['title']
        post.content = post_data['content']
        post.save()

        # 添加通知, 通知给其他关注的用户
        Notification.new_post(post)
        self.write(json_result(0, {'post_id': post.id}))
예제 #2
0
 def post(self, *args, **kwargs):
     post_data = get_cleaned_post_data(self, ['username', 'password'])
     user = User.auth(post_data['username'], post_data['password'])
     if user:
         self.set_secure_cookie('uuid', user.username)
         result = json_result(0, 'login success!')
     else:
         result = json_result(-1, 'login failed!')
     self.write(result)
예제 #3
0
파일: index.py 프로젝트: jmpews/torweb
 def post(self, *args, **kwargs):
     post_data = get_cleaned_post_data(self, ['username', 'password'])
     user = User.auth(post_data['username'], post_data['password'])
     if user:
         # self.set_secure_cookie('uuid', user.username)
         self.set_current_user(user.username)
         result = json_result(0, 'login success!')
     else:
         result = json_result(-1, MSG.str('login_password_error'))
     self.write(result)
예제 #4
0
 def post(self, *args, **kwargs):
     post_data = get_cleaned_post_data(self, ['username', 'password'])
     user = User.auth(post_data['username'], post_data['password'])
     if user:
         # self.set_secure_cookie('uuid', user.username)
         self.set_current_user(user.username)
         result = json_result(0, 'login success!')
     else:
         result = json_result(-1, MSG.str('login_password_error'))
     self.write(result)
예제 #5
0
 def post(self, *args, **kwargs):
     post_data = get_cleaned_post_data(self, ['username', 'password'])
     user = User.auth(post_data['username'], post_data['password'])
     if user:
         self.set_secure_cookie('uuid', user.username)
         self.set_secure_cookie('isteacher', str(user.level))
         # print('set user level'+str(user.level)+ str(type(user.level)) )
         result = json_result(0, 'login success!')
     else:
         result = json_result(-1, '用户名密码错误...')
     self.write(result)
예제 #6
0
    def on_message(self, message):
        json_data = get_cleaned_json_data_websocket(message, ['opt', 'data'])
        data = json_data['data']
        opt = json_data['opt']

        if opt == 'update_recent_user_list':
            current_user_list = ChatMessage.get_recent_user_list(
                self.current_user)
            current_user_list['code'] = 'update_recent_user_list'
            self.write_message(json_result(0, current_user_list))

        elif opt == 'update_recent_user_list_and_open':
            current_user_list = ChatMessage.get_recent_user_list(
                self.current_user)
            current_user_list['code'] = 'update_recent_user_list_and_open'
            self.write_message(json_result(0, current_user_list))

        elif opt == 'send_message':
            other_id = data['user_id']
            other = User.get(User.id == other_id)
            content = data['content']
            cl = ChatMessage.create(sender=self.current_user,
                                    receiver=other,
                                    content=content)
            other_websocket = WebsocketChatHandler.is_online(other.username)
            self.write_message(
                json_result(
                    0, {
                        'code': 'receive_message',
                        'other_id': other.id,
                        'msg':
                        ['>', cl.content,
                         TimeUtil.datetime_delta(cl.time)]
                    }))

            other_websocket.write_message(
                json_result(
                    0, {
                        'code': 'receive_message',
                        'other_id': self.current_user.id,
                        'msg':
                        ['<', cl.content,
                         TimeUtil.datetime_delta(cl.time)]
                    }))
        elif opt == 'recent_chat_message':
            other_id = data['user_id']
            other = User.get(User.id == other_id)

            recent_message = ChatMessage.get_recent_chat_message(
                self.current_user, other)
            recent_message['code'] = 'recent_chat_message'
            self.write_message(json_result(0, recent_message))
예제 #7
0
파일: index.py 프로젝트: jmpews/torweb
    def post(self, *args, **kwargs):
        post_data = get_cleaned_post_data(self, ['username', 'email', 'password'])
        if User.get_by_username(username=post_data['username']):
            self.write(json_result(1, MSG.str('register_same_name')))
            return

        if User.get_by_email(email=post_data['email']):
            self.write(json_result(1, MSG.str('register_same_email')))
            return

        user = User.new(username=post_data['username'],
                 email=post_data['email'],
                 password=post_data['password'])
        self.write(json_result(0,{'username': user.username}))
예제 #8
0
파일: post.py 프로젝트: niuzehai/torweb
 def post(self, *args, **kwargs):
     post_data = get_cleaned_post_data(self, ['title', 'content', 'topic'])
     try:
         topic = PostTopic.get(PostTopic.str == post_data['topic'])
     except PostTopic.DoesNotExist:
         self.write(json_result(1, '请选择正确主题'))
         return
     post = Post.create(topic=topic,
                        title=post_data['title'],
                        content=post_data['content'],
                        user=self.current_user)
     #添加通知, 通知给其他关注的用户
     Notification.new_post(post)
     self.write(json_result(0, {'post_id': post.id}))
예제 #9
0
파일: post.py 프로젝트: susnmos/torweb
 def post(self, *args, **kwargs):
     post_data = get_cleaned_post_data(self, ['post', 'content'])
     try:
         post = Post.get(Post.id == post_data['post'], Post.is_delete == False)
     except PostTopic.DoesNotExist:
         self.write(json_result(1, '请选择正确post'))
         return
     postreply = PostReply.create(
         post=post,
         user=self.current_user,
         content=post_data['content'],
     )
     post.update_latest_reply(postreply)
     Notification.new_reply(postreply, post)
     self.write(json_result(0, {'post_id': post.id}))
예제 #10
0
    def post(self, *args, **kwargs):
        post_data = get_cleaned_post_data(self,
                                          ['username', 'email', 'password'])
        if User.get_by_username(username=post_data['username']):
            self.write(json_result(1, '用户名经存在'))
            return

        if User.get_by_email(email=post_data['email']):
            self.write(json_result(1, '邮箱已经存在'))
            return

        user = User.new(username=post_data['username'],
                        email=post_data['email'],
                        password=post_data['password'])
        self.write(json_result(0, {'username': user.username}))
예제 #11
0
파일: user.py 프로젝트: jmpews/torweb
 def post(self, *args, **kwargs):
     post_data = get_cleaned_post_data(self, ['weibo',])
     user = self.current_user
     profile = Profile.get_by_user(user)
     profile.weibo = post_data['weibo']
     profile.save()
     self.write(json_result(0, {'user': user.username}))
예제 #12
0
 def wrapper(self, *args, **kwargs):
     captcha_cookie = self.get_cookie('captcha', '')
     captcha = get_cleaned_post_data(self, ['captcha'],
                                     blank=True)['captcha']
     if not captcha or captcha != captcha_cookie:
         self.write(json_result(errorcode, result))
         return
     return method(self, *args, **kwargs)
예제 #13
0
파일: post.py 프로젝트: TheRittler/torweb
 def post(self, *args, **kwargs):
     json_data = get_cleaned_json_data(self, ['opt', 'data'])
     data = json_data['data']
     opt = json_data['opt']
     # 支持某个回复
     if opt == 'support-postreply':
         try:
             postreply = PostReply.get(PostReply.id == data['postreply'])
         except:
             self.write(json_result(1, '请输入正确的回复'))
             return
         postreply.up_like()
         self.write(json_result(0, 'success'))
     # 收藏该主题
     elif opt == 'collect-post':
         try:
             post = Post.get(Post.id == data['post'])
         except:
             self.write(json_result(1, '请输入正确的Post'))
             return
         CollectPost.create(post=post, user=self.current_user)
         self.write(json_result(0, 'success'))
     # 取消收藏该主题
     elif opt == 'cancle-collect-post':
         try:
             post = Post.get(Post.id == data['post'])
         except:
             self.write(json_result(1, 'CollectPost不正确'))
             return
         collectpost = CollectPost.get(post=post, user=self.current_user)
         collectpost.delete_instance()
         self.write(json_result(0, 'success'))
     else:
         self.write(json_result(1, 'opt不支持'))
예제 #14
0
 def success(self, data, errorcode=0):
     """
     成功返回
     :param data:
     :param errorcode:
     :return:
     """
     self.write(json_result(errorcode, data))
     self.finish()
예제 #15
0
 def error(self, data, errorcode=-1):
     """
     失败返回
     :param data:
     :param errorcode:
     :return:
     """
     self.write(json_result(errorcode, data))
     self.finish()
예제 #16
0
파일: utils.py 프로젝트: jmpews/torweb
 def post(self, *args, **kwargs):
     img_name = str(uuid.uuid1())
     # import pdb;pdb.set_trace()
     file = self.request.files['imageFile'][0]
     img_name += file['filename']
     img_file = open(config.common_upload_path + img_name, 'wb')
     img_file.write(file['body'])
     print('Upload-File: '+img_name)
     self.write(json_result(0, {'image': img_name}))
예제 #17
0
    def write_error(self, status_code, **kwargs):
        """
        默认错误处理函数
        :param status_code:
        :param kwargs:
        :return:
        """
        if 'exc_info' in kwargs:
            # 参数缺失异常
            if isinstance(kwargs['exc_info'][1], RequestMissArgumentError):
                self.write(json_result(kwargs['exc_info'][1].code, kwargs['exc_info'][1].msg))
                return

        if status_code == 400:
            self.write(json_result(400, '缺少参数'))
            return
        if not config.DEBUG:
            self.redirect("/static/500.html")
예제 #18
0
파일: api.py 프로젝트: susnmos/torweb
 def get(self, *args, **kwargs):
     self.write(
         json_result(
             0, {
                 'cpu_per': system_status_cache[0],
                 'ram_per': system_status_cache[1],
                 'net_conn': system_status_cache[2],
                 'os_start': system_status_cache[3]
             }))
예제 #19
0
 def post(self, *args, **kwargs):
     img_name = str(uuid.uuid1())
     # import pdb;pdb.set_trace()
     file = self.request.files['imageFile'][0]
     img_name += file['filename']
     img_file = open(config.common_upload_path + img_name, 'wb')
     img_file.write(file['body'])
     print('Upload-File: ' + img_name)
     self.write(json_result(0, {'image': img_name}))
예제 #20
0
 def success(self, data, errorcode=0):
     """
     成功返回
     :param data:
     :param errorcode:
     :return:
     """
     self.write(json_result(errorcode, data))
     self.finish()
예제 #21
0
 def error(self, data, errorcode=-1):
     """
     失败返回
     :param data:
     :param errorcode:
     :return:
     """
     self.write(json_result(errorcode, data))
     self.finish()
예제 #22
0
 def post(self, *args, **kwargs):
     post_data = get_cleaned_post_data(self, [
         'weibo',
     ])
     user = self.current_user
     profile = Profile.get_by_user(user)
     profile.weibo = post_data['weibo']
     profile.save()
     self.write(json_result(0, {'user': user.username}))
예제 #23
0
파일: api.py 프로젝트: susnmos/torweb
 def write2(client, system_status_cache):
     client.write_message(
         json_result(
             0, {
                 'cpu_per': system_status_cache[0],
                 'ram_per': system_status_cache[1],
                 'net_conn': system_status_cache[2],
                 'os_start': system_status_cache[3]
             }))
예제 #24
0
    def write_error(self, status_code, **kwargs):
        """
        默认错误处理函数
        :param status_code:
        :param kwargs:
        :return:
        """
        if 'exc_info' in kwargs:
            # 参数缺失异常
            if isinstance(kwargs['exc_info'][1], RequestMissArgumentError):
                self.write(
                    json_result(kwargs['exc_info'][1].code,
                                kwargs['exc_info'][1].msg))
                return

        if status_code == 400:
            self.write(json_result(400, '缺少参数'))
            return
        if not config.DEBUG:
            self.redirect("/static/500.html")
예제 #25
0
파일: user.py 프로젝트: jmpews/torweb
    def on_message(self, message):
        json_data = get_cleaned_json_data_websocket(message, ['opt', 'data'])
        data = json_data['data']
        opt = json_data['opt']

        if opt == 'update_recent_user_list':
            logger.debug('update_recent_user_list...')
            recent_user_list = ChatMessage.get_recent_user_list(self.current_user)
            self.write_message(json_result(0,{'code': 'recent_user_list', 'data': recent_user_list}))

        elif opt == 'update_recent_user_list_and_open':
            recent_user_list = ChatMessage.get_recent_user_list(self.current_user)
            self.write_message(json_result(0,recent_user_list))

        elif opt == 'send_message':
            other_id = data['user_id']
            other = User.get(User.id == other_id)
            content = data['content']
            cl = ChatMessage.create(sender=self.current_user, receiver=other, content=content)
            self.write_message(json_result(0, {'code': 'receive_a_message',
                                               'data': {
                                                    'id': other.id,
                                                    'name': other.username,
                                                    'avatar': other.avatar,
                                                    'msg': ['>', cl.content, TimeUtil.datetime_delta(cl.time)]}}))

            # send to other user
            other_websocket = WebsocketChatHandler.is_online(other.username)
            if other_websocket:
                other_websocket.write_message(json_result(0, {'code': 'receive_a_message',
                                                              'data': {
                                                                'id': self.current_user.id,
                                                                'avatar': self.current_user.avatar,
                                                                'name': self.current_user.username,
                                                                'msg': ['<', cl.content, TimeUtil.datetime_delta(cl.time)]}}))
        elif opt == 'update_recent_message_list':
            other_id = data['user_id']
            other = User.get(User.id == other_id)
            recent_message = ChatMessage.get_recent_chat_message(self.current_user, other)
            logger.debug(recent_message)
            self.write_message(json_result(0,{'code': 'recent_message_list', 'data':recent_message}))
예제 #26
0
파일: api.py 프로젝트: jmpews/torweb
 def write2all(cls, system_status_cache):
     """
     推送给所有用户
     :param system_status_cache:
     :return:
     """
     for client in cls.clients:
         client.write_message(json_result(0, {
         'cpu_per': system_status_cache[0],
         'ram_per': system_status_cache[1],
         'net_conn': system_status_cache[2],
         'os_start': system_status_cache[3]}))
예제 #27
0
파일: dashboard.py 프로젝트: susnmos/torweb
    def post(self, *args, **kwargs):
        json_data = get_cleaned_json_data(self, ['opt', 'data'])
        data = json_data['data']
        opt = json_data['opt']

        # 关注用户
        if opt == 'get-post-list':
            data = []
            posts = Post.select()
            for p in posts:
                tp = obj2dict(p, ['id', 'title'])
                data.append(tp)
            self.write(json_result(0, data))
예제 #28
0
파일: dashboard.py 프로젝트: jmpews/torweb
    def post(self, *args, **kwargs):
        json_data = get_cleaned_json_data(self, ['opt', 'data'])
        data = json_data['data']
        opt = json_data['opt']

        # 关注用户
        if opt == 'get-post-list':
            data = []
            posts = Post.select()
            for p in posts:
                tp = obj2dict(p, ['id', 'title'])
                data.append(tp)
            self.write(json_result(0, data))
예제 #29
0
 def post(self, *args, **kwargs):
     json_data = get_cleaned_json_data(self, ['opt', 'data'])
     data = json_data['data']
     opt = json_data['opt']
     # 关注用户
     if opt == 'follow-user':
         try:
             user = User.get(User.id == data['user'])
         except:
             self.write(json_result(1, '没有该用户'))
             return
         Follower.create(user=user, follower=self.current_user)
         self.write(json_result(0, 'success'))
     # 取关用户
     elif opt == 'unfollow-user':
         try:
             user = User.get(User.id == data['user'])
         except:
             self.write(json_result(1, '没有该用户'))
             return
         try:
             f = Follower.get(Follower.user == user,
                              Follower.follower == self.current_user)
         except:
             self.write(json_result(1, '还没有关注他'))
             return
         f.delete_instance()
         self.write(json_result(0, 'success'))
     # 更新头像
     elif opt == 'update-avatar':
         import base64
         avatar = base64.b64decode(data['avatar'])
         user = self.current_user
         avatar_file_name = user.username + '.png'
         avatar_file = open(config.avatar_upload_path + avatar_file_name,
                            'wb')
         avatar_file.write(avatar)
         user.avatar = avatar_file_name
         user.save()
         self.write(json_result(0, 'success'))
     # 更新社区主题
     elif opt == 'update-theme':
         user = self.current_user
         user.theme = data['theme']
         user.save()
         self.write(json_result(0, 'success'))
     else:
         self.write(json_result(1, 'opt不支持'))
예제 #30
0
파일: api.py 프로젝트: susnmos/torweb
 def write2all(cls, system_status_cache):
     """
     推送给所有用户
     :param system_status_cache:
     :return:
     """
     for client in cls.clients:
         client.write_message(
             json_result(
                 0, {
                     'cpu_per': system_status_cache[0],
                     'ram_per': system_status_cache[1],
                     'net_conn': system_status_cache[2],
                     'os_start': system_status_cache[3]
                 }))
예제 #31
0
파일: blog.py 프로젝트: susnmos/torweb
 def post(self, *args, **kwargs):
     json_data = get_cleaned_json_data(self, ['opt', 'data'])
     data = json_data['data']
     opt = json_data['opt']
     # 获取文章详情
     if opt == 'get-post':
         try:
             post = BlogPost.get(BlogPost.id == int(data['post']),
                                 BlogPost.is_del == False)
         except:
             self.write(json_result(1, '不存在该post'))
             return
         else:
             self.write(
                 json_result(
                     0, {
                         'title': post.title,
                         'content': post.content,
                         'labels': BlogPostLabel.get_post_label(post),
                         'category': post.category.name
                     }))
             return
     # 更新文章
     elif opt == 'update-post':
         try:
             post = BlogPost.get(BlogPost.id == int(data['post']),
                                 BlogPost.is_del == False)
         except:
             self.write(json_result(1, '不存在该post'))
             return
         else:
             cate = BlogPostCategory.get_by_name(data['category'])
             post.category = cate
             post.title = data['title']
             post.content = data['content']
             post.save()
             BlogPostLabel.update_post_label(data['labels'], post)
             self.write(json_result(0, 'success'))
             return
     # 创建文章
     elif opt == 'create-post':
         cate = BlogPostCategory.get_by_name(data['category'])
         post = BlogPost.create(title=data['title'],
                                category=cate,
                                content=data['content'])
         BlogPostLabel.add_post_label(data['labels'], post)
         self.write(json_result(0, 'success'))
         return
     else:
         self.write(json_result(1, 'opt不支持'))
예제 #32
0
파일: blog.py 프로젝트: jmpews/torweb
 def post(self, *args, **kwargs):
     json_data = get_cleaned_json_data(self, ['opt', 'data'])
     data = json_data['data']
     opt = json_data['opt']
     # 获取文章详情
     if opt == 'get-post':
         try:
             post = BlogPost.get(BlogPost.id == int(data['post']), BlogPost.is_del == False)
         except:
             self.write(json_result(1, '不存在该post'))
             return
         else:
             self.write(json_result(0, {'title': post.title,
                            'content': post.content,
                            'labels': BlogPostLabel.get_post_label(post),
                            'category': post.category.name}))
             return
     # 更新文章
     elif opt == 'update-post':
         try:
             post = BlogPost.get(BlogPost.id == int(data['post']), BlogPost.is_del == False)
         except:
             self.write(json_result(1, '不存在该post'))
             return
         else:
             cate = BlogPostCategory.get_by_name(data['category'])
             post.category = cate
             post.title = data['title']
             post.content = data['content']
             post.save()
             BlogPostLabel.update_post_label(data['labels'], post)
             self.write(json_result(0, 'success'))
             return
     # 创建文章
     elif opt == 'create-post':
         cate = BlogPostCategory.get_by_name(data['category'])
         post = BlogPost.create(title=data['title'],
                                category=cate,
                                content=data['content'])
         BlogPostLabel.add_post_label(data['labels'], post)
         self.write(json_result(0, 'success'))
         return
     else:
         self.write(json_result(1, 'opt不支持'))
예제 #33
0
 def wrapper(self, *args, **kwargs):
     if not self.current_user:
         self.write(json_result(errorcode, result))
         return
     return method(self, *args, **kwargs)
예제 #34
0
파일: api.py 프로젝트: jmpews/torweb
 def get(self, *args, **kwargs):
     self.write(json_result(0, {
         'cpu_per': system_status_cache[0],
         'ram_per': system_status_cache[1],
         'net_conn': system_status_cache[2],
         'os_start': system_status_cache[3]}))
예제 #35
0
파일: api.py 프로젝트: jmpews/torweb
 def get(self, *args, **kwargs):
     self.write(json_result(0, {'url': '.'}))
예제 #36
0
파일: api.py 프로젝트: jmpews/torweb
 def write2(client, system_status_cache):
     client.write_message(json_result(0, {
         'cpu_per': system_status_cache[0],
         'ram_per': system_status_cache[1],
         'net_conn': system_status_cache[2],
         'os_start': system_status_cache[3]}))
예제 #37
0
    def on_message(self, message):
        json_data = get_cleaned_json_data_websocket(message, ['opt', 'data'])
        data = json_data['data']
        opt = json_data['opt']

        if opt == 'update_recent_user_list':
            logger.debug('update_recent_user_list...')
            recent_user_list = ChatMessage.get_recent_user_list(
                self.current_user)
            self.write_message(
                json_result(0, {
                    'code': 'recent_user_list',
                    'data': recent_user_list
                }))

        elif opt == 'update_recent_user_list_and_open':
            recent_user_list = ChatMessage.get_recent_user_list(
                self.current_user)
            self.write_message(json_result(0, recent_user_list))

        elif opt == 'send_message':
            other_id = data['user_id']
            other = User.get(User.id == other_id)
            content = data['content']
            cl = ChatMessage.create(sender=self.current_user,
                                    receiver=other,
                                    content=content)
            self.write_message(
                json_result(
                    0, {
                        'code': 'receive_a_message',
                        'data': {
                            'id':
                            other.id,
                            'name':
                            other.username,
                            'avatar':
                            other.avatar,
                            'msg': [
                                '>', cl.content,
                                TimeUtil.datetime_delta(cl.time)
                            ]
                        }
                    }))

            # send to other user
            other_websocket = WebsocketChatHandler.is_online(other.username)
            if other_websocket:
                other_websocket.write_message(
                    json_result(
                        0, {
                            'code': 'receive_a_message',
                            'data': {
                                'id':
                                self.current_user.id,
                                'avatar':
                                self.current_user.avatar,
                                'name':
                                self.current_user.username,
                                'msg': [
                                    '<', cl.content,
                                    TimeUtil.datetime_delta(cl.time)
                                ]
                            }
                        }))
        elif opt == 'update_recent_message_list':
            other_id = data['user_id']
            other = User.get(User.id == other_id)
            recent_message = ChatMessage.get_recent_chat_message(
                self.current_user, other)
            logger.debug(recent_message)
            self.write_message(
                json_result(0, {
                    'code': 'recent_message_list',
                    'data': recent_message
                }))
예제 #38
0
 def redirect404_json(self):
     self.write(json_result(-1, '数据提交错误'))
예제 #39
0
파일: api.py 프로젝트: susnmos/torweb
 def get(self, *args, **kwargs):
     self.write(json_result(0, {'url': '.'}))
예제 #40
0
파일: user.py 프로젝트: jmpews/torweb
    def post(self, *args, **kwargs):
        json_data = get_cleaned_json_data(self, ['opt', 'data'])
        data = json_data['data']
        opt = json_data['opt']

        # 关注用户
        if opt == 'follow-user':
            try:
                user = User.get(User.id == data['user'])
            except:
                self.write(json_result(1, '没有该用户'))
                return
            Follower.create(user=user, follower=self.current_user)
            self.write(json_result(0, 'success'))

        # 取关用户
        elif opt == 'unfollow-user':
            try:
                user = User.get(User.id == data['user'])
            except:
                self.write(json_result(1, '没有该用户'))
                return
            try:
                f = Follower.get(Follower.user == user, Follower.follower == self.current_user)
            except:
                self.write(json_result(1, '还没有关注他'))
                return
            f.delete_instance()
            self.write(json_result(0, 'success'))

        # 更新头像
        elif opt == 'update-avatar':
            import base64
            avatar = base64.b64decode(data['avatar'])
            user = self.current_user
            avatar_file_name = user.username + '.png'
            avatar_file = open(config.avatar_upload_path + avatar_file_name, 'wb')
            avatar_file.write(avatar)
            user.avatar = avatar_file_name
            user.save()
            self.write(json_result(0, 'success'))

        # 更新社区主题
        elif opt == 'update-theme':
            user = self.current_user
            user.theme = data['theme']
            user.save()
            self.write(json_result(0, 'success'))

        # 获取聊天记录
        elif opt == 'realtime-chat':
            user = self.current_user
            other_id = data['other']
            other = User.get(User.id == other_id)
            result = ChatMessage.get_recent_chat_message(user, other)
            self.write(json_result(0, result))

        # 发送消息
        elif opt == 'chat-to' :
            user = self.current_user
            other_id = data['other']
            other = User.get(User.id == other_id)
            content = data['content']
            ChatMessage.create(me=user, other=other, content=content)
            self.write(json_result(0, 'success'))
        else:
            self.write(json_result(1, 'opt不支持'))
예제 #41
0
 def redirect404_json(self):
     self.write(json_result(-1, '数据提交错误'))