aux.py 1.34 KB
import json
from validation import Validation
from flask import render_template, url_for

def answer(succ, error = None):

  if succ == True:
    return json.dumps({
      "success" : True
    })

  return json.dumps({
    "success" : False,
    "error" : error
  })

COLOR_DEFAULT = "rgb(10,10,200)"

def generate(json):
  try:
    
    if json == None:
      return answer(False, "No hay datos para generar este formulario")

    if 'color' not in json:
      json['color'] = COLOR_DEFAULT

    if 'send' not in json:
      return answer(False, "No hay destino en el formulario => {'send' : 'example.com'}")

    if 'title' not in json:
      return answer(False, "No se ingresó título del formulario => {'title' : 'Título'}")

    return render_template(
      "form.html",
      tabs = json['tabs'],
      title = json['title'],
      color = json['color'],
      send = json['send']
    )

  except:
    return answer(False, "Hay un error en los datos de este formulario")

def validate(data):
  validation = Validation()
  if 'url' in data:
    url = data['url']
    del data['url']
    #r = requests.post(url, json = data)

    #if r.text == "true":
    if True:
      return json.dumps({
        'success' : True,
        'cookie' : validation.make_token(),
      })
    
    else:
      return answer(False,"")
  
  return answer(False,"no validation address")