forked from mannequin-moments/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
74 lines (56 loc) · 1.98 KB
/
main.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
import json
import logging
import jinja2
import webapp2
from webapp2_extras import sessions
import models
import util
class RequestHandler(webapp2.RequestHandler):
"""Base request handler for Mannequin Moments."""
jinja_env = jinja2.Environment(
loader=jinja2.FileSystemLoader('templates')
)
def dispatch(self):
self._session_store = sessions.get_store(request=self.request)
try:
super(RequestHandler, self).dispatch()
finally:
self._session_store.save_sessions(self.response)
@webapp2.cached_property
def session(self):
return self._session_store.get_session()
def render(self, tpl_name, **args):
tmpl = self.jinja_env.get_template(tpl_name)
args['logged_in'] = True if self.session.get('user') else False
self.response.out.write(tmpl.render(**args))
class HomeHandler(RequestHandler):
def get(self):
self.render('index.tpl')
class LoginHandler(RequestHandler):
def get(self):
self.render('login.tpl')
def post(self):
user = None
username = self.request.get('username') or None
password = self.request.get('password') or None
# Change #1281 - emergency maintenance due to security issues
# user = redo auth.
return self.render('login.tpl', error='Undergoing emergency maintenance, sorry for any inconvenience caused')
self.session['user'] = username
return webapp2.redirect('/', response=self.response)
class FlagHandler(RequestHandler):
@util.require_login
def get(self):
flags = models.Flag.query().fetch()
self.render('flags.tpl', flags=flags)
config = {
'webapp2_extras.sessions': {
'secret_key': 'a793134b-c2c5-4cbf-973b-64ff7eea863a',
'name': 'mannequin-moments',
}
}
app = webapp2.WSGIApplication([
webapp2.Route('/', HomeHandler),
webapp2.Route('/#', LoginHandler),
webapp2.Route('/flags', FlagHandler),
], config=config)