-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
68 lines (54 loc) · 1.99 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
import os
import jinja2
import webapp2
from google.appengine.api import users
from jwt import JWT
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'],
autoescape=True)
class MainPage(webapp2.RequestHandler):
def get(self):
user = users.get_current_user()
if user:
username = user.nickname()
greetings = 'Glad to see you back, '
log_url = users.create_logout_url(self.request.uri)
log_url_linktext = 'Sign out'
else:
username = 'Friend'
greetings = 'Welcome to our World, '
log_url = users.create_login_url(self.request.uri)
log_url_linktext = 'Sign in'
template_values = {
'user': user,
'username': username,
'greetings': greetings,
'log_url': log_url,
'log_url_linktext': log_url_linktext,
}
template = JINJA_ENVIRONMENT.get_template('client/index.html')
self.response.write(template.render(template_values))
class AddSuggestion(webapp2.RequestHandler):
def get(self):
user = users.get_current_user()
template = JINJA_ENVIRONMENT.get_template('client/add_suggestion.html')
if user:
username = user.nickname()
log_url = users.create_logout_url(self.request.uri)
log_url_linktext = 'Sign out'
token = JWT.create_token(user.email(), "insert")
template_values = {
'user': user,
'username': username,
'log_url': log_url,
'log_url_linktext': log_url_linktext,
'token': token,
}
self.response.write(template.render(template_values))
else:
self.redirect(users.create_login_url(self.request.uri))
app = webapp2.WSGIApplication([
('/', MainPage),
('/add_suggestion', AddSuggestion),
], debug=True)