Commits

marxarelli  committed e76b528

Expanded provider customization.

Implemented providers option as an explicit set of which providers to present in
the UI.

Implemented custom_provider_size option for indicating whether the custom
provider should be shown as a large or small icon.

Improved parsing of white_list values and made resulting patterns more strict.

  • Participants
  • Parent commits 6a1c08f

Comments (0)

Files changed (3)

File authopenid/authopenid.py

     check_list_username = Option('openid', 'check_list_username', None,
             """Username for openid Service.""")
 
+    providers = Option('openid', 'providers', [],
+            """Explicit set of provider names to display. E.g: google, yahoo, ...""")
+
     custom_provider_name = Option('openid', 'custom_provider_name', None,
             """ Custom OpenId provider name. """)
 
     custom_provider_image = Option('openid', 'custom_provider_image', '',
             """ Custom OpenId provider image. """)
 
+    custom_provider_size = Option('openid', 'custom_provider_size', 'small',
+            """ Custom OpenId provider image size (small or large).""")
+
+
     def _get_masked_address(self, address):
         if self.check_ip:
             mask = struct.unpack('>L', socket.inet_aton(self.check_ip_mask))[0]
         generated_list = []
         if list_in_string:
             for item in list_in_string.split(','):
-                item = item.replace('.', '\\.')
-                item = item.replace('*', '.*')
                 item = item.strip()
+                item = re.escape(item)
+                item = '^' + item.replace('\*', '.*') + '$'
                 generated_list.append(re.compile(item))
                 self.env.log.debug("Item compiled: %s" % item)
 
         self.re_white_list = self.generate_re_list(self.white_list)
         self.env.log.debug("Compiling black-list")
         self.re_black_list = self.generate_re_list(self.black_list)
-
+        self.providers_regexp = '.'
+        if self.providers:
+            self.providers_regexp = '^(' + str.join('|', re.split(' *, *', self.providers)) + ')$'
 
     def _getStore(self, db):
         scheme, rest = self.connection_uri.split(':', 1)
             'signup': self.signup_link,
             'whatis': self.whatis_link,
             'css_class': 'error',
+            'providers_regexp': self.providers_regexp,
             'custom_provider_name': self.custom_provider_name,
             'custom_provider_label': self.custom_provider_label,
             'custom_provider_url': self.custom_provider_url,
             'custom_provider_image': self.custom_provider_image,
+            'custom_provider_size': self.custom_provider_size,
             }, None
 
     def _get_session(self, req):
                 'signup': self.signup_link,
                 'whatis': self.whatis_link,
                 'css_class': 'error',
+                'providers_regexp': self.providers_regexp,
                 'custom_provider_name': self.custom_provider_name,
                 'custom_provider_label': self.custom_provider_label,
                 'custom_provider_url': self.custom_provider_url,
                 'custom_provider_image': self.custom_provider_image,
+                'custom_provider_size': self.custom_provider_size,
                 }, None
 
         immediate = 'immediate' in req.args
                 'signup': self.signup_link,
                 'whatis': self.whatis_link,
                 'css_class': 'error',
+                'providers_regexp': self.providers_regexp,
                 'custom_provider_name': self.custom_provider_name,
                 'custom_provider_label': self.custom_provider_label,
                 'custom_provider_url': self.custom_provider_url,
                 'custom_provider_image': self.custom_provider_image,
+                'custom_provider_size': self.custom_provider_size,
                 }, None
         else:
             if request is None:
                     cgi.escape(openid_url),)
                 return 'openidlogin.html', {
                     'images': req.href.chrome('authopenid/images') + '/',
-                   'action': req.href.openidverify(),
-                   'message': msg,
-                   'signup': self.signup_link,
-                   'whatis': self.whatis_link,
-                   'css_class': 'error',
+                    'action': req.href.openidverify(),
+                    'message': msg,
+                    'signup': self.signup_link,
+                    'whatis': self.whatis_link,
+                    'css_class': 'error',
+                    'providers_regexp': self.providers_regexp,
                     'custom_provider_name': self.custom_provider_name,
                     'custom_provider_label': self.custom_provider_label,
                     'custom_provider_url': self.custom_provider_url,
                     'custom_provider_image': self.custom_provider_image,
+                    'custom_provider_size': self.custom_provider_size,
                    }, None
             else:
                 self._commit_session(session, req)
             'signup': self.signup_link,
             'whatis': self.whatis_link,
             'css_class': css_class,
+            'providers_regexp': self.providers_regexp,
             'custom_provider_name': self.custom_provider_name,
             'custom_provider_label': self.custom_provider_label,
             'custom_provider_url': self.custom_provider_url,
             'custom_provider_image': self.custom_provider_image,
+            'custom_provider_size': self.custom_provider_size,
             }, None
 
    # ITemplateProvider methods

File authopenid/htdocs/js/openid-jquery.js

             this.signin(box_id, true);
         }
     },
+    /* Remove providers that do not match the given RegExp */
+    filterProviders: function(re) {
+        for (var k in providers) if (!re.test(k)) delete providers[k];
+        for (var k in providers_small) if (!re.test(k)) delete providers_small[k];
+        for (var k in providers_large) if (!re.test(k)) delete providers_large[k];
+    },
     getBoxHTML: function(provider, box_size, image_ext) {
 
         var box_id = provider["name"].toLowerCase();

File authopenid/templates/openidlogin.html

     <script type="text/javascript">
         $(document).ready(function() {
             <span py:if="custom_provider_name and custom_provider_url and custom_provider_image" py:strip="">
-            providers_small.${custom_provider_name} = {
+            providers_${custom_provider_size}.${custom_provider_name} = {
                 name: '${custom_provider_name}',
                 label: '${custom_provider_label}',
                 url: '${custom_provider_url}',
                 image: '${custom_provider_image}'
                 }
-            providers.${custom_provider_name} = providers_small.${custom_provider_name}
+                providers.${custom_provider_name} = providers_${custom_provider_size}.${custom_provider_name};
             </span>
+            openid.filterProviders(new RegExp('${providers_regexp}'));
             openid.img_path = "${images}";
             openid.init('openid_identifier');
         });