-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_site.py
105 lines (89 loc) · 3.83 KB
/
main_site.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
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
# index.py:
##
# © 2012 Steven Casagrande ([email protected]) and
# Christopher E. Granade ([email protected]).
# This file is a part of the ThingPool Server project.
# Licensed under the AGPL version 3.
##
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##
## IMPORTS #####################################################################
## GAE API ##
from google.appengine.api import users
## WEB FRAMEWORK
import webapp2
import jinja2
## PYTHON STANDARD LIBRARY ##
import os
## THINGPOOL MODULES ##
import api
import config
import index
import dataModels
import security
## CORE SERVER #################################################################
jinja_environment = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/html'
template_values = {
'pool_name': config.POOL_NAME,
'show_requested': False
}
user = users.get_current_user()
if user:
query = dataModels.Person.all().filter('user_account =', user)
person = query.get()
# Check if we need to file a request.
if person is None:
security.request_tp_account(user)
logged_in = False
template_values['show_requested'] = True
else:
if person.permissions > security.USER_STATUS_REQUESTED:
logged_in = True
else:
# FIXME: currently there is no logout button shown,
# so that a user can't change to a valid GAE account.
template_values['login_failed'] = True
template_values['login_failure_reason'] = {
security.USER_STATUS_BANNED: 'This user account has been banned from {}.'.format(config.POOL_NAME),
security.USER_STATUS_UNKNOWN: 'This error should not have happened.',
security.USER_STATUS_REQUESTED: 'Your account has not yet been approved by a {} administrator.'.format(config.POOL_NAME)
}[person.permissions]
logged_in = False
else:
logged_in = False
# Avoid having to put an if operator in every single value by updating
# the dictionary differently if we're logged in or not.
if logged_in:
template_values.update({
'login_button': 'Logout',
'loginout_url': users.create_logout_url(self.request.uri),
'checked_out_things': 12, # FIXME: this is for mockup purposes ONLY.
'username': user.nickname()
})
else:
template_values.update({
'login_button': 'Login',
'loginout_url': users.create_login_url(self.url_for('main')),
'checked_out_things': 0,
'username' : 'Not logged in'
})
template = jinja_environment.get_template('templates/main/index.html')
self.response.out.write(template.render(template_values))