-
Notifications
You must be signed in to change notification settings - Fork 0
/
optout_page.py
61 lines (49 loc) · 2 KB
/
optout_page.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
import webapp2
from google.appengine.ext.webapp import template
from signupVerifier.processors.optout_processor import processOptOut,\
getPersonByOptOutToken
import logging
optout_reason_template = 'templates/optout_request_reason.html'
optout_confirm_template = 'templates/optout_confirm.html'
class OptOutPage(webapp2.RequestHandler):
# Opt-Out Page
# 1.) User Visits Opt-out Page (here)
# 2.) Script checks for Out-Out Token (OptOutProcessor)
# 3a.) If Exists
# 1.) Ask user for Reason (here)
# 2.) Enter Opt-Out (OptOutProcessor)
# 3.) Remove Opt-Out Token (OptOutProcessor)
# 3b.) Else
# 1.) Display Error (here)
def get(self):
self.handleRequest()
def post(self):
self.handleRequest()
def handleRequest(self):
params = self.request.params
# processOptOut and getPersonByOptOutToken will both throw LookupError
# if the provided token can not be found.
try:
if 'token' in params:
token = params['token']
logging.info('Got token %s' % token)
if 'reason' in params:
reason = params['reason']
optout = processOptOut(token, reason)
# Display confirmation page
retval = template.render(optout_confirm_template, {})
else:
person = getPersonByOptOutToken(token)
# Display page requesting reason for optout
values = {'token': token}
retval = template.render(optout_reason_template, values)
else:
# Display a 404
logging.info('No Token')
self.abort(404)
self.response.write(retval)
except LookupError as e:
#Display 404
self.abort(404)
routes = [webapp2.Route('/optout', handler=OptOutPage, name='optout')]
app = webapp2.WSGIApplication(routes=routes, debug=True)