def post(self): data = request.get_json(force=True) categoria_id = data['categoria_id'] scategorias = sCategorias( categoria_id=categoria_id) # se llaman a los servicios try: retorno = scategorias.SP_GET_CATEGORIES( ) # Se obtienen las categorias. # category_Tree = self.__Generar_Arbol_Categorias(retorno) # se asocian las categorias y se convierten a un json. #Se define el metodo del retorno response objectoJson = {'Mensaje': None, 'Resultados': []} if (categoria_id is not None): objectoJson['Mensaje'] = 'Proceso exitoso' objectoJson['Resultados'] = retorno _json = json.dumps(objectoJson) _response = response(_json, status=200, mimetype='application/json') _response.headers['Access-Control-Allow-Origin'] = '*' else: objectoJson['Mensaje'] = 'Hubo un error' _json = json.dumps(objectoJson) _response = response(_json, status=400, mimetype='application/json') return _response except Exception as exp: print(exp) return {'Mensaje': 'Problema interno'}, 500
def get(self): scategorias = sCategories() # se llaman a los servicios try: retorno = scategorias.GET_CATEGORIES() # Se obtienen las categorias. #Se define el metodo del retorno response array = [] for row in retorno: array.append(row) objectoJson = {'Mensaje': None, 'Resultados': []} if (retorno is not None): objectoJson['Mensaje'] = 'Proceso exitoso' objectoJson['Resultados'] = array _json = json.dumps(objectoJson) _response = response(_json, status=200, mimetype='application/json') _response.headers['Access-Control-Allow-Origin'] = '*' else: objectoJson['Mensaje'] = 'Hubo un error' _json = json.dumps(objectoJson) _response = response(_json, status=400, mimetype='application/json') return _response except Exception as exp: print(exp) return {'Mensaje': 'Problema interno'}, 500
def get(self): args = self.__parser.parse_args() usuario_id = args['id'] s_usuario = sGet_Data_Usuario(usuario_id=usuario_id) # se llaman a los servicios try: retorno = s_usuario.SP_GET_USUARIOS() # Se obtienen las categorias. #Se define el metodo del retorno response if (retorno is not None): buildJSON = self._generate_json_usuario(retorno,usuario_id) __return = response(json.dumps({"status":"success",'result':buildJSON }),status=200, mimetype='application/json') __return.headers['Access-Control-Allow-Origin'] = '*' __return.headers['Access-Control-Allow-Methods'] = 'POST' __return.headers['Allow'] = 'POST' return __return else: __return = response(json.dumps({"status":"error",'result': 'usuario no encontrado'}),status=400, mimetype='application/json') __return.headers['Access-Control-Allow-Origin'] = '*' __return.headers['Access-Control-Allow-Methods'] = 'POST' __return.headers['Allow'] = 'POST' return __return except Exception as px: print(px) __return = response({'Error':'Hubo un error interno'},status=400, mimetype='application/json') __return.headers['Access-Control-Allow-Origin'] = '*' __return.headers['Access-Control-Allow-Methods'] = 'POST' __return.headers['Allow'] = 'POST' return __return
def get(self): args = self.__parser.parse_args() Producto_id = args['id'] with conn: query = """select descripcion_Pregunta,respuesta,fecha_respuesta from DBKiero_Productos.dbo.preguntas_kiero where Producto_id = {Producto_id}""".format( Producto_id=Producto_id) crsr = conn.execute(query) rows = crsr.fetchall() crsr.fast_executemany = True try: if rows: buildqa = self._build_qa(rows=rows) buildJSON = {"code": 1, "message": buildqa} __return = response(json.dumps({ "status": "success", 'result': buildJSON }), status=200, mimetype='application/json') __return.headers['Access-Control-Allow-Origin'] = '*' __return.headers['Access-Control-Allow-Methods'] = 'POST' __return.headers['Allow'] = 'POST' return __return else: obj_json = {"code": 0, "message": "producto sin preguntas"} __return = response(json.dumps({ "status": "success", 'result': obj_json }), status=200, mimetype='application/json') __return.headers['Access-Control-Allow-Origin'] = '*' __return.headers['Access-Control-Allow-Methods'] = 'POST' __return.headers['Allow'] = 'POST' return __return except Exception as px: print(px) __return = response({'Error': 'Hubo un error interno'}, status=400, mimetype='application/json') __return.headers['Access-Control-Allow-Origin'] = '*' __return.headers['Access-Control-Allow-Methods'] = 'POST' __return.headers['Allow'] = 'POST' return __return
def post(self): data = request.get_json() try: name = data['name'] lastname = data['lastname'] email = data['email'] idGoogle = data['idGoogle'] email_status = 0 status = 1 nickname = data['nickname'] except Exception: return "Envie todos los datos correctamente" try: retorno2 = users().VALIDATE_USER(email=email) if retorno2: print("usuario registrado") return "usuario registrado" retorno = users().INSERT_USER(name=name,lastname=lastname, email=email,idGoogle=idGoogle,email_status=email_status,status=status,nickname=nickname) objectoJson = {} objectoJson['Mensaje'] = 'Proceso exitoso' objectoJson['Resultados'] = str(retorno) _json = json.dumps(objectoJson) _response = response(_json,status=200, mimetype='application/json') _response.headers['Access-Control-Allow-Origin'] = '*' return _response except Exception as err: print(err)
def post(self): try: data = request.get_json(force=True) questions = data['questions'] id_Estado = 1 id_Usuario= data['id_Usuario'] Producto_id=data['Producto_id'] except Exception as err: return {'status':'success','result':{'code':0,'message':'envie los parametros correspondientes'}} try: with conn: query = """ insert into preguntas_kiero (fecha_Creacion,descripcion_Pregunta,id_Estado,id_Usuario,Producto_id) VALUES ('{fecha_Creacion}','{descripcion_Pregunta}',{id_Estado},{id_Usuario},{Producto_id})""".format(fecha_Creacion=get_today,descripcion_Pregunta=questions,id_Estado=id_Estado,id_Usuario=id_Usuario,Producto_id=Producto_id) crsr = conn.execute(query) crsr.fast_executemany = True buildJSON = {"code":1,"message":"Pregunta creada satisfactoriamente"} __return = response(json.dumps({"status":"success",'result':buildJSON }),status=200, mimetype='application/json') __return.headers['Access-Control-Allow-Origin'] = '*' __return.headers['Access-Control-Allow-Methods'] = 'POST' __return.headers['Allow'] = 'POST' return __return except Exception as px: print(px) json_response = {'code':0,'message':'problema interno'} __return = response({'status':'error','result':json_response},status=400, mimetype='application/json') __return.headers['Access-Control-Allow-Origin'] = '*' __return.headers['Access-Control-Allow-Methods'] = 'POST' __return.headers['Allow'] = 'POST' return __return
def get(self): # queryExec = sRandom_Products().BRING_RANDOM_PRODUCTS_BY_CATEGORIES() # print(queryExec[0]) # rt = [] objectoJson = {} db = self.__conn.kiero # Created or Switched to collection names collection = db.products_sliders_5 #products3 db_category = self.__conn.public_categories collection_category = db_category.category try: random_category = collection.aggregate([{ '$match': { 'Categoria_id': { '$exists': True } } }, { "$sample": { "size": 1 } }]) for category in random_category: category = (category['Categoria_id']) cursor = collection.aggregate([{ '$match': { 'Categoria_id': str(category) } }, { "$sample": { "size": 8 } }]) random_products = [] for row in cursor: random_products.append(row) random_products = self.create(random_products) if random_products: buildJSON = { "code": 1, "message": "productos encontrados satisfactoriamente", 'random_products': random_products } __return = response(json.dumps({ "status": "success", 'result': buildJSON }), status=200, mimetype='application/json') __return.headers['Access-Control-Allow-Origin'] = '*' __return.headers['Access-Control-Allow-Methods'] = 'POST' __return.headers['Allow'] = 'POST' return __return else: buildJSON = {"code": 0, "message": "Algo salio mal"} __return = response(json.dumps({ "status": "success", 'result': buildJSON }), status=200, mimetype='application/json') __return.headers['Access-Control-Allow-Origin'] = '*' __return.headers['Access-Control-Allow-Methods'] = 'POST' __return.headers['Allow'] = 'POST' return __return # for data in queryExec: # data['precio'] = str(data['precio']) # data['imagenes_Productos'] = str(data['imagenes_Productos']).split('~^~') # rt.append(data) except Exception as err: print(err) objectoJson['Mensaje'] = 'Hubo un error' objectoJson['Resultados'] = str(err) _json = json.dumps(objectoJson) _response = response(_json, status=500, mimetype='application/json') _response.headers['Access-Control-Allow-Origin'] = '*' return _response
def post(self): data = request.get_json() # registrar = sRegistro(usuario_id=usuario_id) # se llaman a los servicios random_data = os.urandom(128) string_random = hashlib.md5(random_data).hexdigest()[:32] with conn: query = """select top(1) email from users where email = '{comprobar_email}'""".format(comprobar_email=data['email']) crsr = conn.execute(query) rows = crsr.fetchone() crsr.fast_executemany = True if rows is None: try: name = data['name'] lastname = data['lastname'] email = data['email'] password = sha256.hash(data['password']) nickname = name+str(random.randint(60000, 100000)) source_ip = request.remote_addr email_status=0 status = 1 token_confirmation_email = string_random new_user = [email,password] access_token = create_access_token(identity = data['email']) refresh_token = create_refresh_token(identity = data['email']) with conn: new_user_save = """insert into users (name,lastname,nickname, email,password,source_ip,email_status,status,create_at,token_confirmation_email,email_confirmation_sent_on) values ('{name}','{lastname}','{nickname}','{email}','{password}','{source_ip}',{email_status},{status},'{date}','{token_confirmation_email}','{email_confirmation_sent_on}')""".format(name=name,lastname=lastname,nickname=nickname,email=email,password=password,source_ip=source_ip,email_status=email_status,status=status,date=get_today,token_confirmation_email=token_confirmation_email,email_confirmation_sent_on=get_today) conn.execute(new_user_save) crsr.fast_executemany = True try: msg = Message('Pregunta registrada', sender = '*****@*****.**', recipients = ['*****@*****.**', '*****@*****.**','*****@*****.**']) msg.body = """ Nuevo usuario registrado: Nombre: {name} {lastname} email: {email} fecha: {datetime_re} """.format(name=name,lastname=lastname,email=email,datetime_re=today) mail.send(msg) except Exception as unErr: print(unErr) data_email_confirmation =str(token_confirmation_email) +'~^~'+ str(date_time[0]) # token_email = AES_Encryption().encrypt(data_email_confirmation) buildConfirmationLink = "https://www.kiero.co/confirmation_email.html?{token_email}".format(token_email=token_confirmation_email) try: with app.app_context(): msg = Message(subject="Correo de confirmación", sender=app.config.get("MAIL_USERNAME"), recipients=[email], # use your email for testing body=""" correo = {email} Este es el correo de confirmación, copie el siguiente link y peguelo en el buscador de su navegador favorito {url} """.format(email=email,url=buildConfirmationLink)) mail.send(msg) except Exception as err: print(err) buildJSON = { 'message': 'El usuario {} a sido creado'.format(data['email']), 'access_token': access_token, 'refresh_token': refresh_token } __return = response(json.dumps({"status":1,'result':buildJSON }),status=200, mimetype='application/json') __return.headers['Access-Control-Allow-Origin'] = '*' __return.headers['Access-Control-Allow-Methods'] = 'POST' __return.headers['Allow'] = 'POST' return __return except Exception as err: print(err) __return = response({'Error':'Hubo un error interno'},status=400, mimetype='application/json') __return.headers['Access-Control-Allow-Origin'] = '*' __return.headers['Access-Control-Allow-Methods'] = 'POST' __return.headers['Allow'] = 'POST' return __return elif rows[0] == data['email']: return {'status':0 ,'message': 'User {} already exists'.format(data['email'])}