コード例 #1
0
    "posts" : fields.List(fields.Nested(post_details))
})

login_details = api.model('login_details', {
  'username': fields.String(required=True, example='xX_greginator_Xx'),
  'password': fields.String(required=True, example='1234'),
})

user_details = api.model('user_details', {
    'id': fields.Integer(min=0),
    'username': fields.String(example='xX_greginator_Xx'),
    'email': fields.String(example='*****@*****.**'),
    'name':  fields.String(example='greg'),
    'posts': fields.List(fields.Integer(min=0)),
    'following': fields.List(fields.Integer(min=0)),
    'followed_num': fields.Integer(min=0)
})
user_update_details = api.model('user_update_details', {
    'email': fields.String(example='*****@*****.**'),
    'name':  fields.String(example='greg'),
    'password': fields.String(example='1234')
})
signup_details = api.model('signup_details', {
  'username': fields.String(required=True, example='xX_greginator_Xx'),
  'password': fields.String(required=True, example='1234'),
  'email': fields.String(required=True, example='*****@*****.**'),
  'name':  fields.String(required=True, example='greg')
})

auth_details = api.parser().add_argument('Authorization', help="Your Authorization Token in the form 'Token <AUTH_TOKEN>'",location='headers')
コード例 #2
0
from flask_restplus import Resource, fields
import requests
from datetime import datetime
import sys
import json
import traceback
from babel.numbers import format_currency
from concurrent.futures import ThreadPoolExecutor

from app.apis.uniparthenope.v1.login_v1 import token_required, token_required_general

url = "https://uniparthenope.esse3.cineca.it/e3rest/api/"
ns = api.namespace('uniparthenope')

# ------------- DEPARTMENT INFO -------------
parser = api.parser()
parser.add_argument('stuId', type=str, required=True, help='User stuId')


@ns.doc(parser=parser)
class DepInfo(Resource):
    @ns.doc(security='Basic Auth')
    @token_required
    def get(self, stuId):
        """Get Department Information"""

        headers = {
            'Content-Type': "application/json",
            "Authorization": "Basic " + g.token
        }
コード例 #3
0
                'version': lxc.version,
                'lxcpath': lxc.get_global_config_item('lxc.lxcpath'),
                'default_config': lxc.get_global_config_item('lxc.default_config')
            }
        }

        if not container:
            output = {
                'attributes': json_output
            }
        else:
            output = json_output

        return {'data': output}

host_reboot_parser = api.parser()
host_reboot_parser.add_argument('message', type=str, location='json')


class HostReboot(Resource):
    decorators = [jwt_required]

    @user_has('host_reboot')
    @api.expect(host_reboot_fields_post)
    def post(self):
        """
        Reboot host
        """
        args = host_reboot_parser.parse_args()

        if not args.message:
コード例 #4
0
ファイル: models.py プロジェクト: rhf0410/COMP9041
    })

user_details = api.model(
    'user_details', {
        'id': fields.Integer(min=0),
        'username': fields.String(example='xX_greginator_Xx'),
        'email': fields.String(example='*****@*****.**'),
        'name': fields.String(example='greg'),
        'posts': fields.List(fields.Integer(min=0)),
        'following': fields.List(fields.Integer(min=0)),
        'followed_num': fields.Integer(min=0)
    })
user_update_details = api.model(
    'user_update_details', {
        'email': fields.String(example='*****@*****.**'),
        'name': fields.String(example='greg'),
        'password': fields.String(example='1234')
    })
signup_details = api.model(
    'signup_details', {
        'username': fields.String(required=True, example='xX_greginator_Xx'),
        'password': fields.String(required=True, example='1234'),
        'email': fields.String(required=True, example='*****@*****.**'),
        'name': fields.String(required=True, example='greg')
    })

auth_details = api.parser().add_argument(
    'Authorization',
    help="Your Authorization Token in the form 'Token <AUTH_TOKEN>'",
    location='headers')
コード例 #5
0
import uuid
from flask_restplus import Resource
from google.cloud import storage
from firebase import firebase
from werkzeug.datastructures import FileStorage
from app import api, app, classify_image, my_utils

upload_parser = api.parser()
upload_parser.add_argument('file',
                           location='files',
                           type=FileStorage,
                           required=True)

firebase = firebase.FirebaseApplication(
    'https://pupper-classifier.appspot.com/')
client = storage.Client()
bucket = client.get_bucket('pupper-classifier.appspot.com')


def random_file_name(ext, length):
    return str(uuid.uuid4())[0:length] + "." + ext


@api.route('/upload-image/')
@api.expect(upload_parser)
class Upload(Resource):
    def get(self):
        return "hello world"

    def post(self):
        args = upload_parser.parse_args()
コード例 #6
0
ファイル: helpers.py プロジェクト: JamesTheBard/sca
from app import api, db, app
from flask import abort, jsonify
from flask_jwt_extended import verify_jwt_in_request, get_jwt_identity
from functools import wraps
from sqlalchemy import inspect
from app.models.users import User
from app.models.groups import Group

token_parser = api.parser()
token_parser.add_argument('Authorization',
                          location='headers',
                          type=str,
                          help='Bearer Access Token',
                          required=True)


def init():
    u = User.query.all()
    if not u:
        admin_user = User(username=app.config['APP_DEFAULT_USERNAME'], )
        admin_user.set_password(app.config['APP_DEFAULT_PASSWORD'])
        admin_group = Group(name=app.config['APP_DEFAULT_ADMIN_GROUP'])
        admin_user.in_groups.append(admin_group)
        db.session.add(admin_user)
        db.session.add(admin_group)
        db.session.commit()


def is_admin(f):
    @wraps(f)
    def wrap(*args, **kwargs):
コード例 #7
0
ファイル: login.py プロジェクト: sergicollado/simpleFlaskSeed
from flask.ext.restplus import Resource
from app import api, namespace

parser = api.parser()
parser.add_argument('idCard', required=True, type=str, location='form',
                    help="IdCard cannot be blank!")

@namespace.route('/login')
@api.doc(params={'idCard':'Idenfitication document'})
class Login(Resource):

    @api.doc(parser=parser)
    def post(self):
        '''Login user into platform'''
        args =parser.parse_args()
        return {
            'user':args
        }

コード例 #8
0
from flask import request, url_for
from flask_restx import Resource
from werkzeug.datastructures import FileStorage

from app import api
from app.services import ImageService

post_parser = api.parser()
post_parser.add_argument('file', type=FileStorage, required=True, location='files')


class ImagesUploadController(Resource):

    @api.expect(post_parser)
    @api.response(200, 'Success')
    def post(self):
        if 'file' not in request.files:
            return {'file': 'No file part'}, 400
        file: FileStorage = request.files['file']
        if file.filename == '':
            return {'file': 'No file part'}, 400

        image, file_path, thumbnail_path = ImageService.save(file)

        ImageService.schedule_thumbnail(image, file_path, thumbnail_path)

        return {'id': image.id, 'file': url_for('meta', idx=image.id)}
コード例 #9
0
    'allow_contact_by_merchant': fields.Boolean(description='whether to communicated by merchant'),
    'allow_press': fields.Boolean(description='whether to have media report it'),
    'item_price': fields.String(description='item_price'),
    'item_model': fields.String(description='item_model'),
    'tradeInfo': fields.String(description='tradeInfo'),
    'relatedProducts': fields.String(description='relatedProducts'),
    'purchase_timestamp': fields.DateTime(description='purchase_timestamp'),
    'invoice_files': fields.List(fields.Nested(file_fields)),
    'id_files': fields.List(fields.Nested(file_fields))
})

complaint_list = api.model('ComplaintListModel', {
    'complaint_list': fields.List(fields.Nested(complaint_fields))
})

complaint_parser = api.parser()
complaint_parser.add_argument('complaint_id', type=str, required=True, help='complaint id', location='json')

@ns.route('/complaint')
@api.doc(responses={
    200: 'Success',
    400: 'Validation Error'
})
class Complaint(Resource):

    @ns.doc('get Complaint by complaint_id')
    @api.doc(parser=complaint_parser)
    @api.expect(complaint_parser)
    def get(self):
        '''get Complaint by complaint_id'''
コード例 #10
0
import datetime
import uuid
import jwt
from flask import request, jsonify, make_response
from werkzeug.security import generate_password_hash, check_password_hash
from app import api, app, Resource, User, db, Session, Bucketlist, models, BucketlistItems
from app.decorators import token_required

login_parser = api.parser()
login_parser.add_argument('name',
                          type=str,
                          help='Username',
                          location='form',
                          required=True)
login_parser.add_argument('password',
                          type=str,
                          help='Password',
                          location='form',
                          required=True)


class UserLogin(Resource):
    '''Allow a user to login to the Bucketlist application'''
    @api.doc(parser=login_parser)
    def post(self):
        '''Login a user.'''
        args = parser.parse_args()
        name = args['name']
        passwd = args['password']

        if not name or not passwd:
コード例 #11
0
ファイル: controllers.py プロジェクト: enderv/bug-search
from app.common.elastic_help import ElasticSearch
from app.common.bug import clean_bug_data
from app import api, app

#TODO make this config load projects and create client for each!
search_clients = {}
for project in app.config['PROJECTS']:
    search_clients[project] = ElasticSearch(
        index=project,
        hosts=app.config['ELASTIC_SEARCH_HOST'],
        doc_type=app.config['DOC_TYPE'])

bug_search_module = Blueprint('bug_search_module', __name__, url_prefix='/bug')
bug_search_module_api = Api(bug_search_module)

bug_parser = api.parser()
bug_parser.add_argument('title',
                        type=str,
                        required=True,
                        help='Bug Title',
                        location='form')
bug_parser.add_argument('description',
                        type=str,
                        required=True,
                        help='Bug Description',
                        location='form')


@api.doc(responses={404: 'Not found'}, params={'bug_id': 'The Bug ID'})
class GeneralBug(Resource):
    @api.doc(
コード例 #12
0
from app import api
from app.common.inputs import email, unique_email, password

users_post = api.parser()

users_post.add_argument(
    'email',
    type=unique_email,
    required=True,
    help='A Valid email address'
)

users_post.add_argument(
    'password',
    type=password,
    required=True,
    help='At least 8 characters required'
)

users_put = api.parser()

users_put.add_argument(
    'email',
    type=email,
    help='A Valid email address'
)

users_put.add_argument(
    'password',
    type=password,
    help='At least 8 characters required'
コード例 #13
0
ファイル: auth_api.py プロジェクト: pistoolster/web-backend

@ns.route('/phone_exist/<string:phone_num>')
@api.doc(params={'phone_num': 'A phone number'})
class PhoneExist(Resource):
    '''Check if phone number is registered'''
    @api.doc(responses={200: 'Success', 400: 'Validation Error'})
    def get(self, phone_num):
        user = User.query.filter_by(username=phone_num).first()
        print(user)
        if user is None:
            return {phone_num: "Not Registerred phone num"}, 400
        return {"state": "Success"}, 200


sms_parser = api.parser()
sms_parser.add_argument('v_code',
                        type=str,
                        required=True,
                        help='verification code',
                        location='json')


@ns.route('/sms/<string:phone_num>')
@api.doc(params={'phone_num': 'A phone number'})
@api.doc(responses={
    200: 'Success',
    400: 'Validation Error',
    401: 'Passcode is not correct'
})
class SMS(Resource):
コード例 #14
0
import flask
from flask import render_template, flash, redirect, url_for, request, Blueprint
from flask_login import login_user, logout_user, current_user, login_required
from app import application, db, api
from app.models import User, FuzzySearchRaw, MerchantQueryRaw
from app.sms.send_sms import send_message
from app.qichacha.qichacha_api import fuzzy_search, basic_detail
from flask_restplus import Resource, fields
import datetime
import json

ns = api.namespace('api', description='All API descriptions')

qichacha_parser = api.parser()
qichacha_parser.add_argument('keyword',
                             type=str,
                             required=True,
                             help='keyword',
                             location='json')


@ns.route('/fuzzy_query')
@api.doc(responses={200: 'Success', 400: 'Validation Error'})
class FuzzyQuery(Resource):
    @login_required
    @api.doc(parser=qichacha_parser)
    def post(self):
        '''fuzzy_query'''

        args = qichacha_parser.parse_args()
        keyword = args['keyword']
コード例 #15
0
        fields.String(
            required=True,
            example='Eggs and cheese ham is a deluxe meal served for kings')
    })

recipe_list_model = api.model(
    'recipe_list_model', {
        'recipes': fields.List(fields.Nested(recipe_complete_model)),
    })

# Request models
request_id_model = api.model(
    'request_id_model', {'request_id': fields.Integer(required=True, min=0)})

request_complete_model = api.model(
    'request_complete_model', {
        'request_id': fields.Integer(required=True, min=0),
        'times_requested': fields.Integer(required=True, min=1),
        'ingredients': fields.List(fields.Nested(ingredient_model))
    })

request_list_model = api.model(
    'request_list_model',
    {'requests': fields.List(fields.Nested(request_complete_model))})

auth_model = api.parser().add_argument(
    'Authorization',
    help="Authorization token given from logging in",
    location='headers',
    required=True)