Update Copyright header point to COPYING file
[cascardo/ipsilon.git] / ipsilon / util / user.py
index fd557a0..ee3fe41 100644 (file)
@@ -1,23 +1,9 @@
-# Copyright (C) 2013  Simo Sorce <simo@redhat.com>
-#
-# see file 'COPYING' for use and warranty information
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# Copyright (C) 2013 Ipsilon project Contributors, for license see COPYING
 
 from ipsilon.util.data import UserStore
 from ipsilon.util.log import Log
 import cherrypy
+import logging
 
 
 class Site(object):
@@ -121,6 +107,8 @@ class UserSession(Log):
 
     def login(self, username, userattrs=None):
         if self.user == username:
+            if userattrs and not self.get_user_attrs():
+                self.save_user_attrs(userattrs)
             return
 
         # REMOTE_USER changed, replace user
@@ -137,10 +125,11 @@ class UserSession(Log):
 
     def logout(self, user):
         if user is not None:
-            if not type(user) is User:
+            if not isinstance(user, User):
                 raise TypeError
             # Completely reset user data
-            cherrypy.log.error('%s %s' % (user.name, user.fullname))
+            cherrypy.log.error('%s %s' % (user.name, user.fullname),
+                               severity=logging.INFO)
             user.reset()
 
         # Destroy current session in all cases
@@ -154,8 +143,7 @@ class UserSession(Log):
 
     def save_user_attrs(self, userattrs):
         cherrypy.session['userattrs'] = userattrs
-        cherrypy.session.save()
-        self._debug('Saved user attrs')
+        self.debug('Saved user attrs')
         self.userattrs = userattrs
 
     def _get_provider_attr_name(self, provider):
@@ -171,16 +159,14 @@ class UserSession(Log):
     def save_provider_data(self, provider, data):
         attr = self._get_provider_attr_name(provider)
         cherrypy.session[attr] = data
-        cherrypy.session.save()
-        self._debug('Saved %s provider data' % provider)
+        self.debug('Saved %s provider data' % provider)
 
     def save_data(self, facility, name, data):
         """ Save named data in the session so it can be retrieved later """
         if facility not in cherrypy.session:
             cherrypy.session[facility] = dict()
         cherrypy.session[facility][name] = data
-        cherrypy.session.save()
-        self._debug('Saved session data named [%s:%s]' % (facility, name))
+        self.debug('Saved session data named [%s:%s]' % (facility, name))
 
     def get_data(self, facility, name):
         """ Get named data in the session if available """
@@ -198,8 +184,7 @@ class UserSession(Log):
                 return
             cherrypy.session[facility][name] = None
             del cherrypy.session[facility][name]
-            self._debug('Nuked session data named [%s:%s]' % (facility, name))
+            self.debug('Nuked session data named [%s:%s]' % (facility, name))
         else:
             del cherrypy.session[facility]
-            self._debug('Nuked session facility [%s]' % (facility,))
-        cherrypy.session.save()
+            self.debug('Nuked session facility [%s]' % (facility,))