def fulfill(session): r = db['advertisers'].find_one({'pending_request.session':session}) if(r is not None): r = r['pending_request'] db['advertisers'].update({'user':r['author']},{'$push':{'request':r}}) Request.from_json(r).sendmail() else: print('r was none')
def before_request_func(): g.request_params = request.args if request.method == 'GET' else request.form g.cookies_disabled = False # Generate session values for user if unavailable if not valid_user_session(session): session['config'] = json.load(open(app.config['DEFAULT_CONFIG'])) \ if os.path.exists(app.config['DEFAULT_CONFIG']) else {'url': request.url_root} session['uuid'] = str(uuid.uuid4()) session['fernet_keys'] = generate_user_keys(True) # Flag cookies as possibly disabled in order to prevent against # unnecessary session directory expansion g.cookies_disabled = True if session['uuid'] not in app.user_elements: app.user_elements.update({session['uuid']: 0}) # Always redirect to https if HTTPS_ONLY is set (otherwise default to False) https_only = os.getenv('HTTPS_ONLY', False) if https_only and request.url.startswith('http://'): return redirect(request.url.replace('http://', 'https://', 1), code=308) g.user_config = Config(**session['config']) if not g.user_config.url: g.user_config.url = request.url_root.replace( 'http://', 'https://') if https_only else request.url_root g.user_request = Request(request.headers.get('User-Agent'), language=g.user_config.lang) g.app_location = g.user_config.url
def viewrequest(): prof = db['influencers'].find_one({'user': request.args.get('user')})['request'] if type(prof) is not dict: try: prof = prof[int(request.args.get('r'))] except: return render_template('no_ads.html') r = Request(budget=prof['budget'], link=prof['link'], tags=prof['tags'], contact=prof['contact'], author=prof['author'], user=request.args.get('user'), r=int(request.args.get('r'))) return redirect('/viewrequest?r=' + str(int(request.args.get('r')) + 1) ) if prof['completed'] == 1 else r.get_render_template()
def create_request(): #Creates a request object from a form submission sess = stripe_payment.payment(request.form['budget']) r = Request(budget=request.form['budget'], link=request.form['note'], tags=unquote(request.args.get('tags')), contact=request.form['contact'], user='', author=current_user.username, session=sess.id) db['advertisers'].update({'user': current_user.username}, {'$set': { 'pending_request': r.get_json() }}) authorize = { 'public_key': auth.auth_data['stripe_auth']['public'], 'CHECKOUT_SESSION_ID': sess.id } return render_template("stripe_payment.html", authori=authorize)
def _set_imoveis(self): data = {'filtro': self._set_filtro()} data['url_tipo'] = 'imoveis' data['tipo'] = 'get' self.__imoveis = Request(self.__uteis).request(data) if not len(self.__imoveis['itens']['itens']): message = 'Nenhum imovel para este id_contato: {}'.format( self.contato['id']) self.log_error(message) raise ImoveisInvalido(message)
def before_request_func(): g.user_request = Request(request.headers.get('User-Agent')) g.user_config = json.load( open(CONFIG_PATH)) if os.path.exists(CONFIG_PATH) else { 'url': request.url_root } if 'url' not in g.user_config or not g.user_config['url']: g.user_config['url'] = request.url_root g.app_location = g.user_config['url']
def set_contatos(self): data = self._get_filtro() data['url_tipo'] = 'contatos' data['tipo'] = 'get' self.__contatos = Request(self.__uteis).request(data) if self.itens: return True else: message = 'Nenhum contato retornado' self.log_error(message) # raise ContatosInvalido(message) return False
def createcampaign(): desc = request.form['desc'] #platforms = request.form['platform'] sess = stripe_payment.payment(request.form['budget']) r = Request( budget=request.form['budget'], link=request.form['link'], tags=desc, contact=request.form['contact'], user='', #platforms=platforms, author=current_user.username, session=sess.id) db['advertisers'].update({'user': current_user.username}, {'$set': { 'pending_request': r.get_json() }}) authorize = { 'public_key': auth.auth_data['stripe_auth']['public'], 'CHECKOUT_SESSION_ID': sess.id } return render_template("stripe_payment.html", authori=authorize)
def before_request_func(): json_config = json.load( open(CONFIG_PATH)) if os.path.exists(CONFIG_PATH) else { 'url': request.url_root } g.user_config = Config(**json_config) if not g.user_config.url: g.user_config.url = request.url_root g.user_request = Request(request.headers.get('User-Agent'), language=g.user_config.lang) g.app_location = g.user_config.url
def before_request_func(): g.request_params = ( request.args if request.method == 'GET' else request.form ) # Skip pre-request actions if verifying session if '/session' in request.path and not valid_user_session(session): return default_config = json.load(open(app.config['DEFAULT_CONFIG'])) \ if os.path.exists(app.config['DEFAULT_CONFIG']) else {} # Generate session values for user if unavailable if (not valid_user_session(session) and 'cookies_disabled' not in request.args): session['config'] = default_config session['uuid'] = str(uuid.uuid4()) session['key'] = generate_user_key() # Skip checking for session on any searches that don't # require a valid session if (not Endpoint.autocomplete.in_path(request.path) and not Endpoint.healthz.in_path(request.path)): return redirect(url_for( 'session_check', session_id=session['uuid'], follow=get_request_url(request.url)), code=307) else: g.user_config = Config(**session['config']) elif 'cookies_disabled' not in request.args: # Set session as permanent session.permanent = True app.permanent_session_lifetime = timedelta(days=365) g.user_config = Config(**session['config']) else: # User has cookies disabled, fall back to immutable default config session.pop('_permanent', None) g.user_config = Config(**default_config) if not g.user_config.url: g.user_config.url = get_request_url(request.url_root) g.user_request = Request( request.headers.get('User-Agent'), get_request_url(request.url_root), config=g.user_config) g.app_location = g.user_config.url
def before_request_func(): # Always redirect to https if HTTPS_ONLY is set (otherwise default to false) https_only = os.getenv('HTTPS_ONLY', False) if https_only and request.url.startswith('http://'): url = request.url.replace('http://', 'https://', 1) code = 308 return redirect(url, code=code) json_config = json.load(open(CONFIG_PATH)) if os.path.exists(CONFIG_PATH) else {'url': request.url_root} g.user_config = Config(**json_config) if not g.user_config.url: g.user_config.url = request.url_root.replace('http://', 'https://') if https_only else request.url_root g.user_request = Request(request.headers.get('User-Agent'), language=g.user_config.lang) g.app_location = g.user_config.url
def auth(self, request): try: credentials = Request(request).data credentials["password"] = hashlib.md5( credentials["password"]).hexdigest() query = translate(UsuarioSerializer, credentials) except KeyError: return Response({}, status.HTTP_400_BAD_REQUEST, "Envio erroneo de parametros") try: usuarios = Usuario.objects.filter(**query) if usuarios.count() is not 1: raise ObjectDoesNotExist except ObjectDoesNotExist: return Response({}, status.HTTP_404_NOT_FOUND, "No se encontro el usuario") token = Token.getToken(UsuarioSerializer(usuarios[0]).data) return Response({'token': token})
def get_cidades(self, ids): data = {'filtro': {}} data['filtro']['ids'] = ids data['url_tipo'] = 'cidades_in' data['tipo'] = 'get' cidades = Request(self.__uteis).request(data) if len(cidades): for cidade in cidades: self.__cidades[cidade['id']] = { 'logo': cidade['topo'], 'titulo': cidade['nome'], 'link': cidade['link'], 'portal': cidade['portal'], 'menu': cidade['menu'] } if len(cidades) != len(ids.split(',')): message = 'Uma ou mais cidades não encontradas com os ids: {}'.format( ids) self.log_error(message) return True message = 'Nenhuma cidade encontrada com os ids: {}'.format(ids) self.log_error(message) return False
def test_request_error(uteis_localhost, data_contatos_tipo_errado): request = Request(uteis_localhost) with pytest.raises(RequestInvalido): print(request.request(data_contatos_tipo_errado))
from app.request import Request from app.uteis import Uteis uteis = Uteis(['localhost']) uteis.set_keys() request = Request(uteis) data = {'filtro': {}} data['filtro']['limit'] = 5 data['filtro']['dias'] = 60 data['url_tipo'] = 'contatos' data['tipo'] = 'get' request = request.request(data) print(request)
def before_request_func(): global bang_json # Check for latest version if needed now = datetime.now() if now - timedelta(hours=24) > app.config['LAST_UPDATE_CHECK']: app.config['LAST_UPDATE_CHECK'] = now app.config['HAS_UPDATE'] = check_for_update( app.config['RELEASES_URL'], app.config['VERSION_NUMBER']) g.request_params = ( request.args if request.method == 'GET' else request.form ) # Skip pre-request actions if verifying session if '/session' in request.path and not valid_user_session(session): return default_config = json.load(open(app.config['DEFAULT_CONFIG'])) \ if os.path.exists(app.config['DEFAULT_CONFIG']) else {} # Generate session values for user if unavailable if (not valid_user_session(session) and 'cookies_disabled' not in request.args): session['config'] = default_config session['uuid'] = str(uuid.uuid4()) session['key'] = generate_user_key() # Skip checking for session on any searches that don't # require a valid session if (not Endpoint.autocomplete.in_path(request.path) and not Endpoint.healthz.in_path(request.path) and not Endpoint.opensearch.in_path(request.path)): return redirect(url_for( 'session_check', session_id=session['uuid'], follow=get_request_url(request.url)), code=307) else: g.user_config = Config(**session['config']) elif 'cookies_disabled' not in request.args: # Set session as permanent session.permanent = True app.permanent_session_lifetime = timedelta(days=365) g.user_config = Config(**session['config']) else: # User has cookies disabled, fall back to immutable default config session.pop('_permanent', None) g.user_config = Config(**default_config) if not g.user_config.url: g.user_config.url = get_request_url(request.url_root) g.user_request = Request( request.headers.get('User-Agent'), get_request_url(request.url_root), config=g.user_config) g.app_location = g.user_config.url # Attempt to reload bangs json if not generated yet if not bang_json and os.path.getsize(app.config['BANG_FILE']) > 4: try: bang_json = json.load(open(app.config['BANG_FILE'])) except json.decoder.JSONDecodeError: # Ignore decoding error, can occur if file is still # being written pass
def test_deve_retornar_variavel_com_id_quando_put(uteis_localhost,data_cadastro_put): request = Request(uteis_localhost) valor = request.get_tipo(data_cadastro_put['url_tipo'], data_cadastro_put) url = '{}contatos_site_sincronizado/'.format(uteis_localhost.uri) assert valor == url
def test_deve_fazer_update_quando_enviado_id_valido_valor_des(uteis_localhost, data_cadastro_put_up_des): request = Request(uteis_localhost) assert request.request(data_cadastro_put_up_des)
def test_deve_retornar_url_localhost_quando_uteis_localhost(uteis_localhost): request = Request(uteis_localhost) uri = 'http://localhost:5000/' assert request.uri == uri
def test_nao_deve_ter_keys_quando_programacao(uteis_programacao): request = Request(uteis_programacao) with pytest.raises(KeysInvalido): request.set_auth()
def test_deve_retornar_url_contatos_quando_get_tipo_contatos(uteis_localhost): request = Request(uteis_localhost) uri = 'http://localhost:5000/get_contatos/' assert request.get_tipo('contatos',{}) == uri
def test_deve_retornar_url_false_quando_get_tipo_invalido(uteis_localhost): request = Request(uteis_localhost) assert not request.get_tipo('',{})
def test_deve_retornar_url_contatos_quando_get_tipo_contatos(uteis_localhost): request = Request(uteis_localhost) uri = 'http://imoveis.powempresas.com/get_contatos/' assert request.get_tipo('contatos', {}) == uri
def test_deve_retornar_url_imoveismongo_quando_get_tipo_imoveis(uteis_localhost): request = Request(uteis_localhost) uri = 'http://localhost:5000/imoveismongo' assert request.get_tipo('imoveis',{}) == uri
def test_deve_retornar_contatos_quando_request_com_data(uteis_localhost, data_contatos): request = Request(uteis_localhost) contatos = request.request(data_contatos) assert len(contatos)
def before_request_func(): g.user_request = Request(request.headers.get('User-Agent')) g.user_config = json.load( open(CONFIG_PATH)) if os.path.exists(CONFIG_PATH) else {}
def test_deve_retornar_url_quente_quando_uteis_(uteis_): request = Request(uteis_) uri = 'http://imoveis.powempresas.com/' assert request.uri == uri
def test_deve_retornar_auth_object_quando_localhost(uteis_localhost): request = Request(uteis_localhost) request.set_auth() assert request.auth
def update_contato(self, id): data = {'itens': {}} data['itens']['ids'] = id data['url_tipo'] = 'contato_up' data['tipo'] = 'put' return Request(self.__uteis).request(data)
def before_request_func(): g.user_request = Request(request.headers.get('User-Agent'))