-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore.py
More file actions
89 lines (64 loc) · 2.48 KB
/
Copy pathscore.py
File metadata and controls
89 lines (64 loc) · 2.48 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
from mod_python import apache
import MySQLdb
import hashlib
from operator import itemgetter, attrgetter
def index(req):
#start registration process
#set content type to html
req.content_type = "text/html"
#get the connection information for DB
conn = Connect_To_Database()
#open a connection to the DB server
curs = conn.cursor()
#execute a check to see if
curs.execute("SELECT * FROM PS_Users")
#catch the server response
users = curs.fetchall()
#close connection to database
curs.close()
req.content_type = "text/html"
req.write("<p><html>")
req.write("<p>Score Board <p>")
sorted_users = sorted(users, key=itemgetter(2), reverse=True)
counter = 0
for user in sorted_users:
counter += 1
req.write("<p>" + str(counter) + ". " + str(user[0]) + " with " + str(user[2]) + " points")
return apache.OK
def mysql_password(str):
#This function is identical to the MySQL PASSWORD() function.
pass1 = hashlib.sha1(str).digest()
pass2 = hashlib.sha1(pass1).hexdigest()
return "*" + pass2.upper()
def Connect_To_Database():
#get the settings file and read it in
settings_file = open("/var/www/settings", 'r')
#read settings form the file
for line in settings_file:
settings = []
settings = line.split("=")
if settings[0] == "UserName":
setting_user_name = settings[1].strip("\n")
elif settings[0] == "Password":
setting_password = settings[1].strip("\n")
elif settings[0] == "Database":
setting_database = settings[1].strip("\n")
elif settings[0] == "Host":
setting_host = settings[1].strip("\n")
else:
print "I don't understand parsed setting"
#connect to the Database
conn = MySQLdb.connect(host=setting_host, user=setting_user_name, passwd=setting_password, db=setting_database)
#return the connection settings
return conn
if user_name or user_password in users:
return '<meta http-equiv="refresh" content="0;url=/register/">'
else:
#open a connection to the DB server
curs = conn.cursor()
#execute a check to see if
curs.execute("INSERT INTO PS_Users (User_Name, User_Password, Total_Points) VALUES (%s,%s,%s)",(user_name, user_password, defualt_score))
#commit and close connection to database
conn.commit()
curs.close()
return '<meta http-equiv="refresh" content="0;url=/">'