-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebinterface.py
More file actions
160 lines (147 loc) · 5.64 KB
/
webinterface.py
File metadata and controls
160 lines (147 loc) · 5.64 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# Code was released into the public domain by Darien Caldwell
# http://forums.secondlife.com/showthread.php?t=323981
import cgi
import urllib
import logging
import lindenip
import os
import relations
import time
import datetime
import string
from model import GoogleSLIds
from random import choice
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
head = '''
<html>
<head>
<title>webinterface</title>
<style>
body {
background-color: #000000;
color: #FF0000;
}
input {
background-color: #000000;
color: #FF0000;
outline-color: #000000;
border-color: #FF0000;
}
</style>
</head>
<body>
'''
end = '''
</body>
</html>
'''
form = '''
<form name="username" action="/webinterface/" method="post">
Verify an account you own. Enter your user name:
<input type="text" name="username" />
<input type="submit" value="Submit" />
</form>
'''
def GenVeriCode(length=4, chars=string.letters + string.digits):
return ''.join([choice(chars) for i in range(length)])
class MainPage(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
userid = user.user_id()
q1 = GoogleSLIds.all().filter("google_id =", userid)
q2 = GoogleSLIds.all().filter("google_id =", userid)
q3 = GoogleSLIds.all().filter("google_id =", userid)
if q1.count() == 0:
message = '''
You do not have any SL names linked to this acount. Enter a SL username to be verified. You will get an IM to complte the verifcation.
<br />
'''+form
self.response.out.write(head+message+end)#promt to add name to list
else:
q1.filter("verifed =", True)
if not q1.count() == 0:
message = "Verifed names:<br />"
for x in q1:
message += x.sl_name+"<br />"
av = x.sl_key
subdictown = {}
subdictsecown = {}
ownersubs = relations.getby_subj_type(av, 'owns')
for sub in ownersubs:
id = sub.obj_id
if id not in subdictown:
subdictown[id] = relations.key2name(id)
else:
#delete duplicates
sub.delete()
secownersubs = relations.getby_subj_type(av, 'secowns')
for sub in secownersubs:
id = sub.obj_id
if id not in (subdictown or subdictsecown):#since you can be both an owner and a secowner, ignore those here already in the owner list
subdictsecown[id] = relations.key2name(id)
out = ''
for sub in subdictown:
out += '<a href="/map/?key=%s">%s</a> own <br />' % (sub, subdictown[sub])
for sub in subdictsecown:
out += '<a href="/map/?key=%s">%s</a> secown <br />' % (sub, subdictsecown[sub])
message += out
q2.filter("verifed =", False)
if not q2.count() == 0:
message += "You have the following names waiting to be verifed: <br />"
for x in q2:
message += x.sl_name+"<br />"
message += form
#at least one acount verifed
self.response.out.write(head+message+end)
else:
message = "You have the following names waiting to be verifed: <br />"
results = q2.fetch(10)
for x in results:
message += x.sl_name+"<br />"
message += form
self.response.out.write(head+message+end)#show the acocounts not verifed and promt or more
def post(self):
user = users.get_current_user()
a = GoogleSLIds().gql("WHERE google_id = :1 AND sl_name = :2", user.user_id(), self.request.get("username")).get()
if (a is None):
a = GoogleSLIds()
if not (a.verifed):
a.google_id = user.user_id()
a.google_email = user.email()
a.sl_name = self.request.get("username")
a.sl_key = relations.name2key(a.sl_name)
a.datetime = datetime.datetime.utcnow()
a.vericode = GenVeriCode()
if not a.sl_key == None:
#notify in world object
a.sentim = False
logging.info('%s asked to be linked to %s and was found in the database' % (a.google_email, a.sl_name))
else:
a.sentim = True #cannot send an IM so mark as sent.
logging.info('%s asked to be linked to %s but was not found in the database.' % (a.google_email, a.sl_name))
a.put()
message = '''
If we have records of '''+a.sl_name+''' then a IM has been sent.
<br />
Enter a SL username to be verified. You will get an IM to complete the verification.
<br />
'''+form
else:
message = '''
You have already verified '''+a.sl_name+'''.
<br />
Enter a SL username to be verified. You will get an IM to complete the verification.
<br />
'''+form
self.response.out.write(head+message+end)
application = webapp.WSGIApplication(
[('.*', MainPage)
],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()