This repository has been archived by the owner on Dec 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.py
executable file
·64 lines (49 loc) · 1.54 KB
/
user.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
#!/usr/bin/env python
import wsgiref.handlers
import os
from urllib import unquote
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.api import users
from fearcon.db import *
class MainHandler(webapp.RequestHandler):
def get(self):
level = None
login = ''
logout = ''
msg = ''
tmpl = 'tmpl/index.html'
if users.get_current_user():
logout = users.create_logout_url( self.request.path )
else:
login = users.create_login_url( self.request.path )
nickname = self.request.path
nickname = nickname.replace( '/user/', '' )
nickname = unquote( nickname )
levels = UserLevel.gql( 'WHERE nick = :1', nickname )
if levels.count() > 0:
level = levels[0]
if not level:
msg = "ruh roh: no such user - " + nickname
title = 'fearcon'
tmpl = 'tmpl/error.html'
else:
title = 'fearcon : ' + level.user.nickname()
template_values = {
'levels': [ 5, 4, 3, 2, 1 ],
'title': title,
'msg': msg,
'home': '/',
'login': login,
'logout': logout
}
if level:
template_values[ 'current' ] = level.level
path = os.path.join(os.path.dirname(__file__), tmpl )
self.response.out.write(template.render(path, template_values))
def main():
application = webapp.WSGIApplication([('/user/.*', MainHandler)],
debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()