Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: sitescripts/submit_email/web/submit_email.py

Issue 29326122: Issue 3015 - Remove legacy code for Adblock Browser from submit_email (Closed)
Patch Set: Created Sept. 8, 2015, 1:36 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sitescripts/submit_email/template/verification.mail ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details. 13 # GNU General Public License for more details.
14 # 14 #
15 # You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17 17
18 import fcntl 18 import fcntl
19 import hmac 19 import hmac
20 import hashlib 20 import hashlib
21 import wsgiref.util 21 import wsgiref.util
22 import ConfigParser
22 from urlparse import parse_qsl, urljoin 23 from urlparse import parse_qsl, urljoin
23 from urllib import urlencode, quote 24 from urllib import urlencode, quote
24 25
25 from sitescripts.utils import get_config, sendMail, encode_email_address 26 from sitescripts.utils import get_config, sendMail, encode_email_address
26 from sitescripts.web import url_handler, form_handler, send_simple_response 27 from sitescripts.web import url_handler, form_handler, send_simple_response
27 28
28 VERIFICATION_PATH = '/verifyEmail' 29 VERIFICATION_PATH = '/verifyEmail'
29 DEFAULT_PRODUCT = 'adblockbrowser'
30 30
31 def sign(config, data): 31 def sign(config, data):
32 secret = config.get('submit_email', 'secret') 32 secret = config.get('submit_email', 'secret')
33 return hmac.new(secret, data, hashlib.sha1).hexdigest() 33 return hmac.new(secret, data, hashlib.sha1).hexdigest()
34 34
35 @url_handler('/submitEmail') 35 @url_handler('/submitEmail')
36 @form_handler 36 @form_handler
37 def submit_email(environ, start_response, data): 37 def submit_email(environ, start_response, data):
38 config = get_config()
39
40 try:
41 product = data['product']
42 template = config.get('submit_email', product + '_verification_email_templat e')
43 except (KeyError, ConfigParser.NoOptionError):
44 return send_simple_response(start_response, 400, 'Unkown product')
Felix Dahlke 2015/09/08 13:44:21 s/Unkown/Unknown?
Sebastian Noack 2015/09/08 14:09:43 Done.
45
38 email = data.get('email', '').strip() 46 email = data.get('email', '').strip()
39 try: 47 try:
40 email = encode_email_address(email) 48 email = encode_email_address(email)
41 except ValueError: 49 except ValueError:
42 return send_simple_response( 50 return send_simple_response(
43 start_response, 400, 51 start_response, 400,
44 'Please enter a valid email address.' 52 'Please enter a valid email address.'
45 ) 53 )
46 54
47 config = get_config() 55 params = [('email', email), ('signature', sign(config, email)), ('product', pr oduct)]
48 params = [('email', email), ('signature', sign(config, email))]
49 lang = data.get('lang') 56 lang = data.get('lang')
50 if lang: 57 if lang:
51 params.append(('lang', lang)) 58 params.append(('lang', lang))
52 59
53 product = data.get('product', DEFAULT_PRODUCT)
54 email_template = product + '_verification_email_template'
55 params.append(('product', product))
56
57 sendMail( 60 sendMail(
58 config.get('submit_email', email_template), 61 template,
59 { 62 {
60 'recipient': email, 63 'recipient': email,
61 'verification_url': '%s?%s' % ( 64 'verification_url': '%s?%s' % (
62 urljoin(wsgiref.util.application_uri(environ), VERIFICATION_PATH), 65 urljoin(wsgiref.util.application_uri(environ), VERIFICATION_PATH),
63 urlencode(params) 66 urlencode(params)
64 ) 67 )
65 } 68 }
66 ) 69 )
67 70
68 return send_simple_response( 71 return send_simple_response(
69 start_response, 200, 72 start_response, 200,
70 'A confirmation email has been sent. Please check ' 73 'A confirmation email has been sent. Please check '
71 'your email and click the confirmation link.' 74 'your email and click the confirmation link.'
72 ) 75 )
73 76
74 @url_handler(VERIFICATION_PATH) 77 @url_handler(VERIFICATION_PATH)
75 def verify_email(environ, start_response): 78 def verify_email(environ, start_response):
76 config = get_config() 79 config = get_config()
77 params = dict(parse_qsl(environ.get('QUERY_STRING', ''))) 80 params = dict(parse_qsl(environ.get('QUERY_STRING', '')))
78 81
82 try:
83 filename = config.get('submit_email', params['product'] + '_filename')
84 except (KeyError, ConfigParser.NoOptionError):
85 return send_simple_response(start_response, 400, 'Unkown product')
Felix Dahlke 2015/09/08 13:44:21 s/Unkown/Unknown/?
Sebastian Noack 2015/09/08 14:09:43 Done.
86
79 email = params.get('email', '') 87 email = params.get('email', '')
80 signature = params.get('signature', '') 88 signature = params.get('signature', '')
81 if sign(config, email) != signature: 89 if sign(config, email) != signature:
82 return send_simple_response( 90 return send_simple_response(
83 start_response, 403, 91 start_response, 403,
84 'Invalid signature in verification request.' 92 'Invalid signature in verification request.'
85 ) 93 )
86 94
87 product = params.get('product', DEFAULT_PRODUCT)
88 filename = config.get('submit_email', product + '_filename')
89
90 with open(filename, 'ab', 0) as file: 95 with open(filename, 'ab', 0) as file:
91 fcntl.lockf(file, fcntl.LOCK_EX) 96 fcntl.lockf(file, fcntl.LOCK_EX)
92 try: 97 try:
93 print >>file, email 98 print >>file, email
94 finally: 99 finally:
95 fcntl.lockf(file, fcntl.LOCK_UN) 100 fcntl.lockf(file, fcntl.LOCK_UN)
96 101
97 location = config.get('submit_email', 'successful_verification_redirect_locati on') 102 location = config.get('submit_email', 'successful_verification_redirect_locati on')
98 location = location.format(lang=quote(params.get('lang') or 'en', '')) 103 location = location.format(lang=quote(params.get('lang') or 'en', ''))
99 start_response('303 See Other', [('Location', location)]) 104 start_response('303 See Other', [('Location', location)])
100 return [] 105 return []
OLDNEW
« no previous file with comments | « sitescripts/submit_email/template/verification.mail ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld