Exemple #1
0
def get_avatar(name):
    admin = Admin.query.filter_by(name=name).first()
    avatar = 'admin/images/guest.png'
    if admin and admin.avatar:
        avatar = admin.avatar
    data = {'image': avatar}
    return Success(data=data)
Exemple #2
0
 def get(self):
     logger.info('收到测试请求')
     hostname = socket.gethostname()
     data = {
         'hostname': socket.gethostname(),
         'ip': socket.gethostbyname(hostname),
         'say': 'Hi mocobk',
         'time': time.strftime('%Y-%m-%d %H:%M:%S')
     }
     return Success(data=data)
Exemple #3
0
 def get(self):
     args = self.parser.parse_args()
     mock_data = MockData.query.filter(
         MockData.status != -1,
         MockData.project_id == args.project_id,
         (MockData.id != args.parent_id) if args.parent_id else text(''),
         (MockData.method == args.method) if args.method else text(''),
         (MockData.url == args.url) if args.url else text(''),
         (MockData.match_type == args.match_type) if args.match_type else text(''),
     ).all()
     data = MockDataSchema().dump(mock_data, many=True)
     return Success(data=data)
Exemple #4
0
    def get(self):
        args = CommonRequestParser().parse_args()
        search_words = args.get('search_words')
        projects_paginate = MockProject.query.filter(MockProject.status != -1,
                                                     or_(MockProject.name.like(f'%{search_words}%'),
                                                         MockProject.description.like(f'%{search_words}%')
                                                         ) if search_words else text('')
                                                     ).paginate(page=args.page, per_page=args.page_size)

        data = MockProjectSchema().dump(projects_paginate.items, many=True)
        return Success(data={
            'page': projects_paginate.page,
            'pages': projects_paginate.pages,
            'total': projects_paginate.total,
            'data': data,
        })
Exemple #5
0
    def post(self):
        args = self.parser.parse_args()
        if args.get('target_url'):
            is_match = args.url in args.target_url if args.match_type == 0 else bool(
                re.search(args.url, args.target_url, re.IGNORECASE))
        else:
            is_match = True

        headers = self.mock(args.headers) if args.get('headers') else {}
        response = self.mock(args.response) if args.get('response') else {}
        content_type = {"Content-Type": args.content_type} if args.get('content_type') else {}

        return Success(data={
            'is_match': is_match,
            'headers': {'Access-Control-Allow-Origin': '*', **content_type, **headers},
            'response': response,
        })
Exemple #6
0
def login():
    form = AdminLoginForm(request.form)
    if request.method == "POST":
        if form.validate():
            admin = Admin.query.filter_by(name=form.name.data).first()
            if admin and admin.check_password(form.password.data):
                login_user(admin)
                admin.login_ip = request.remote_addr
                admin.login_time = datetime.datetime.now().strftime(
                    "%Y-%m-%d %H:%M:%S")
                admin.login_count += 1
                next = request.args.get('next')
                if not next or not next.startswith('/'):
                    next = url_for('admin.index')
                return Success(message="登录成功", redirect_to=next)
            return Fail(message="用户名或密码错误")
        return Fail(message=form.first_error)
    else:
        if current_user.is_authenticated and request.blueprint in current_user.get_id(
        ):
            return redirect(url_for('admin.index'))
        return render_template("admin/auth/login.html")
Exemple #7
0
    def get(self):
        """
        select a.*,b.count
        from mock_data a join
        (select max(id) as id,count(*) as count  from  mock_data  where project_id = 6 group by method,url) b
        on a.id=b.id ORDER BY a.create_time DESC;
        """
        parser: RequestParser = CommonRequestParser()
        parser.add_argument('project_id', type=int)
        args = parser.parse_args()

        search_words = args.get('search_words')

        sub_query = db.session.query(
            func.max(MockData.id).label('id'),
            func.count('*').label('count')).filter(
                MockData.status != -1, MockData.project_id == args.project_id,
                or_(MockData.url.like(f'%{search_words}%'),
                    MockData.description.like(f'%{search_words}%'))
                if search_words else text('')).group_by(
                    MockData.method, MockData.url,
                    MockData.match_type).subquery()

        mock_data_paginate = db.session.query(MockData, sub_query.c.count) \
            .join(sub_query, MockData.id == sub_query.c.id).paginate(page=args.page,
                                                                     per_page=args.page_size,
                                                                     error_out=False)

        data = MockDataWithCountSchema().dump(mock_data_paginate.items,
                                              many=True)
        return Success(
            data={
                'page': mock_data_paginate.page,
                'pages': mock_data_paginate.pages,
                'total': mock_data_paginate.total,
                'data': data,
            })
Exemple #8
0
 def get(self, uid):
     user = User.query.get_or_404(uid)
     data = UserSchema().dump(user)
     return Success(data=data)
Exemple #9
0
 def get(self):
     users = User.query.all()
     data = UserSchema(many=True).dump(users)
     return Success(data=data)
Exemple #10
0
 def get(self, id_):
     project = MockProject.query.filter(
         MockProject.status != -1, MockProject.id == id_).first_or_404()
     data = MockProjectSchema().dump(project)
     return Success(data=data)
Exemple #11
0
 def get(self, id_):
     mock_data = MockData.query.filter(MockData.status != -1,
                                       MockData.id == id_).first_or_404()
     data = MockDataSchema().dump(mock_data)
     return Success(data=data)
Exemple #12
0
 def get(self):
     user = User.query.get(g.user.uid)
     data = UserSchema().dump(user)
     return Success(data=data)