-
Notifications
You must be signed in to change notification settings - Fork 1
/
login.py
executable file
·93 lines (76 loc) · 2.58 KB
/
login.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
#!/usr/bin/python2
import config
import header
import cgi,commands,os,MySQLdb
import Cookie
db = MySQLdb.connect("localhost","root", "Aj1.....", "arcus")
cursor = db.cursor()
if(os.environ['REQUEST_METHOD'] == "POST"):
username = cgi.FormContent()['username'][0]
password = cgi.FormContent()['password'][0]
form = cgi.FieldStorage()
if(form.getvalue('new')):
query = "INSERT INTO users(username,password) VALUES('{0}','{1}')". format(username,password)
try:
cursor.execute(query)
db.commit()
last = cursor.lastrowid
c = Cookie.SimpleCookie()
c['id'] = last
print c
if('HTTP_REFERER' in os.environ):
print("Location:{0}\r\n\r\n". format(os.environ['HTTP_REFERER']))
else:
print("Location:/")
#print ""
except:
header.header_content()
print("Username already exist.")
db.rollback()
else:
query = "SELECT * FROM users WHERE username = '{0}'". format(username)
try:
cursor.execute(query)
results = cursor.fetchone()
if(results>0 and password == results[2]):
c = Cookie.SimpleCookie()
c['id'] = results[0]
print c
print("Location:{0}\r\n\r\n". format(os.environ['HTTP_REFERER']))
else:
header.header_content()
print("wrong password")
except:
header.header_content()
print "Error: unable to fecth data"
elif(os.environ['REQUEST_METHOD'] == "GET"):
header.header_content()
#print(os.environ)
print """
<div class="login-dark">
<form action="/login.py" method="POST">
<h2>Login Form</h2>
<div class="illustration"><i class="icon ion-ios-locked-outline"></i></div>
<div class="form-group">
<input class="form-control" type="text" name="username" placeholder="USERNAME">
</div>
<div class="form-group">
<input class="form-control" type="password" name="password" placeholder="PASSWORD">
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="new">SIGN-UP</label>
</div>
<div class="form-group">
<button class="btn btn-primary btn-block" type="submit">LOG-IN </button>
</div>
</form>
</div>
<script src="/js/jquery.min.js"></script>
<script src="/bootstrap/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap.min.js"></script>
<script src="/js/script.min.js"></script>
</body>
</html>
"""