Exemple #1
0
    def post(self):
        self.set_header("Content-Type", "application/json")
        act = self.get_argument("act", '')
        folk_id = self.get_argument("id", '')

        folk_name = self.get_argument("folk_name", '')
        relation = self.get_argument("relation", '')
        birthday = self.get_argument("birthday", 0)

        if folk_id or folk_name or relation or birthday:
            user_id = self.get_secure_cookie("user_id")
            if act == 'add':
                Folk.create_folk(user_id, folk_name, relation, birthday)

            if act == 'edit':
                params = {'user_id': user_id, 'folk_id': folk_id, 'folk_name': folk_name, 'relation': relation, 'birthday': birthday}
                Folk.update_folk(params)

            if act == 'del':
                Folk.delete_folk(user_id, folk_id)

            clear_cache_by_pathlist(['/'])
            self.write(json.dumps("OK"))
        else:
            self.write(json.dumps("参数异常"))
Exemple #2
0
    def post(self):
        try:
            tf = {'true': 1, 'false': 0}
            act = self.get_argument("act", '').encode('utf-8')
            user_id = self.get_argument("user_id", '').encode('utf-8')
            user_name = self.get_argument("user_name", '').encode('utf-8')
            email = self.get_argument("email", '').encode('utf-8')
            status = tf[self.get_argument("status", 'false').encode('utf-8')]
        except:
            self.write(json.dumps("用户名、邮箱均为必填项!"))
            return

        params = {'user_id': user_id, 'user_name': user_name, 'email': email, 'password': None, 'status': status}
        if act == 'add' and user_name is not None and email is not None:
            password = Users.create(params)
            # sub = {
            #     "%website%": [getAttr("SITE_TITLE").encode('utf-8')],
            #     "%url%": [getAttr("BASE_URL")],
            #     "%name%": [user_name],
            #     "%password%": [password]
            # }
            # sendTemplateEmail(u"密码重置通知 - " + getAttr('SITE_TITLE'), sub, str(email))
            sendEmail(u"密码重置通知 - " + getAttr('SITE_TITLE'), u"您的新密码是:" + password + u"<br /><br />请及时登录并修改密码!",
                      str(email))
        elif act == 'edit' and user_id is not None:
            Users.update(params)

        clear_cache_by_pathlist(['/'])

        self.set_header("Content-Type", "application/json")
        self.write(json.dumps("OK"))
Exemple #3
0
    def get(self):
        act = self.get_argument("act", '')
        id = self.get_argument("id", '')

        obj = None
        if act == 'del':
            if id:
                Type.delete_type(id)
                clear_cache_by_pathlist(['/'])
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
            return
        elif act == 'edit':
            if id:
                obj = Type.get_type(id)
                clear_cache_by_pathlist(['/'])

        # 类型列表
        type_list = Type.get_all()
        total = math.ceil(Type.count_all() / float(getAttr('ADMIN_TYPE_NUM')))
        self.echo('admin_report.html', {
                'title': "数据报表",
                'objs': type_list,
                'obj': obj,
                'total': total,
        }, layout='_layout_admin.html')
Exemple #4
0
    def post(self):
        act = self.get_argument("act", '')
        id = self.get_argument("id", '')

        type_name = self.get_argument("type_name", '')
        type_type = self.get_argument("type_type", '')
        type_order = self.get_argument("type_order", 0)

        if id or type_name or type_type or type_order:
            if act == 'add':
                Type.create_type(type_name, type_type, type_order)

            if act == 'edit':
                params = {'type_id': id, 'type_name': type_name, 'type_type': type_type, 'type_order': type_order}
                Type.update_type(params)

            if act == 'del':
                Type.delete_type(id)

            clear_cache_by_pathlist(['/'])

            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
        else:
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("参数异常"))
Exemple #5
0
    def post(self):
        act = self.get_argument("act", '')
        if act == 'findid':
            eid = self.get_argument("id", '')
            self.redirect('%s/admin/comment/%s' % (BASE_URL, eid))
            return

        tf = {'true': 1, 'false': 0}
        post_dic = {
            'author':
            self.get_argument("author"),
            'email':
            self.get_argument("email", ''),
            'content':
            safe_encode(self.get_argument("content").replace('\r', '\n')),
            'url':
            self.get_argument("url", ''),
            'visible':
            self.get_argument("visible", 'false'),
            'id':
            id
        }
        post_dic['visible'] = tf[post_dic['visible'].lower()]

        Comments.update(post_dic)
        clear_cache_by_pathlist(['post:%s' % id])
        self.redirect('%s/admin/comment/%s' % (BASE_URL, id))
        return
Exemple #6
0
    def post(self):
        try:
            tf = {'true': 1, 'false': 0}
            act = self.get_argument("act", '').encode('utf-8')
            category_id = self.get_argument("id", '').encode('utf-8')
            father_category_id = self.get_argument("father_id", 0).encode('utf-8')
            category_name = self.get_argument("name", '').encode('utf-8')
            show_type = self.get_argument("show_type", '').encode('utf-8')
            display_order = self.get_argument("sort", '0').encode('utf-8')
            allow_comment = tf[self.get_argument("allow_comment", "false").encode('utf-8')]
            allow_publish = tf[self.get_argument("allow_publish", "false").encode('utf-8')]
            description = self.get_argument("description", '').encode('utf-8')
        except:
            self.write(json.dumps("用户名、密码、验证码均为必填项!"))
            return

        if category_name:
            params = {'category_id': category_id, 'father_category_id': father_category_id,
                      'category_name': category_name, 'show_type': show_type, 'display_order': display_order,
                      'allow_comment': allow_comment, 'allow_publish': allow_publish, 'description': description}
            if act == 'add':
                Categories.create(params)

            if act == 'edit':
                Categories.update(params)

            clear_cache_by_pathlist(['/'])

            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
        else:
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("参数异常"))
Exemple #7
0
    def post(self):
        ADMIN_CATEGORY_NUM = self.get_argument("ADMIN_CATEGORY_NUM", '')
        if ADMIN_CATEGORY_NUM:
            setAttr('ADMIN_CATEGORY_NUM', ADMIN_CATEGORY_NUM)

        ADMIN_POST_NUM = self.get_argument("ADMIN_POST_NUM", '')
        if ADMIN_POST_NUM:
            setAttr('ADMIN_POST_NUM', ADMIN_POST_NUM)

        ADMIN_COMMENT_NUM = self.get_argument("ADMIN_COMMENT_NUM", '')
        if ADMIN_COMMENT_NUM:
            setAttr('ADMIN_COMMENT_NUM', ADMIN_COMMENT_NUM)

        ADMIN_USER_NUM = self.get_argument("ADMIN_USER_NUM", '')
        if ADMIN_USER_NUM:
            setAttr('ADMIN_USER_NUM', ADMIN_USER_NUM)

        ADMIN_LINK_NUM = self.get_argument("ADMIN_LINK_NUM", '')
        if ADMIN_LINK_NUM:
            setAttr('ADMIN_LINK_NUM', ADMIN_LINK_NUM)

        clear_cache_by_pathlist(['/'])

        self.set_header("Content-Type", "application/json")
        self.write(json.dumps("OK"))
        return
Exemple #8
0
    def post(self):
        try:
            act = self.get_argument("act", '').encode('utf-8')
            link_id = self.get_argument("id", '').encode('utf-8')
            link_name = self.get_argument("name", '').encode('utf-8')
            url = self.get_argument("url", '').encode('utf-8')
            display_order = self.get_argument("sort", '0').encode('utf-8')
        except:
            self.write(json.dumps("网站名称、URL均为必填项!"))
            return

        if link_name and url:
            params = {
                'link_id': link_id,
                'link_name': link_name,
                'url': url,
                'display_order': display_order
            }
            if act == 'add':
                Links.create(params)

            if act == 'edit':
                Links.update(params)

            clear_cache_by_pathlist(['/'])

        self.set_header("Content-Type", "application/json")
        self.write(json.dumps("OK"))
Exemple #9
0
    def get(self):
        act = self.get_argument("act", '').encode('utf-8')
        user_id = self.get_argument("id", '').encode('utf-8')

        obj = None
        if act == 'add':
            obj = Users
            obj.user_id = ''
            obj.user_name = ''
            obj.email = ''
            obj.status = 1
            self.echo('admin_user_edit.html', {
                'title': "添加用户",
                'method': "/admin/users?act=add",
                'obj': obj,
            },
                      layout='_layout_admin.html')
            return
        elif act == 'edit':
            if user_id:
                obj = Users.get(user_id)
                self.echo('admin_user_edit.html', {
                    'title': "编辑用户",
                    'method': "/admin/users?act=edit",
                    'obj': obj,
                },
                          layout='_layout_admin.html')
                return
        elif act == 'del':
            if user_id:
                Users.delete(user_id)
                clear_cache_by_pathlist(['/'])
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
            return

        # 用户列表
        page = self.get_argument("page", 1)
        category = Users.get_paged(page, getAttr('ADMIN_USER_NUM'))
        total = math.ceil(Users.count_all() / float(getAttr('ADMIN_USER_NUM')))
        if page == 1:
            self.echo('admin_user_list.html', {
                'title': "用户列表",
                'objs': category,
                'obj': obj,
                'total': total,
            },
                      layout='_layout_admin.html')
        else:
            result = {
                'list': category,
                'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result, default=dthandler))
            return
Exemple #10
0
 def get(self, id=''):
     try:
         if id:
             User.delete_user(id)
             cache_key_list = ['/', 'user:%s' % id]
             clear_cache_by_pathlist(cache_key_list)
             self.set_header("Content-Type", "application/json")
             self.write(json.dumps("OK"))
             return
     except:
         raise tornado.web.HTTPError(500)
Exemple #11
0
    def get(self):
        act = self.get_argument("act", '').encode('utf-8')
        user_id = self.get_argument("id", '').encode('utf-8')

        obj = None
        if act == 'add':
            obj = Users
            obj.user_id = ''
            obj.user_name = ''
            obj.email = ''
            obj.status = 1
            self.echo('admin_user_edit.html', {
                'title': "添加用户",
                'method': "/admin/users?act=add",
                'obj': obj,
            }, layout='_layout_admin.html')
            return
        elif act == 'edit':
            if user_id:
                obj = Users.get(user_id)
                self.echo('admin_user_edit.html', {
                    'title': "编辑用户",
                    'method': "/admin/users?act=edit",
                    'obj': obj,
                }, layout='_layout_admin.html')
                return
        elif act == 'del':
            if user_id:
                Users.delete(user_id)
                clear_cache_by_pathlist(['/'])
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
            return

        # 用户列表
        page = self.get_argument("page", 1)
        category = Users.get_paged(page, getAttr('ADMIN_USER_NUM'))
        total = math.ceil(Users.count_all() / float(getAttr('ADMIN_USER_NUM')))
        if page == 1:
            self.echo('admin_user_list.html', {
                'title': "用户列表",
                'objs': category,
                'obj': obj,
                'total': total,
            }, layout='_layout_admin.html')
        else:
            result = {
                'list': category,
                'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result, default=dthandler))
            return
Exemple #12
0
    def post(self):
        rspd = {"status": 200, "msg": "OK"}
        try:
            tf = {'true': 1, 'false': 0}
            act = self.get_argument("act", '').encode('utf-8')
            post_dic = {
                'category_id':
                self.get_argument("category_id", '-').encode('utf-8'),
                'user_id':
                self.get_secure_cookie("user_id"),
                'title':
                self.get_argument("title").encode('utf-8'),
                'digest':
                '-',
                'content':
                self.get_argument("content").encode('utf-8'),
                'image_url':
                '-',
                'tags':
                ','.join(self.get_arguments("tag")),
                'allow_comment':
                tf[self.get_argument("clo", 'false')],
                'top':
                tf[self.get_argument("top", 'false')],
                'password':
                self.get_argument("password", '').encode('utf-8'),
                'salt':
                '-',
            }
        except:
            rspd['status'] = 500
            rspd['msg'] = "用户名、邮箱均为必填项!"
            self.write(json.dumps(rspd))
            return

        if act == 'add':
            Posts.create(post_dic)
        elif act == 'edit':
            post_dic['post_id'] = int(self.get_argument("post_id", ""))
            Posts.update(post_dic)

        clear_cache_by_pathlist(['/'])

        if not debug:
            add_task('default', '/task/pingrpctask')

        self.set_header("Content-Type", "application/json")
        rspd['msg'] = "成功保存文章!"
        self.write(json.dumps(rspd))
Exemple #13
0
    def post(self):
        try:
            tf = {'true': 1, 'false': 0}
            act = self.get_argument("act", '').encode('utf-8')
            category_id = self.get_argument("id", '').encode('utf-8')
            father_category_id = self.get_argument("father_id",
                                                   0).encode('utf-8')
            category_name = self.get_argument("name", '').encode('utf-8')
            show_type = self.get_argument("show_type", '').encode('utf-8')
            display_order = self.get_argument("sort", '0').encode('utf-8')
            allow_comment = tf[self.get_argument("allow_comment",
                                                 "false").encode('utf-8')]
            allow_publish = tf[self.get_argument("allow_publish",
                                                 "false").encode('utf-8')]
            description = self.get_argument("description", '').encode('utf-8')
        except:
            self.write(json.dumps("用户名、密码、验证码均为必填项!"))
            return

        if category_name:
            params = {
                'category_id': category_id,
                'father_category_id': father_category_id,
                'category_name': category_name,
                'show_type': show_type,
                'display_order': display_order,
                'allow_comment': allow_comment,
                'allow_publish': allow_publish,
                'description': description
            }
            if act == 'add':
                Categories.create(params)

            if act == 'edit':
                Categories.update(params)

            clear_cache_by_pathlist(['/'])

            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
        else:
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("参数异常"))
Exemple #14
0
    def get(self):
        act = self.get_argument("act", '').encode('utf-8')
        category_id = self.get_argument("id", '').encode('utf-8')

        obj = None
        if act == 'del':
            if category_id:
                Categories.delete(category_id)
                clear_cache_by_pathlist(['/'])
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
            return
        elif act == 'edit':
            if category_id:
                obj = Categories.get(category_id)

        # 分类列表
        page = self.get_argument("page", 1)
        category = Categories.get_paged(page, getAttr('ADMIN_CATEGORY_NUM'))
        total = int(
            math.ceil(Categories.count_all() /
                      float(getAttr('ADMIN_CATEGORY_NUM'))))
        if page == 1:
            self.echo('admin_category.html', {
                'title': "分类列表",
                'objs': category,
                'obj': obj,
                'category_kv': Categories.get_all_kv(0),
                'show_types': ShowTypes.get_all(),
                'total': total,
            },
                      layout='_layout_admin.html')
        else:
            result = {
                'list': category,
                'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result, default=dthandler))
            return
Exemple #15
0
    def post(self):
        value = self.get_argument("MAIL_FROM", '')
        if value:
            setAttr('MAIL_FROM', value)

        value = self.get_argument("MAIL_KEY", '')
        if value:
            setAttr('MAIL_KEY', value)

        value = self.get_argument("MAIL_SMTP", '')
        if value:
            setAttr('MAIL_SMTP', value)

        value = self.get_argument("MAIL_PORT", '')
        if value:
            setAttr('MAIL_PORT', value)

        clear_cache_by_pathlist(['/'])

        self.set_header("Content-Type", "application/json")
        self.write(json.dumps("OK"))
        return
Exemple #16
0
    def post(self):
        act = self.get_argument("act", '')
        if act == 'findid':
            eid = self.get_argument("id", '')
            self.redirect('%s/admin/comment/%s' % (BASE_URL, eid))
            return

        tf = {'true': 1, 'false': 0}
        post_dic = {
        'author': self.get_argument("author"),
        'email': self.get_argument("email", ''),
        'content': safe_encode(self.get_argument("content").replace('\r', '\n')),
        'url': self.get_argument("url", ''),
        'visible': self.get_argument("visible", 'false'),
        'id': id
        }
        post_dic['visible'] = tf[post_dic['visible'].lower()]

        Comments.update(post_dic)
        clear_cache_by_pathlist(['post:%s' % id])
        self.redirect('%s/admin/comment/%s' % (BASE_URL, id))
        return
Exemple #17
0
    def post(self):
        rspd = {"status": 200, "msg": "OK"}
        try:
            tf = {'true': 1, 'false': 0}
            act = self.get_argument("act", '').encode('utf-8')
            post_dic = {
            'category_id': self.get_argument("category_id", '-').encode('utf-8'),
            'user_id': self.get_secure_cookie("user_id"),
            'title': self.get_argument("title").encode('utf-8'),
            'digest': '-',
            'content': self.get_argument("content").encode('utf-8'),
            'image_url': '-',
            'tags': ','.join(self.get_arguments("tag")),
            'allow_comment': tf[self.get_argument("clo", 'false')],
            'top': tf[self.get_argument("top", 'false')],
            'password': self.get_argument("password", '').encode('utf-8'),
            'salt': '-',
            }
        except:
            rspd['status'] = 500
            rspd['msg'] = "用户名、邮箱均为必填项!"
            self.write(json.dumps(rspd))
            return

        if act == 'add':
            Posts.create(post_dic)
        elif act == 'edit':
            post_dic['post_id'] = int(self.get_argument("post_id", ""))
            Posts.update(post_dic)

        clear_cache_by_pathlist(['/'])

        if not debug:
            add_task('default', '/task/pingrpctask')

        self.set_header("Content-Type", "application/json")
        rspd['msg'] = "成功保存文章!"
        self.write(json.dumps(rspd))
Exemple #18
0
    def post(self):
        self.set_header('Content-Type', 'application/json')
        rspd = {'status': 201, 'msg': 'OK'}

        try:
            tf = {'true': 1, 'false': 0}
            email = self.get_argument("email", '')
            name = self.get_argument("username", '')
            pw = random_string(16)
            status = tf[self.get_argument("status", 'true')]
        except:
            rspd['status'] = 500
            rspd['msg'] = '错误: 注意必填项'
            self.write(json.dumps(rspd))
            return

        try:
            userid = User.create_user(name, email, pw, status)
            if userid:
                sendEmail(u"新用户注册通知 - " + SITE_TITLE, u"您的密码是:" + pw + u"<br />请及时登录并修改密码!", email)

                rspd['status'] = 200
                rspd['msg'] = '创建用户成功,已邮件通知该用户!'
                rspd['userid'] = userid
                rspd['method'] = "/admin/edit_user"
                clear_cache_by_pathlist(['/', 'user:%s' % str(userid)])
            else:
                rspd['status'] = 500
                rspd['msg'] = '错误: 通知邮件发送失败,请稍后重试'
        except OperationalError:
            rspd['status'] = 500
            rspd['msg'] = '错误: 该 Email 地址已被占用,请尝试重新提交'
        except:
            rspd['status'] = 500
            rspd['msg'] = '错误: 未知错误,请尝试重新提交'

        self.write(json.dumps(rspd))
        return
Exemple #19
0
    def post(self):
        try:
            tf = {'true': 1, 'false': 0}
            act = self.get_argument("act", '').encode('utf-8')
            user_id = self.get_argument("user_id", '').encode('utf-8')
            user_name = self.get_argument("user_name", '').encode('utf-8')
            email = self.get_argument("email", '').encode('utf-8')
            status = tf[self.get_argument("status", 'false').encode('utf-8')]
        except:
            self.write(json.dumps("用户名、邮箱均为必填项!"))
            return

        params = {
            'user_id': user_id,
            'user_name': user_name,
            'email': email,
            'password': None,
            'status': status
        }
        if act == 'add' and user_name is not None and email is not None:
            password = Users.create(params)
            # sub = {
            #     "%website%": [getAttr("SITE_TITLE").encode('utf-8')],
            #     "%url%": [getAttr("BASE_URL")],
            #     "%name%": [user_name],
            #     "%password%": [password]
            # }
            # sendTemplateEmail(u"密码重置通知 - " + getAttr('SITE_TITLE'), sub, str(email))
            sendEmail(u"密码重置通知 - " + getAttr('SITE_TITLE'),
                      u"您的新密码是:" + password + u"<br /><br />请及时登录并修改密码!",
                      str(email))
        elif act == 'edit' and user_id is not None:
            Users.update(params)

        clear_cache_by_pathlist(['/'])

        self.set_header("Content-Type", "application/json")
        self.write(json.dumps("OK"))
Exemple #20
0
    def post(self):
        try:
            act = self.get_argument("act", '').encode('utf-8')
            link_id = self.get_argument("id", '').encode('utf-8')
            link_name = self.get_argument("name", '').encode('utf-8')
            url = self.get_argument("url", '').encode('utf-8')
            display_order = self.get_argument("sort", '0').encode('utf-8')
        except:
            self.write(json.dumps("网站名称、URL均为必填项!"))
            return

        if link_name and url:
            params = {'link_id': link_id, 'link_name': link_name, 'url': url, 'display_order': display_order}
            if act == 'add':
                Links.create(params)

            if act == 'edit':
                Links.update(params)

            clear_cache_by_pathlist(['/'])

        self.set_header("Content-Type", "application/json")
        self.write(json.dumps("OK"))
Exemple #21
0
    def get(self):
        act = self.get_argument("act", '')
        link_id = self.get_argument("id", '')

        obj = None
        if act == 'del':
            if link_id:
                Links.delete(link_id)
                clear_cache_by_pathlist(['/'])
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
            return
        elif act == 'edit':
            if link_id:
                obj = Links.get(link_id)
                clear_cache_by_pathlist(['/'])

        # 友情链接列表
        page = self.get_argument("page", 1)
        links = Links.get_paged(page, getAttr('ADMIN_LINK_NUM'))
        total = math.ceil(Links.count_all() / float(getAttr('ADMIN_LINK_NUM')))
        if page == 1:
            self.echo('admin_link.html', {
                'title': "友情链接",
                'objs': links,
                'obj': obj,
                'total': total,
            },
                      layout='_layout_admin.html')
        else:
            result = {
                'list': links,
                'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result))
            return
Exemple #22
0
    def get(self):
        act = self.get_argument("act", '').encode('utf-8')
        category_id = self.get_argument("id", '').encode('utf-8')

        obj = None
        if act == 'del':
            if category_id:
                Categories.delete(category_id)
                clear_cache_by_pathlist(['/'])
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
            return
        elif act == 'edit':
            if category_id:
                obj = Categories.get(category_id)

        # 分类列表
        page = self.get_argument("page", 1)
        category = Categories.get_paged(page, getAttr('ADMIN_CATEGORY_NUM'))
        total = int(math.ceil(Categories.count_all() / float(getAttr('ADMIN_CATEGORY_NUM'))))
        if page == 1:
            self.echo('admin_category.html', {
                'title': "分类列表",
                'objs': category,
                'obj': obj,
                'category_kv': Categories.get_all_kv(0),
                'show_types': ShowTypes.get_all(),
                'total': total,
            }, layout='_layout_admin.html')
        else:
            result = {
                'list': category,
                'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result, default=dthandler))
            return
Exemple #23
0
    def get(self):
        act = self.get_argument("act", '')
        folk_id = self.get_argument("id", '')
        user_id = self.get_secure_cookie("user_id")

        obj = None
        if act == 'del':
            if folk_id:
                Folk.delete_folk(user_id, folk_id)
                clear_cache_by_pathlist(['/'])
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
            return
        elif act == 'edit':
            if folk_id:
                obj = Folk.get_folk(user_id, folk_id)
                clear_cache_by_pathlist(['/'])

        # 亲人列表
        page = self.get_argument("page", 1)
        objs = Folk.get_paged(user_id, page, getAttr('ADMIN_FOLK_NUM'))
        total = math.ceil(Folk.count_all(user_id) / float(getAttr('ADMIN_FOLK_NUM')))
        if page == 1:
            self.echo('admin_folk_list.html', {
                'title': "亲人管理",
                'objs': objs,
                'obj': obj,
                'total': total,
            }, layout='_layout_admin.html')
        else:
            result = {
                'list': objs,
                'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result))
            return
Exemple #24
0
    def post(self):
        value = self.get_argument("SITE_TITLE", '')
        if value:
            setAttr('SITE_TITLE', value)
        value = self.get_argument("SITE_TITLE2", '')
        if value:
            setAttr('SITE_TITLE2', value)

        value = self.get_argument("SITE_SUB_TITLE", '')
        if value:
            setAttr('SITE_SUB_TITLE', value)

        value = self.get_argument("KEYWORDS", '')
        if value:
            setAttr('KEYWORDS', value)

        value = self.get_argument("SITE_DECR", '')
        if value:
            setAttr('SITE_DECR', value)

        value = self.get_argument("ADMIN_NAME", '')
        if value:
            setAttr('ADMIN_NAME', value)

        value = self.get_argument("MOVE_SECRET", '')
        if value:
            setAttr('MOVE_SECRET', value)

        value = self.get_argument("NOTICE_MAIL", '')
        if value:
            setAttr('NOTICE_MAIL', value)

        clear_cache_by_pathlist(['/'])

        self.set_header("Content-Type", "application/json")
        self.write(json.dumps("OK"))
        return
Exemple #25
0
    def get(self):
        act = self.get_argument("act", '')
        link_id = self.get_argument("id", '')

        obj = None
        if act == 'del':
            if link_id:
                Links.delete(link_id)
                clear_cache_by_pathlist(['/'])
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
            return
        elif act == 'edit':
            if link_id:
                obj = Links.get(link_id)
                clear_cache_by_pathlist(['/'])

        # 友情链接列表
        page = self.get_argument("page", 1)
        links = Links.get_paged(page, getAttr('ADMIN_LINK_NUM'))
        total = math.ceil(Links.count_all() / float(getAttr('ADMIN_LINK_NUM')))
        if page == 1:
            self.echo('admin_link.html', {
                'title': "友情链接",
                'objs': links,
                'obj': obj,
                'total': total,
            }, layout='_layout_admin.html')
        else:
            result = {
                'list': links,
                'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result))
            return
Exemple #26
0
    def post(self, id='', title=''):
        action = self.get_argument("act")

        if action == 'inputpw':
            wrn = self.get_secure_cookie("wrpw")
            if wrn is not None and int(wrn) >= 10:
                self.write('403')
                return

            pw = self.get_argument("pw", '')
            pobj = Posts.get_post_simple(id)
            if pw:
                if pobj.password == pw:
                    clear_cache_by_pathlist(['post:%s' % id])
                    self.set_secure_cookie("rp%s" % id,
                                           pobj.password,
                                           expires_days=1)
                else:
                    self.set_secure_cookie("wrpw",
                                           str(int(wrn) + 1),
                                           expires_days=1)
            else:
                self.set_secure_cookie("wrpw",
                                       str(int(wrn) + 1),
                                       expires_days=1)

            self.redirect('%s/topic/%d/%s' % (BASE_URL, pobj.id, pobj.title))
            return

        self.set_header('Content-Type', 'application/json')
        rspd = {'status': 201, 'msg': 'ok'}

        if action == 'readmorecomment':
            fromid = self.get_argument("fromid", '')
            all_num = int(self.get_argument("allnum", 0))
            each_page_comment_num = getAttr('EACH_PAGE_COMMENT_NUM')
            showed_num = int(
                self.get_argument("showednum", each_page_comment_num))
            if fromid:
                rspd['status'] = 200
                if (all_num - showed_num) >= each_page_comment_num:
                    limit = each_page_comment_num
                else:
                    limit = all_num - showed_num
                cobjs = Comments.get_post_page_comments_by_id(
                    id, fromid, limit)
                rspd['commentstr'] = self.render('comments.html',
                                                 {'cobjs': cobjs})
                rspd['lavenum'] = all_num - showed_num - limit
                self.write(json.dumps(rspd))
            return

        # 评论次数限制不好使
        usercomnum = self.get_secure_cookie("usercomnum")
        if usercomnum is not None and int(usercomnum) > getAttr(
                'MAX_COMMENT_NUM_A_DAY'):
            rspd = {'status': 403, 'msg': '403: Forbidden'}
            self.write(json.dumps(rspd))
            return
        else:
            usercomnum = 0

        try:
            post_dic = {
                'author':
                self.get_argument("author"),
                'email':
                self.get_argument("email", ''),
                'content':
                safe_encode(self.get_argument("comment").replace('\r', '\n')),
                'url':
                self.get_argument("url", ''),
                'postid':
                self.get_argument("postid"),
                'add_time':
                int(time()),
                'toid':
                self.get_argument("toid", ''),
                'visible':
                getAttr('COMMENT_DEFAULT_VISIBLE')
            }
        except:
            rspd['status'] = 500
            rspd['msg'] = '错误:请检查你提交的数据是否正确!'
            self.write(json.dumps(rspd))
            return

        pobj = Posts.get_post_simple(id)
        if pobj and not pobj.closecomment:
            cobjid = Comments.create(post_dic)
            if cobjid:
                Posts.update_comment_num(pobj.comment_num + 1, id)
                self.set_secure_cookie("usercomnum",
                                       str(int(usercomnum) + 1),
                                       expires_days=1)
                rspd['status'] = 200
                rspd['msg'] = '恭喜您,已成功提交评论!'

                rspd['msg'] = self.render(
                    'comment.html', {
                        'postid':
                        id,
                        'cobjid':
                        cobjid,
                        'gravatar':
                        'http://www.gravatar.com/avatar/%s' %
                        md5(post_dic['email']).hexdigest(),
                        'url':
                        post_dic['url'],
                        'author':
                        post_dic['author'],
                        'add_time':
                        int(time()),
                        'visible':
                        post_dic['visible'],
                        'content':
                        post_dic['content'],
                    })

                clear_cache_by_pathlist(['/', 'post:%s' % id])

                #send mail
                if not debug:
                    try:
                        NOTICE_MAIL = getAttr('NOTICE_MAIL')
                        if NOTICE_MAIL:
                            tolist = [NOTICE_MAIL]
                        else:
                            tolist = []
                        if post_dic['toid']:
                            tcomment = Comments.get(post_dic['toid'])
                            if tcomment and tcomment.email:
                                tolist.append(tcomment.email)
                        commenturl = "%s/t/%s#r%s" % (BASE_URL, str(
                            pobj.id), str(cobjid))
                        m_subject = u'有人回复您在 《%s》 里的评论 %s' % (pobj.title,
                                                              str(cobjid))
                        m_html = u'这是一封提醒邮件(请勿直接回复): %s ,请尽快处理: %s' % (
                            m_subject, commenturl)

                        if tolist:
                            import sae.mail

                            sae.mail.send_mail(','.join(tolist), m_subject,
                                               m_html,
                                               (getAttr('MAIL_SMTP'),
                                                int(getAttr('MAIL_PORT')),
                                                getAttr('MAIL_FROM'),
                                                getAttr('MAIL_KEY'), True))

                    except:
                        pass
            else:
                rspd['msg'] = '保存评论失败!'
        else:
            rspd['msg'] = '当前文章禁止评论!'
        self.write(json.dumps(rspd))
Exemple #27
0
    def get(self):
        act = self.get_argument("act", '')
        post_id = self.get_argument("post_id", '')

        obj = None
        if act == 'add':
            obj = Posts
            obj.post_id = ''
            obj.category_id = ''
            obj.category_name = ''
            obj.title = ''
            obj.content = ''
            obj.tags = ''
            obj.allow_comment = 1
            obj.top = 0
            obj.password = ''
            self.echo('admin_post_edit.html', {
                'title': "添加文章",
                'method': "/admin/posts?act=add",
                'categories': Categories.get_all_kv(),
                'tags': Tags.get_all_tag_name(),
                'obj': obj,
            },
                      layout='_layout_admin.html')
            return
        elif act == 'edit':
            if post_id:
                obj = Posts.get(post_id)
                self.echo('admin_post_edit.html', {
                    'title': "编辑文章",
                    'method': "/admin/posts?act=edit",
                    'categories': Categories.get_all_kv(),
                    'tags': Tags.get_all_tag_name(),
                    'obj': obj,
                },
                          layout='_layout_admin.html')
                return
        elif act == 'del':
            if post_id:
                oldobj = Posts.get(post_id)
                Archives.remove_post_from_archive(post_id=post_id)
                Posts.delete(post_id)
                cache_key_list = [
                    '/',
                    'post:%s' % post_id,
                    'cat:%s' % quoted_string(oldobj.category)
                ]
                clear_cache_by_pathlist(cache_key_list)
                clear_cache_by_pathlist(['post:%s' % post_id])

                Posts.delete(post_id)
                clear_cache_by_pathlist(['/'])
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
            return

        # 文章列表
        page = self.get_argument("page", 1)
        posts = Posts.get_paged(page, getAttr('ADMIN_POST_NUM'))
        categories = Categories.get_all_kv()
        total = math.ceil(Posts.count_all() / int(getAttr('ADMIN_POST_NUM')))
        if page == 1:
            self.echo('admin_post_list.html', {
                'title': "文章链接",
                'objs': posts,
                'categories': categories,
                'total': total,
            },
                      layout='_layout_admin.html')
        else:
            result = {
                'list': posts,
                'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result))
            return
Exemple #28
0
    def get(self):
        act = self.get_argument("act", '')
        post_id = self.get_argument("post_id", '')

        obj = None
        if act == 'add':
            obj = Posts
            obj.post_id = ''
            obj.category_id = ''
            obj.category_name = ''
            obj.title = ''
            obj.content = ''
            obj.tags = ''
            obj.allow_comment = 1
            obj.top = 0
            obj.password = ''
            self.echo('admin_post_edit.html', {
            'title': "添加文章",
            'method': "/admin/posts?act=add",
            'categories': Categories.get_all_kv(),
            'tags': Tags.get_all_tag_name(),
            'obj': obj,
            }, layout='_layout_admin.html')
            return
        elif act == 'edit':
            if post_id:
                obj = Posts.get(post_id)
                self.echo('admin_post_edit.html', {
                'title': "编辑文章",
                'method': "/admin/posts?act=edit",
                'categories': Categories.get_all_kv(),
                'tags': Tags.get_all_tag_name(),
                'obj': obj,
                }, layout='_layout_admin.html')
                return
        elif act == 'del':
            if post_id:
                oldobj = Posts.get(post_id)
                Archives.remove_post_from_archive(post_id=post_id)
                Posts.delete(post_id)
                cache_key_list = ['/', 'post:%s' % post_id, 'cat:%s' % quoted_string(oldobj.category)]
                clear_cache_by_pathlist(cache_key_list)
                clear_cache_by_pathlist(['post:%s' % post_id])

                Posts.delete(post_id)
                clear_cache_by_pathlist(['/'])
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
            return

        # 文章列表
        page = self.get_argument("page", 1)
        posts = Posts.get_paged(page, getAttr('ADMIN_POST_NUM'))
        categories = Categories.get_all_kv()
        total = math.ceil(Posts.count_all() / int(getAttr('ADMIN_POST_NUM')))
        if page == 1:
            self.echo('admin_post_list.html', {
            'title': "文章链接",
            'objs': posts,
            'categories': categories,
            'total': total,
            }, layout='_layout_admin.html')
        else:
            result = {
            'list': posts,
            'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result))
            return