Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added various settings to customize the login dialog. (fixes #1)

  • Loading branch information...
commit 656d399a9ad8086011d4d3c6aaa2856afa23cc42 1 parent 573365c
Georges Dubus authored
1  CHANGES.rst
Source Rendered
@@ -6,6 +6,7 @@ DEV
6 6 - Use a pre-built verifier object for lower per-request overhead (thanks @rfk).
7 7 - Renamed the setting persona.audience to persona.audiences to match the PyBrowserID API.
8 8 - Added the "persona.verifier" setting to change the verifier.
  9 +- Added various settings to customize the login dialog.
9 10
10 11 1.0
11 12 ---
30 README.rst
Source Rendered
@@ -88,6 +88,34 @@ persona.audiences
88 88 persona.verifier
89 89 The doted python name of the BrowserID assertion verifier. Optional. Default is 'browserid.RemoteVerifier'. Another possible value could be 'browserid.LocalVerifier' (not recommended for now).
90 90
  91 +.. _`persona documentation`: https://developer.mozilla.org/en-US/docs/Persona/Remote_Verification_API
  92 +
  93 +Login dialog customization
  94 +++++++++++++++++++++++++++
  95 +
  96 +Persona provides a few ways to customize the login dialog. To be precise, they
  97 +are arguments to the `navigator.id.request` API call. For the full description of these parameters,
  98 +see `the documentation of navigator.id.request`_.
  99 +
  100 +.. _the documentation of navigator.id.request: https://developer.mozilla.org/en-US/docs/DOM/navigator.id.request
  101 +
  102 +persona.siteName
  103 + Plain text name of your site to show in the login dialog. Optional.
  104 +
  105 +persona.siteLogo
  106 + Absolute path to an image to show in the login dialog. Optional.
  107 +
  108 +persona.privacyPolicy
  109 + Absolute path or URL to the web site's privacy policy. Optional.
  110 +
  111 +persona.termsOfService
  112 + Absolute path or URL to the web site's terms of service. Optional.
  113 +
  114 +Routes
  115 +++++++
  116 +
  117 +If the default route names or paths conflicts with your application, you can change them :
  118 +
91 119 persona.login_route
92 120 The login route name. Optional, default is 'login'.
93 121
@@ -100,8 +128,6 @@ persona.logout_route
100 128 persona.logout_path
101 129 The logout route path. Optional, default is '/logout'.
102 130
103   -.. _`persona documentation`: https://developer.mozilla.org/en-US/docs/Persona/Remote_Verification_API
104   -
105 131 Python 3 compatibility
106 132 ----------------------
107 133
3  demo/demo.py
@@ -29,6 +29,9 @@ def template(request):
29 29 'persona.secret': 'some secret',
30 30 'persona.audiences': 'http://localhost:8080',
31 31 'mako.directories': '.',
  32 + 'persona.siteName': 'Super demo app',
  33 + 'persona.privacyPolicy': '/nonExistentPrivacy.html',
  34 + 'persona.termsOfService': '/nonExistentTos.html',
32 35 }
33 36 config = Configurator(settings=settings)
34 37 config.include('pyramid_persona')
9 pyramid_persona/__init__.py
... ... @@ -1,3 +1,4 @@
  1 +import json
1 2 import warnings
2 3 from pyramid.authentication import SessionAuthenticationPolicy
3 4 from pyramid.authorization import ACLAuthorizationPolicy
@@ -60,6 +61,14 @@ def check():
60 61 audiences = aslist(settings['persona.audiences'])
61 62 config.registry['persona.verifier'] = verifier_factory(audiences)
62 63
  64 + # Parameters for the request API call
  65 + request_params = {}
  66 + for option in ('privacyPolicy', 'siteLogo', 'siteName', 'termsOfService'):
  67 + setting_name = 'persona.%s'%option
  68 + if setting_name in settings:
  69 + request_params[option] = settings[setting_name]
  70 + config.registry['persona.request_params'] = json.dumps(request_params)
  71 +
63 72 # Login and logout views.
64 73 login_route = settings.get('persona.login_route', 'login')
65 74 login_path = settings.get('persona.login_path', '/login')
4 pyramid_persona/templates/persona.js
... ... @@ -1,5 +1,5 @@
1 1 $(function() {
2   - $('#signin').click(function() { navigator.id.request(); return false;});
  2 + $('#signin').click(function() { navigator.id.request(%(request_params)s); return false;});
3 3
4 4 $('#signout').click(function() { navigator.id.logout(); return false;});
5 5
@@ -26,4 +26,4 @@ $(function() {
26 26 });
27 27 }
28 28 });
29   -});
  29 +});
3  pyramid_persona/utils.py
@@ -23,7 +23,8 @@ def js(request):
23 23 'user': user,
24 24 'login': '/login',
25 25 'logout': '/logout',
26   - 'csrf_token': request.session.get_csrf_token()
  26 + 'csrf_token': request.session.get_csrf_token(),
  27 + 'request_params': markupsafe.Markup(request.registry['persona.request_params']),
27 28 }
28 29 template = markupsafe.Markup(pkg_resources.resource_string('pyramid_persona', 'templates/persona.js').decode())
29 30 return template % data

0 comments on commit 656d399

Please sign in to comment.
Something went wrong with that request. Please try again.