| OLD | NEW |
| 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, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 start_response, 400, | 42 start_response, 400, |
| 43 'Please enter a valid email address.' | 43 'Please enter a valid email address.' |
| 44 ) | 44 ) |
| 45 | 45 |
| 46 config = get_config() | 46 config = get_config() |
| 47 params = [('email', email), ('signature', sign(config, email))] | 47 params = [('email', email), ('signature', sign(config, email))] |
| 48 lang = data.get('lang') | 48 lang = data.get('lang') |
| 49 if lang: | 49 if lang: |
| 50 params.append(('lang', lang)) | 50 params.append(('lang', lang)) |
| 51 | 51 |
| 52 if data.get('edge', '') == '': |
| 53 email_template = 'verification_email_template' |
| 54 else: |
| 55 email_template = 'edge_verification_email_template' |
| 56 params.append(('edge', 'true')) |
| 57 |
| 52 sendMail( | 58 sendMail( |
| 53 config.get('submit_email', 'verification_email_template'), | 59 config.get('submit_email', email_template), |
| 54 { | 60 { |
| 55 'recipient': email, | 61 'recipient': email, |
| 56 'verification_url': '%s?%s' % ( | 62 'verification_url': '%s?%s' % ( |
| 57 urljoin(wsgiref.util.application_uri(environ), VERIFICATION_PATH), | 63 urljoin(wsgiref.util.application_uri(environ), VERIFICATION_PATH), |
| 58 urlencode(params) | 64 urlencode(params) |
| 59 ) | 65 ) |
| 60 } | 66 } |
| 61 ) | 67 ) |
| 62 | 68 |
| 63 return send_simple_response( | 69 return send_simple_response( |
| 64 start_response, 200, | 70 start_response, 200, |
| 65 'A confirmation email has been sent. Please check ' | 71 'A confirmation email has been sent. Please check ' |
| 66 'your email and click the confirmation link.' | 72 'your email and click the confirmation link.' |
| 67 ) | 73 ) |
| 68 | 74 |
| 69 @url_handler(VERIFICATION_PATH) | 75 @url_handler(VERIFICATION_PATH) |
| 70 def verify_email(environ, start_response): | 76 def verify_email(environ, start_response): |
| 71 config = get_config() | 77 config = get_config() |
| 72 params = dict(parse_qsl(environ.get('QUERY_STRING', ''))) | 78 params = dict(parse_qsl(environ.get('QUERY_STRING', ''))) |
| 73 | 79 |
| 74 email = params.get('email', '') | 80 email = params.get('email', '') |
| 75 signature = params.get('signature', '') | 81 signature = params.get('signature', '') |
| 76 if sign(config, email) != signature: | 82 if sign(config, email) != signature: |
| 77 return send_simple_response( | 83 return send_simple_response( |
| 78 start_response, 403, | 84 start_response, 403, |
| 79 'Invalid signature in verification request.' | 85 'Invalid signature in verification request.' |
| 80 ) | 86 ) |
| 81 | 87 |
| 82 filename = config.get('submit_email', 'filename') | 88 if params.get('edge', '') == 'true': |
| 89 filename = config.get('submit_email', 'edge_filename') |
| 90 else: |
| 91 filename = config.get('submit_email', 'filename') |
| 92 |
| 83 with open(filename, 'ab', 0) as file: | 93 with open(filename, 'ab', 0) as file: |
| 84 fcntl.lockf(file, fcntl.LOCK_EX) | 94 fcntl.lockf(file, fcntl.LOCK_EX) |
| 85 try: | 95 try: |
| 86 print >>file, email | 96 print >>file, email |
| 87 finally: | 97 finally: |
| 88 fcntl.lockf(file, fcntl.LOCK_UN) | 98 fcntl.lockf(file, fcntl.LOCK_UN) |
| 89 | 99 |
| 90 location = config.get('submit_email', 'successful_verification_redirect_locati
on') | 100 location = config.get('submit_email', 'successful_verification_redirect_locati
on') |
| 91 location = location.format(lang=quote(params.get('lang') or 'en', '')) | 101 location = location.format(lang=quote(params.get('lang') or 'en', '')) |
| 92 start_response('303 See Other', [('Location', location)]) | 102 start_response('303 See Other', [('Location', location)]) |
| 93 return [] | 103 return [] |
| OLD | NEW |