-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage_users.py
78 lines (73 loc) · 3.91 KB
/
manage_users.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
from base_handler import *
import cgi
import MySQLdb
from google.appengine.api import users
import os
class ManageUsers(BaseHandler):
def get(self,id):
user = users.get_current_user()
if user:
email = user.email()
if (os.getenv('SERVER_SOFTWARE') and os.getenv('SERVER_SOFTWARE').startswith('Google App Engine/')):
db = MySQLdb.connect(unix_socket='/cloudsql/hack-the-north-1:its-not-django', db='musicsite', user='root')
else:
db = MySQLdb.connect(host='localhost', user='root', passwd="htndjango",db="musicsite")
self.response.write('<a href="/communities"><button>Return to Community list</button></a><br>')
self.response.write('<a href="/communities/%s"><button>Go to Community</button></a><br>'%id)
self.response.write('<form action="" method="post"><input type="hidden" name="leaveboolean" value="1"><input type="submit" value="Leave community"></form>')
cursor = db.cursor()
cursor.execute('SELECT * FROM users WHERE email = "%s" AND invite_accepted=1 AND community_id=%s'%(email,id))
if (cursor.rowcount == 0):
self.redirect('/communities')
else:
cursor.execute('SELECT name FROM communities WHERE id = %s'%id)
community_name = ""
for row in cursor:
community_name = row[0]
self.response.write('Add new user email: <form action="" method="post"><input type="hidden" name="community_name" value="%s"><input type="text" name="email"><input type="submit" value="Add User"></form>'%community_name)
cursor.execute('SELECT email FROM users WHERE community_id = %s'%id)
self.response.write("Current members in %s:"%community_name)
for row in cursor:
self.response.write('<br>%s' % (row[0]))
else:
self.redirect('/communities')
def post(self,id):
user = users.get_current_user()
if user:
email = user.email()
if (os.getenv('SERVER_SOFTWARE') and os.getenv('SERVER_SOFTWARE').startswith('Google App Engine/')):
db = MySQLdb.connect(unix_socket='/cloudsql/hack-the-north-1:its-not-django', db='musicsite', user='root')
else:
db = MySQLdb.connect(host='localhost', user='root', passwd="htndjango",db="musicsite")
cursor = db.cursor()
cursor.execute('SELECT * FROM users WHERE email = "%s" AND invite_accepted=1 AND community_id=%s'%(email,id))
if (cursor.rowcount == 0):
self.redirect('/communities')
else:
leavestatus = cgi.escape(self.request.get('leaveboolean'))
community_id = cgi.escape(self.request.get('id'))
if (leavestatus == "1"):
self.response.write("You have left this community.<br><a href='/communities'><button>Return to Communities</button></a>")
cursor = db.cursor()
cursor.execute('UPDATE users SET invite_hidden=1, invite_accepted=0 WHERE community_id = %s AND email = "%s"' % (id,email))
db.commit()
else:
self.response.write('<a href="/communities"><button>Return to Community list</button></a><br>')
self.response.write('<a href="/communities/%s"><button>Go to Community</button></a><br>'%id)
self.response.write('<form action="" method="post"><input type="hidden" name="leaveboolean" value="1"><input type="submit" value="Leave community"></form>')
email = cgi.escape(self.request.get('email'))
self.response.write('%s has been invited!<br><br>' % email)
cursor = db.cursor()
cursor.execute('SELECT name FROM communities WHERE id = %s'%id)
community_name = ""
for row in cursor:
community_name = row[0]
cursor.execute('INSERT INTO users VALUES (%s,"%s","%s","%s",0,0)'%(id,community_name,email,email))
db.commit()
self.response.write('Add new user email: <form action="" method="post"><input type="hidden" name="community_name" value="%s"><input type="text" name="email"><input type="submit" value="Add User"></form>'%community_name)
cursor.execute('SELECT email FROM users WHERE community_id = %s'%id)
self.response.write("Current members in %s:"%community_name)
for row in cursor:
self.response.write('<br>%s' % (row[0]))
else:
self.redirect('/communities')