-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
96 lines (77 loc) · 2.97 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
from google.appengine.ext.webapp import template
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from ncspace.ext import captcha
import config
class MainPage(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
if user:
chtml = captcha.displayhtml(
public_key = config.recaptcha_public_key,
use_ssl = False,
error = None)
template_values = {}
template_values['captchahtml'] = chtml
template_values['user_name'] = user.nickname()
path = os.path.join(os.path.dirname(__file__), 'template/index.html')
self.response.out.write(template.render(path, template_values))
else:
self.redirect(users.create_login_url(self.request.uri))
def post(self):
# Verification: reCAPTCHA
challenge = self.request.get('recaptcha_challenge_field')
response = self.request.get('recaptcha_response_field')
remoteip = os.environ['REMOTE_ADDR']
template_values = {}
cResponse = captcha.submit(
challenge,
response,
config.recaptcha_private_key,
remoteip)
if cResponse.is_valid:
template_values['recaptcha_error'] = 0
else:
chtml = captcha.displayhtml(
public_key = config.recaptcha_public_key,
use_ssl = False,
error = cResponse.error_code)
template_values['captchahtml'] = chtml
user = users.get_current_user()
template_values['user_name'] = user.nickname()
path = os.path.join(os.path.dirname(__file__), 'template/index.html')
output = template.render(path, template_values)
self.response.out.write(output)
class AboutPage(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
if user:
template_values = {
'user_name': user.nickname()
}
path = os.path.join(os.path.dirname(__file__), 'template/about.html')
self.response.out.write(template.render(path, template_values))
else:
self.redirect(users.create_login_url(self.request.uri))
class ContactPage(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
if user:
template_values = {
'user_name': user.nickname()
}
path = os.path.join(os.path.dirname(__file__), 'template/contact.html')
self.response.out.write(template.render(path, template_values))
else:
self.redirect(users.create_login_url(self.request.uri))
application = webapp.WSGIApplication(
[('/', MainPage),
('/about', AboutPage),
('/contact', ContactPage)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()