allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject allura git commit: [#8199] Adds CRLF line endings to 2FA recovery codes download for Windows UAs
Date Mon, 23 Apr 2018 15:59:18 GMT
Repository: allura
Updated Branches:
  refs/heads/master ab97dbfbe -> 2445c75e1


[#8199] Adds CRLF line endings to 2FA recovery codes download for Windows UAs


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/2445c75e
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/2445c75e
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/2445c75e

Branch: refs/heads/master
Commit: 2445c75e1617b2672ccd859dbe2a52807b84c8ad
Parents: ab97dbf
Author: Kenton Taylor <ktaylor@slashdotmedia.com>
Authored: Thu Apr 19 19:44:52 2018 +0000
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Mon Apr 23 10:59:07 2018 -0500

----------------------------------------------------------------------
 Allura/allura/controllers/auth.py                | 3 +++
 Allura/allura/lib/helpers.py                     | 6 +++++-
 Allura/allura/templates/user_recovery_codes.html | 6 +++---
 3 files changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/2445c75e/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index 7dc1532..537d545 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -812,9 +812,12 @@ class PreferencesController(BaseController):
         h.auditlog_user('Viewed multifactor recovery codes')
         provider = plugin.AuthenticationProvider.get(request)
 
+        windows_line_endings = "WINDOWS" in request.headers.get('USER_AGENT', '').upper()
+
         return dict(
             codes=codes,
             menu = provider.account_navigation(),
+            windows_line_endings=windows_line_endings
         )
 
     @expose()

http://git-wip-us.apache.org/repos/asf/allura/blob/2445c75e/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 572b6e6..c0fe667 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -1286,13 +1286,17 @@ def rate_limit(cfg_opt, artifact_count, start_date, exception=None):
                 raise exception()
 
 
-def base64uri(content_or_image, image_format='PNG', mimetype='image/png'):
+def base64uri(content_or_image, image_format='PNG', mimetype='image/png', windows_line_endings=False):
     if hasattr(content_or_image, 'save'):
         output = StringIO()
         content_or_image.save(output, format=image_format)
         content = output.getvalue()
     else:
         content = content_or_image
+
+    if windows_line_endings:
+        content = content.replace('\n', '\r\n')
+
     data = base64.b64encode(content)
     return 'data:{};base64,{}'.format(mimetype, data)
 

http://git-wip-us.apache.org/repos/asf/allura/blob/2445c75e/Allura/allura/templates/user_recovery_codes.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/user_recovery_codes.html b/Allura/allura/templates/user_recovery_codes.html
index 5039dd0..bf4a63d 100644
--- a/Allura/allura/templates/user_recovery_codes.html
+++ b/Allura/allura/templates/user_recovery_codes.html
@@ -26,9 +26,9 @@
 
 
 {% macro plaintext(codes) %}
-{{ config['site_name'] }} Recovery Codes:
+{{- config['site_name'] }} Recovery Codes:
 {% for code in codes %}
-{{ code }}
+{{ code -}}
 {% endfor %}
 {% endmacro %}
 
@@ -38,7 +38,7 @@
     <h2 class="subtitle">Your {{ config['site_name'] }} Recovery Codes</h2>
     <p>
         <a href="#" class="print"><strong>Print</strong></a> these!
-        <a href="{{ h.base64uri(plaintext(codes), mimetype='text/plain') }}" download="{{
config['site_name'] }} recovery codes.txt" class="download"><strong>Download</strong></a>
them!
+        <a href="{{ h.base64uri(plaintext(codes), mimetype='text/plain', windows_line_endings=windows_line_endings)
}}" download="{{ config['site_name'] }} recovery codes.txt" class="download"><strong>Download</strong></a>
them!
         Keep them safe.
     </p>
     <p>


Mime
View raw message