コード例 #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)
コード例 #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
コード例 #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
コード例 #4
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
コード例 #5
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
コード例 #6
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)
コード例 #7
0
 def get(self):
     result = Auth.identify(Auth, request)
     if result['status']:
         user = Users.query.filter_by(
             username=result["data"]["username"]).first()
         print user.group.gusers.all()
         # Groups.delete(Groups, 1)
     else:
         result = common.falseReturn(result['data'], "请求失败")
     return jsonify(result)
コード例 #8
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('', '密码不正确'))
コード例 #9
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)
コード例 #10
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')
コード例 #11
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)