Esempio n. 1
0
    def post(self):
        iauth = Auth.identify(Auth, request)
        if iauth['status']:
            if iauth['data']['isAdmin']:
                name = request.json.get('groupname')
                about = request.json.get('about')
                if check_group(name):
                    group = Groups(name=name, about=about)
                    res = Groups.add(group)
                    if group.id:
                        result = common.trueReturn(
                            {
                                'id': group.id,
                                'name': group.name
                            }, "请求成功")
                    else:
                        result = common.falseReturn(res, '请求失败')
                else:
                    result = common.falseReturn('该分组已存在', '请求失败')
            else:
                result = common.falseReturn('权限不足.', "请求失败")

        else:
            result = common.falseReturn(iauth['data'], "请求失败")
        return jsonify(result)
Esempio n. 2
0
    def identify(self, request):
        """
        用户鉴权
        :return: list
        """
        auth_header = request.headers.get("mToken")
        if auth_header:
            auth_tokenArr = auth_header.split(" ")
            if (not auth_tokenArr or auth_tokenArr[0] != 'JWT'
                    or len(auth_tokenArr) != 2):
                result = falseReturn('', '请传递正确的验证头信息')
            else:
                auth_token = auth_tokenArr[1]
                payload = self.decode_auth_token(auth_token)
                if not isinstance(payload, str):
                    user = User.query.filter_by(
                        id=payload['data']['id']).first()
                    if (user is None):
                        result = falseReturn('', '找不到该用户信息')
                    else:
                        if user.login_time == payload['data']['login_time']:
                            result = trueReturn(user.id, '请求成功')
                        else:
                            result = falseReturn('', 'Token已更改,请重新登录获取')
                else:

                    result = falseReturn('', payload)
        else:
            result = falseReturn('', '没有提供认证token')
        return result
Esempio n. 3
0
    def kill_auth(self, request):
        '''
        删除权限
        :return:
        '''
        auth_header = request.headers.get("mToken")
        if auth_header:
            auth_tokenArr = auth_header.split(" ")
            if (not auth_tokenArr or auth_tokenArr[0] != 'JWT'
                    or len(auth_tokenArr) != 2):
                result = falseReturn('', '请传递正确的验证头信息')
            else:
                auth_token = auth_tokenArr[1]
                payload = self.decode_auth_token(auth_token)
                if not isinstance(payload, str):
                    # user = User.get(payload['data']['id'])
                    user = User.query.filter_by(
                        id=payload['data']['id']).first()
                    if (user is None):
                        result = falseReturn('', '找不到该用户信息')
                    else:
                        user.login_time = None
                        user.update()
                        result = trueReturn('', '登出成功')
                else:

                    result = falseReturn('', payload)

        else:
            result = falseReturn('', '您还没登录,请先登录')
        return result
Esempio n. 4
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('article_id', type=int)
     article_id = parser.parse_args()['article_id']
     filter = {Comment.article_id == article_id, Comment.parent_id == None}
     comment = Comment.query.filter(*filter).all()
     print(comment)
     return trueReturn(comment, 'success')
Esempio n. 5
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('name', type=str)
     category = parser.parse_args()
     c = dict(category)
     ctg = Category(**c)
     Category.add(ctg)
     return trueReturn(ctg, 'success')
Esempio n. 6
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('title', type=str)
     parser.add_argument('content', type=str)
     parser.add_argument('user_id', type=int)
     parser.add_argument('category_id', type=int)
     article = parser.parse_args()
     atc = Articles(**dict(article))
     Articles.add(atc)
     return trueReturn(atc, 'success')
Esempio n. 7
0
    def get(self):
        '''
        返回整个分页图片
        :return:
        '''
        try:
            # 注册入参
            parser = reqparse.RequestParser()
            parser.add_argument('pageIndex',
                                type=int,
                                location=['headers', 'args'])
            parser.add_argument('pageSize',
                                type=int,
                                location=['headers', 'args'])
            # 获取入参
            args = parser.parse_args()
            pageIndex = args['pageIndex'] or 1
            pageSize = args['pageSize'] or 12

            search_img = girls_img.query.order_by(girls_img.id.asc())
            imgs = search_img.paginate(pageIndex,
                                       per_page=pageSize,
                                       error_out=False)

            count = imgs.total
            totalPage = math.floor(count / pageSize)
            list = []
            for item in imgs.items:
                list.append({
                    'id':
                    item.id,
                    'girls_album_id':
                    item.girls_album_id,
                    'img_url':
                    item.img_url,
                    'local_img_url':
                    "/static/girlsImg/%s" % item.local_img_url,
                })

            return trueReturn(
                {
                    'list': list,
                    'pageInfo': {
                        'pageIndex': pageIndex,
                        'pageSize': pageSize,
                        'count': count,
                        'totalPage': totalPage,
                    }
                }, 'success')

        except Exception as e:
            raise Exception(e)
            print(e)
            return falseReturn('', e)
Esempio n. 8
0
 def get(self, groupid):
     iauth = Auth.identify(Auth, request)
     if iauth['status']:
         if iauth['data']['isAdmin']:
             try:
                 Groups.delete(Groups, groupid)
                 result = common.trueReturn('删除分组成功.', "请求成功")
             except Exception as e:
                 result = common.falseReturn(e, "请求失败")
         else:
             result = common.falseReturn('权限不足.', "请求失败")
     else:
         result = common.falseReturn(iauth['data'], "请求失败")
     return result
Esempio n. 9
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('user_id', type=int)
     parser.add_argument('content', type=str)
     parser.add_argument('article_id', type=int)
     parser.add_argument('parent_id', type=int)
     parser.add_argument('reply_uid', type=int)
     comment = parser.parse_args()
     c = dict(comment)
     com = Comment(**c)
     back = Comment.add(com)
     if back is not None:
         return falseReturn(back, 'error')
     return trueReturn(com, 'success')
Esempio n. 10
0
 def get(self):
     iauth = Auth.identify(Auth, request)
     if iauth['status']:
         try:
             g_list = []
             for g in Groups.query.all():
                 g_list.append({
                     "id": g.id,
                     "name": g.name,
                     "about": g.about,
                 })
             result = common.trueReturn(g_list, u"请求成功")
         except Exception as e:
             result = common.falseReturn(e, "请求失败")
     else:
         result = common.falseReturn(iauth['data'], "请求失败")
     return result
Esempio n. 11
0
 def get(self):
     '''
     获取相册集合
     tagID(可选):int//标签id
     keywords(可选):str//查询关键词
     pageIndex(可选):int//当前页数(默认为1)
     pageSize(可选):int//每页条数(默认为10)
     :return:
     '''
     #注册入参
     parser = reqparse.RequestParser()
     parser.add_argument('tagID', type=int, location='headers')
     parser.add_argument('keywords', type=str, location='headers')
     parser.add_argument('pageIndex', type=int, location='headers')
     parser.add_argument('pageSize', type=int, location='headers')
     #获取入参
     args = parser.parse_args()
     pageIndex = args['pageIndex'] or 1
     pageSize = args['pageSize'] or 10
     tagID = args['tagID']
     keywords = args['keywords']
     #查询参数可选
     filter = []
     if tagID:
         filter.append(girls_album.girls_tag_id == tagID)
     if keywords:
         filter.append(girls_album.title.ilike("%" + keywords + "%"))
     # album = girls_album.query.filter_by(girls_tag_id=696).first()
     search_album = girls_album.query.filter(*filter).order_by(
         girls_album.id.desc())
     album = search_album.paginate(pageIndex,
                                   per_page=pageSize,
                                   error_out=False)
     count = search_album.count()
     totalPage = math.floor(count / pageSize)
     return trueReturn(
         {
             'list': album.items,
             'pageInfo': {
                 'pageIndex': pageIndex,
                 'pageSize': pageSize,
                 'count': count,
                 'totalPage': totalPage,
             }
         }, 'success')
Esempio n. 12
0
 def post(self):
     iauth = Auth.identify(Auth, request)
     if iauth['status']:
         try:
             group = Groups.query.filter_by(
                 id=request.json.get('id')).first()
             if not check_group(request.json.get('groupname')):
                 result = common.falseReturn('该分组名字已存在', "请求失败")
             else:
                 group.name = request.json.get('groupname')
                 group.about = request.json.get('about')
                 a = group.update()
                 result = common.trueReturn('分组更新成功', "请求成功")
         except Exception as e:
             result = common.falseReturn(e, "请求失败")
     else:
         result = common.falseReturn(iauth['data'], "请求失败")
     return jsonify(result)
Esempio n. 13
0
 def authenticate(self, username, password):
     '''
     用户登录
     :param username:
     :param password:
     :return:
     '''
     userInfo = User.query.filter_by(username=username).first()
     if userInfo is None:
         return jsonify(falseReturn('', '用户名不存在'))
     else:
         if userInfo.check_password(userInfo._password, password):
             login_time = int(time.time())
             userInfo.login_time = login_time
             # Users.update(Users)
             userInfo.update()
             token = self.encode_auth_token(userInfo.id, login_time)
             return jsonify(trueReturn(token.decode(), 'success'))
         else:
             return jsonify(falseReturn('', '密码不正确'))
Esempio n. 14
0
    def get(self):
        '''
        整个标签集合
        :return:
        '''
        tags = girls_tag.query.all()
        list = []
        for tag in tags:
            list.append({
                'id':
                tag.id,
                'title':
                tag.title,
                'tag':
                tag.tag,
                'cover_img':
                tag.cover_img,
                'local_cover_img':
                "/static/girlsImg/%s" % tag.local_cover_img,
            })

        return trueReturn({'list': list}, 'success')
Esempio n. 15
0
    def get(self):
        '''
        返回对应相册的图集
        :return:

        '''
        try:
            parser = reqparse.RequestParser()
            parser.add_argument('albumId', type=int, location="headers")
            args = parser.parse_args()
            album_id = args['albumId']
            imgs = girls_img.query.filter_by(girls_album_id=album_id)
            count = girls_img.query.filter_by(girls_album_id=album_id).count()
            return trueReturn({
                'list': imgs,
                'info': {
                    'count': count
                }
            }, 'success')

        except Exception as e:
            print(e)
            return falseReturn('', e)