-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuspas.py
executable file
·116 lines (107 loc) · 3.89 KB
/
uspas.py
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
111
112
113
114
115
116
#!/usr/bin/python2.7
"""
runs on the server, reads form input, prints HTML
"""
import cgi, sys
import mysql.connector
import string
import time
from validate_email import validate_email
from datetime import date
import cgitb
cgitb.enable()
print("Content-type: text/html")
db = mysql.connector.connect(user='root',password='dgi', database='mesh')
cursor = db.cursor()
form = cgi.FieldStorage()
head = """
<!DOCTYPE html>
<html>
<head>
<title>Leaflet.draw vector editing handlers</title>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
"""
fin = """
</body>
</html>
"""
login = """
</head>
<body>
<form method="POST" action="uspas.py" onsubmit="return checkForm(this);">
<fieldset>
<legend>Login</legend>
<p>Username: <input title="Enter your mail has username" type="email" required placeholder="Enter a valid email address" name="username"></p>
<p>Password: <input title="Password must contain at least 6 characters, including UPPER/lowercase and numbers" type="password" name="pwd1" onchange="
this.setCustomValidity(this.validity.patternMismatch ? this.title : '');
if(this.checkValidity()) form.pwd2.pattern = this.value;
"></p>
<p><input type="submit" name="login" value="Login"></p>
<p><input type="submit" name="registrar" value="Register"></p>
</fieldset>
</form>
"""
def printmenu(num):
print("</head>")
print("<body>")
print("<form action='link.py' method='post'>")
print("<input type='hidden' name=sid value=" + str(num) +">")
print("<button type='submit'>Edit Network</button>")
print("<button type='submit' formmethod='post' formaction='link.py'>Run Network</button>")
print("</form>")
print("<form action='uspas.py' method='post'>")
print("<button type='submit'>Return to login</button>")
print("</form>")
registrar = """
</head>
<body>
<form method="POST" action="uspas.py" onsubmit="return checkForm(this);">
<fieldset>
<legend>Register</legend>
<p>Username: <input title="Enter your mail has username" type="email" required placeholder="Enter a valid email address" name="username"></p>
<p>Password: <input title="Password must contain at least 6 characters, including UPPER/lowercase and numbers" type="password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}" name="pwd1" onchange="
this.setCustomValidity(this.validity.patternMismatch ? this.title : '');
if(this.checkValidity()) form.pwd2.pattern = this.value;
"></p>
<p>Confirm Password: <input title="Please enter the same Password as above" type="password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}" name="pwd2" onchange="
this.setCustomValidity(this.validity.patternMismatch ? this.title : '');
"></p>
<p><input type="submit" name="register" value="Register"></p>
</fieldset>
</form>
"""
print(head)
if 'registrar' in form:
print(registrar)
elif 'register' in form:
email = form['username'].value
if validate_email(email,verify=True):
data =(form['username'].value,form['pwd1'].value,3,date.today())
insert_stmt = (
"INSERT INTO usuarios (mail,password,level,fecha) "
"VALUES (%s, %s, %s, %s)")
cursor.execute(insert_stmt,data)
db.commit()
print(login)
else:
print("<p><font color='red'>Mail not exist try again register</font></p>")
print(registrar)
elif 'login' in form:
data =form['username'].value
cursor.execute ("SELECT password,numero FROM usuarios WHERE mail = '%s'" %(data))
pasnum = cursor.fetchone()
if pasnum != None:
passw,num = pasnum
if passw == form['pwd1'].value:
printmenu(num)
else:
print("<p><font color='red'>Bad password, try again if not have username register</font></p>")
print(login)
else:
print("<p><font color='red'>Bad username, try again if not have username register</font></p>")
print(login)
elif 'sid' in form:
printmenu(form['sid'].value)
else:
print(login)
print(fin)