deploy.py
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#-*- coding: utf-8 -*-
from flask import Flask, json, request, url_for, render_template
import random
app = Flask(__name__)
TOKEN_LENGHT = 32
TOKEN_STRING = "\
1234567890\
qwertyuiopasdfghjklzxcvbnm\
QWERTYUIOPASDFGHJKLZXCVBNM"
sessions = {}
@app.after_request
def after_request(response):
# headers permitidos para la conversación
response.headers.add('Access-Control-Allow-Headers', '\
Access-Control-Allow-Methods,\
Access-Control-Allow-Origin,\
Content-Type')
# orígenes permitidos para CORS
response.headers.add('Access-Control-Allow-Origin', '*')
# métodos permitidos
response.headers.add('Access-Control-Allow-Methods', 'GET,POST')
return response
def validate(name,psw):
if name == "admin" and psw == "admin":
return True
return False
def token():
result = ""
i = 0
while i < TOKEN_LENGHT:
char = random.randrange(0,len(TOKEN_STRING))
result += str(TOKEN_STRING[char])
i += 1
return result
@app.route('/login', methods = ['POST'])
def login():
data = request.json
if validate(data['name'],data['pass']):
sessions['name'] = token()
return json.dumps({
"error_code" : 0,
"error" : "",
"token" : sessions['name']
})
return json.dumps({
"error_code" : 1,
"error" : "fallo en la validacion",
"token" : None
})
@app.route('/', methods = ['GET', 'POST'])
def main():
data = [
{
"title" : "general",
"fields" : [
{
"title" : "nombre",
"type" : "text",
"placeholder" : "Luciano",
"required" : True
},
{
"title" : "mail",
"type" : "mail",
"placeholder" : "ejemplo@gmail.com",
}
]
},
{
"title" : "detalles",
"fields" : [
{
"title" : "género",
"type" : "select",
"placeholder" : "Gènero",
"options" : [
"Hombre",
"Mujer",
"#other"
]
},
{
"title" : "Gusto",
"type" : "checkbox",
"options" : [
"Hombres",
"Mujeres",
"#other"
],
"required" : True
}
]
},
{
"title" : "third",
"fields" : []
}
]
return render_template("form.html",tabs=data,title="Formulario de Prueba",color="#33aaff")
if __name__ == "__main__":
app.run("0.0.0.0")