示例#1
0
 def get_multiple_route(endpoint=None):
     try:
         key = request.url
         if CacheService.if_any(key):
             message = CacheService.get(key)
         else:
             origin = request.args.get('origin')
             destination = request.args.get('destination')
             timestamp = request.args.get('timestamp')
             waypoints = request.args.get('waypoints', None)
             intersections = request.args.get('intersections', False)
             intersections = intersections != False
             area = request.args.get('area', 'bandung')
             message = RouteService.get_multiple_route(
                 origin=origin,
                 destination=destination,
                 timestamp=timestamp,
                 waypoints=waypoints,
                 area=area,
                 intersections=intersections)
             CacheService.save(key, message)
         response = jsonify(message)
         response.status_code = 200
         return response
     except Exception as exception:
         return handle_error(endpoint=endpoint, e=exception)
示例#2
0
 def hello():
     try:
         message = {'text': 'hello'}
         res_json = json.dumps(message)
         return res_json
     except Exception as exception:
         return handle_error(endpoint=endpoint, e=exception)
  def create_record(endpoint):
    try:
     
      # Step 0: Parse Mobile Client payload (application/json)
      content = request.get_json(silent=True)
      mobileRequestPayload = {
          'code': content.get('code'),
          'sessionCode': content.get('sessionCode')
      }
      LOGGER.info(['mobileRequestPayload', mobileRequestPayload])

      # Basic Auth
      bpId, bp_user_access_token, bp_user_refresh_token, bp_user_access_token_expires_in = BlockpassHandler.basicAuth(
          mobileRequestPayload)
      if bpId == None:
          return jsonify({'err': 500, 'msg': 'basic_auth_failed'}), 500
      
      # -- Check old record has any missing fields.
      #     - Missing fields => request upload data again
      #     - No => return action 'none'
      record = KycRecordModel.find_record_by_blockpassId(bpId)
      if record != None and record.isFullfillRecord():
          return jsonify({
              'nextAction': 'none',
          })
    
      # Step 3: Create new record to store user data
      if record == None:
        record = KycRecordModel()
        record.bpId = bpId

      # store this for further query if need
      record.bpToken = bp_user_access_token
      record.bpRefreshToken = bp_user_refresh_token

      # time token expired at
      now = datetime.datetime.now()
      record.bpExpiredAt = now + datetime.timedelta(milliseconds = bp_user_access_token_expires_in)
      
      # temporary data. Which using later on after user complete upload data
      record.session_code = mobileRequestPayload.get('sessionCode')
      
      # save record
      record.save()

      # one_time_pass to upload data
      one_time_pass = '******' + str(record.id)

      # request mobile app upload data 
      return jsonify({
          'nextAction': 'upload',
          'accessToken': one_time_pass,
          'requiredFields': KycRecordModel.requiredFields(),
          'certs': KycRecordModel.niceToHaveCertificates()
      })

    except Exception as exception:
      return handle_error(endpoint=endpoint, e=exception)
示例#4
0
 def get_events_by_area (endpoint=None):
   try:
     area = request.args.get('area')
     timestamp = request.args.get('timestamp')
     message = EventService.get_events_by_area(area=area, timestamp=timestamp)
     response = jsonify(message)
     response.status_code = 200
     return response
   except Exception as exception:
     return handle_error(endpoint=endpoint, e=exception)
  def status(endpoint):
    try:

      # Step 0: Parse Mobile Client payload (application/json)
      content = request.get_json(silent=True)
      mobileRequestPayload = {
          'code': content.get('code'),
          'sessionCode': content.get('sessionCode', None)
      }
      LOGGER.info(['mobileRequestPayload', mobileRequestPayload])
      
      # Basic Auth
      bpId, bp_user_access_token = BlockpassHandler.basicAuth(
          mobileRequestPayload)
      if bpId == None:
          return jsonify({'err': 500, 'msg': 'basic_auth_failed'}), 500

      # Step 3: Query KycRecord base on bpId
      record = KycRecordModel.find_record_by_blockpassId(bpId)

      if record == None:
        # New User
        message = {
            'status': KycRecordModel.BLOCKPASS_RECORD_STATUS['NOT_FOUND'],
            'identities': KycRecordModel.BLOCKPASS_STATUS_DEFAULT['identities'],
            'certificates': []
        }
        return jsonify(message)
      else:  
        # Old user
        message = {
            'nextAction': 'none',
            'status': KycRecordModel.BLOCKPASS_RECORD_STATUS['APPROVED'],
            'identities': record.generateProfileStatus(),
            'certificates': record.generateCertificateStatus()
        }

        # Notify to Web-page
        session_code = mobileRequestPayload.get('sessionCode')
        if session_code != None:
            BlockpassHandler.ssoComplete(bp_user_access_token, session_code, record)

        return jsonify(message)
      

    except Exception as exception:
      return handle_error(endpoint=endpoint, e=exception)
  def upload(endpoint):
    try:
      # Step 0: Parse Mobile Client payload (application/json)
      fields = request.form
      files = request.files

      one_time_pass = fields.get('accessToken')
      email = fields.get('email')
      selfie = files.get('selfie')
      onfido = fields.get('[cer]onfido')
      onfido_service_cert = fields.get('[cer]onfido-service-cert')
      complyadvantage_service_cert = fields.get('[cer]complyadvantage-service-cert')

      LOGGER.info(['mobileRequestPayload', fields, files])

      # Step 1: check one_time_pass
      tmp = one_time_pass.split(':')
      if tmp[0] != 'ugrly-pass-for-record':
        return jsonify({'err': 403, 'msg': 'one_time_pass_wrong'}), 403

      recordId = tmp[1]

      # Step 2: fill data info KycModel
      record = KycRecordModel.find_record_by_id(recordId)
      record.email = email

      # It is just demo. It better if we store it some-where and just store link in DB
      record.selfie = selfie
      
      print record.session_code
      if record.session_code != None:
          BlockpassHandler.ssoComplete(record.bpToken, record.session_code, record)
          record.session_code = None

    
      # Save it!
      record.save()
  
      return jsonify({
          'nextAction': 'none',
      })

    except Exception as exception:
      return handle_error(endpoint=endpoint, e=exception)