예제 #1
0
 def post(self) -> Dict:
     """
     accept json format:
         {
             "username": "******"Vasya",
             "password": "******"qwerty"
         }
     todo finalize exceptions processing
     """
     data = parser.parse_args()
     current_user = UserModel
     current_user.name, current_user.password = data['username'], UserModel.generate_hash(data['password'])
     try:
         password_FromDatabase = db.select('test_user',
                                           {'select_values': 'password',
                                            'condition': {'username': current_user.name}})[0]
         if len(password_FromDatabase) == 0:
             return {'message': f'User {current_user.name} doesn\'t exist'}
         if current_user.verify_hash(current_user.password, password_FromDatabase[0]):
             access_token = create_access_token(identity=data['username'])
             refresh_token = create_refresh_token(identity=data['username'])
             return {
                     'message': f'Logged as {current_user.name}',
                     'access_token': access_token,
                     'refresh_token': refresh_token
                     }
         else:
             return {'message': 'Wrong credentials'}
     except Exception as e:
         logger.exception(f'There is exception: {e} in api.endpoint module in UserLogin class')
         return {'message': 'Can\'t login'}
예제 #2
0
    def build_query(self, resource_type, params, id_only=False):
        '''
        Compile a SQL query from a set of FHIR search params
        
        If `id_only` is true, a SQL query that selects only `resource_id` will be returned
        '''
        query_args = [Resource.visible == True,
                      Resource.resource_type == resource_type,
                      Resource.owner_id == self.owner_id]
    
        valid_search_params = SPECS[resource_type]['searchParams']
        make_pred = partial(self.make_pred_from_param,
                            resource_type,
                            possible_param_types=valid_search_params) 
        predicates = [pred for pred in map(make_pred, iterdict(params))
                if pred is not None]
    
        # customized coordinate search parameter
        if 'coordinate' in params and resource_type == 'Sequence':
            coords = params['coordinate'].split(',') 
            coord_preds = map(make_coord_pred, coords)
            query_args.append(db.or_(*coord_preds))
        if len(predicates) > 0:
            query_args.append(
                Resource.resource_id.in_(intersect_predicates(predicates).alias())) 
        if '_id' in params:
            query_args.append(Resource.resource_id.in_(params['_id'].split(',')))

        if id_only:
            return db.select([Resource.resource_id]).\
                                    select_from(Resource).\
                                    where(db.and_(*query_args)).alias()
        else: 
            return Resource.query.filter(*query_args)
예제 #3
0
파일: logview.py 프로젝트: mmspide/wahh
def ajax():
    start_time = request.form.get('start_time')
    end_time = request.form.get('end_time')
    select_method = request.form.get('select_method')
    mod_type = request.form.get('mod_type')
    r = select(start_time, end_time, select_method, mod_type)
    count = len(r)
    result = waf_log_json(r, count)
    return json.dumps(result)
예제 #4
0
    def build_query(self, resource_type, params, id_only=False):
        '''
        Compile a SQL query from a set of FHIR search params
        
        If `id_only` is true, a SQL query that selects only `resource_id` will be returned
        '''

        query_args = [
            Resource.visible == True,
            Resource.resource_type == resource_type,
            #Resource.owner_id == self.owner_id or Resource.owner_id=='0'
        ]
        valid_search_params = SPECS[resource_type]['searchParams']

        make_pred = partial(self.make_pred_from_param,
                            resource_type,
                            possible_param_types=valid_search_params)

        predicates = [
            pred for pred in map(make_pred, iterdict(params))
            if pred is not None
        ]
        #print params
        # customized coordinate search parameter
        if 'coordinate' in params and resource_type == 'Sequence':
            coords = params['coordinate'].split(',')
            coord_preds = map(make_coord_pred, coords)
            query_args.append(db.or_(*coord_preds))

        if len(predicates) > 0:
            query_args.append(
                Resource.resource_id.in_(
                    intersect_predicates(predicates).alias()))
        if '_id' in params:
            query_args.append(
                Resource.resource_id.in_(params['_id'].split(',')))

        if id_only:
            return db.select([Resource.resource_id]).\
                                    select_from(Resource).\
                                    where(db.and_(*query_args)).alias()

        else:
            return Resource.query.filter(*query_args)
예제 #5
0
파일: detector.py 프로젝트: hugiron/indor
async def get_camera_id(detector_id):
    camera_id_query = db.select([Camera.id]) \
        .order_by(Camera.last_update.asc()) \
        .where(db.and_(Camera.detector_id == 0,
                       Camera.status == True,
                       Camera.is_complete == False)) \
        .limit(1)
    status, result = await Camera.update \
        .values(detector_id=detector_id) \
        .where(Camera.id == camera_id_query) \
        .gino \
        .status()
    if status == 'UPDATE 0':
        return None
    camera = await db.select([Camera.id])\
        .where(db.and_(Camera.detector_id == detector_id,
                       Camera.is_complete == False))\
        .gino\
        .model(Camera)\
        .first()
    return camera.id
예제 #6
0
PARAM_RE = re.compile(
    r'(?P<param>[^\.:]+)(?::(?P<modifier>[^\.:]+))?(?:\.(?P<chained_param>.+))?'
)
COMPARATOR_RE = r'(?P<comparator><|<=|>|>=)'
REFERENCE_RE = re.compile(
    r'(?:(?P<extern_base>.+/))?(?P<resource_type>.+)/(?P<resource_id>.+)')
TOKEN_RE = re.compile(r'(?:(?P<system>.+)?\|)?(?P<code>.+)')
NUMBER_RE = re.compile(r'%s?(?P<number>\d+(?:\.\d+)?)' % COMPARATOR_RE)
QUANTITY_RE = re.compile(r'%s\|(?P<system>.+)?\|(?P<code>.+)?' %
                         NUMBER_RE.pattern)
DATE_RE = re.compile(r'%s?(?P<date>.+)' % COMPARATOR_RE)
COORD_RE = re.compile(r'(?P<chrom>.+):(?P<start>\d+)-(?P<end>\d+)')
# there are two types of modifier: Resource modifier and others...
NON_TYPE_MODIFIERS = ['missing', 'text', 'exact']
# select helper
SELECT_FROM_SEARCH_PARAM = db.select([SearchParam.resource_id
                                      ]).select_from(SearchParam)


class InvalidQuery(Exception):
    '''
    We use this to capture an invalid query
    so that we can return a HTTP 400 as required by FHIR's specs.
    '''
    pass


def intersect_predicates(predicates):
    '''
    helper function to intersect a set of predicates
    '''
    return db.intersect(
예제 #7
0
from functools import partial
import re

# REs used to parse FHIR's crazily complex search parameters 
PARAM_RE = re.compile(r'(?P<param>[^\.:]+)(?::(?P<modifier>[^\.:]+))?(?:\.(?P<chained_param>.+))?')
COMPARATOR_RE = r'(?P<comparator><|<=|>|>=)'
REFERENCE_RE = re.compile(r'(?:(?P<extern_base>.+/))?(?P<resource_type>.+)/(?P<resource_id>.+)')
TOKEN_RE = re.compile(r'(?:(?P<system>.+)?\|)?(?P<code>.+)')
NUMBER_RE = re.compile(r'%s?(?P<number>\d+(?:\.\d+)?)'% COMPARATOR_RE)
QUANTITY_RE = re.compile(r'%s\|(?P<system>.+)?\|(?P<code>.+)?'% NUMBER_RE.pattern)
DATE_RE = re.compile(r'%s?(?P<date>.+)' % COMPARATOR_RE)
COORD_RE = re.compile(r'(?P<chrom>.+):(?P<start>\d+)-(?P<end>\d+)') 
# there are two types of modifier: Resource modifier and others...
NON_TYPE_MODIFIERS = ['missing', 'text', 'exact'] 
# select helper
SELECT_FROM_SEARCH_PARAM = db.select([SearchParam.resource_id]).select_from(SearchParam)


class InvalidQuery(Exception):
    '''
    We use this to capture an invalid query
    so that we can return a HTTP 400 as required by FHIR's specs.
    '''
    pass 


def intersect_predicates(predicates):
    '''
    helper function to intersect a set of predicates
    '''
    return db.intersect(*[SELECT_FROM_SEARCH_PARAM.where(pred)