[ckan-changes] [okfn/ckan] 10bb7f: [release-v1.6.1][noticket] repoze.who handler path...

GitHub noreply at github.com
Mon Apr 30 11:23:50 UTC 2012


  Branch: refs/heads/release-v1.6.1
  Home:   https://github.com/okfn/ckan
  Commit: 10bb7f20a28caa429c0783100011d491fc3fed76
      https://github.com/okfn/ckan/commit/10bb7f20a28caa429c0783100011d491fc3fed76
  Author: David Read <david.read at hackneyworkshop.com>
  Date:   2012-04-30 (Mon, 30 Apr 2012)

  Changed paths:
    M ckan/controllers/user.py
    M ckan/lib/base.py

  Log Message:
  -----------
  [release-v1.6.1][noticket] repoze.who handler paths are now read from who.ini so that they can be moved in the URI space. Added comments and logging.


diff --git a/ckan/controllers/user.py b/ckan/controllers/user.py
index 0a26d59..741cbea 100644
--- a/ckan/controllers/user.py
+++ b/ckan/controllers/user.py
@@ -52,6 +52,11 @@ def _setup_template_variables(self, context):
 
     ## end hooks
 
+    def _get_repoze_handler(self, handler_name):
+        '''Returns the URL that repoze.who will respond to and perform a
+        login or logout.'''
+        return getattr(request.environ['repoze.who.plugins']['friendlyform'], handler_name)
+        
     def index(self):
         LIMIT = 20
 
@@ -165,7 +170,9 @@ def _save_new(self, context):
             return self.new(data_dict, errors, error_summary)
         if not c.user:
             # Redirect to a URL picked up by repoze.who which performs the login
-            h.redirect_to('/login_generic?login=%s&password=%s' % (
+            login_url = self._get_repoze_handler('login_handler_path')
+            h.redirect_to('%s?login=%s&password=%s' % (
+                login_url,
                 str(data_dict['name']),
                 quote(data_dict['password1'].encode('utf-8'))))
         else:
@@ -283,10 +290,10 @@ def logged_in(self):
             h.redirect_to(locale=lang, controller='user', action='login')
 
     def logout(self):
-        # save our language in the session so we don't loose it
+        # save our language in the session so we don't lose it
         session['lang'] = request.environ.get('CKAN_LANG')
         session.save()
-        h.redirect_to('/user/logout')
+        h.redirect_to(self._get_repoze_handler('logout_handler_path'))
 
     def set_lang(self, lang):
         # this allows us to set the lang in session.  Used for logging
diff --git a/ckan/lib/base.py b/ckan/lib/base.py
index 0dfe78e..3d46b45 100644
--- a/ckan/lib/base.py
+++ b/ckan/lib/base.py
@@ -142,9 +142,11 @@ def _identify_user(self):
         b) For API calls he may set a header with his API key.
         If the user is identified then:
           c.user = user name (unicode)
+          c.userobj = user object
           c.author = user name
         otherwise:
           c.user = None
+          c.userobj = None
           c.author = user\'s IP address (unicode)
         '''
         # see if it was proxied first
@@ -153,8 +155,10 @@ def _identify_user(self):
             c.remote_addr = request.environ.get('REMOTE_ADDR', 'Unknown IP Address')
 
         # environ['REMOTE_USER'] is set by repoze.who if it authenticates a user's
-        # cookie or OpenID. (But it doesn't check the user (still) exists in our
-        # database - we need to do that here.
+        # cookie or OpenID. But repoze.who doesn't check the user (still)
+        # exists in our database - we need to do that here. (Another way would
+        # be with an userid_checker, but that would mean another db access.
+        # See: http://docs.repoze.org/who/1.0/narr.html#module-repoze.who.plugins.sql )
         c.user = request.environ.get('REMOTE_USER', '')
         if c.user:
             c.user = c.user.decode('utf8')
@@ -204,9 +208,12 @@ def __call__(self, environ, start_response):
                     if not is_valid_cookie_data:
                         if session.id:
                             if not session.get('lang'):
+                                self.log.debug('No session data any more - deleting session')
+                                self.log.debug('Session: %r', session.items())
                                 session.delete()
                         else:
                             response.delete_cookie(cookie)
+                            self.log.debug('No session data any more - deleting session cookie')
                 # Remove auth_tkt repoze.who cookie if user not logged in.
                 elif cookie == 'auth_tkt' and not session.id:
                     response.delete_cookie(cookie)


================================================================



More information about the ckan-changes mailing list