3 # Copyright (C) 2013 Simo Sorce <simo@redhat.com>
5 # see file 'COPYING' for use and warranty information
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from ipsilon.util.data import Store
25 def __init__(self, value):
26 # implement lookup of sites id for link/name
32 def __init__(self, username):
35 self._userdata = dict()
37 self._userdata = self._get_user_data(username)
40 def _get_user_data(self, username):
42 return store.get_user_preferences(username)
46 self._userdata = dict()
50 if 'is_admin' in self._userdata:
51 if self._userdata['is_admin'] == '1':
56 def is_admin(self, value):
58 self._userdata['is_admin'] = '1'
60 self._userdata['is_admin'] = '0'
64 if 'fullname' in self._userdata:
65 return self._userdata['fullname']
70 def fullname(self, value):
71 self._userdata['fullname'] = value
75 if 'sites' in self._userdata:
77 for site in self._userdata['sites']:
84 #TODO: implement setting sites via the user object ?
88 class UserSession(object):
90 self.user = cherrypy.session.get('user', None)
93 return User(self.user)
95 def remote_login(self):
96 if cherrypy.request.login:
97 return self.login(cherrypy.request.login)
99 def login(self, username):
100 if self.user == username:
103 # REMOTE_USER changed, destroy old session and regenerate new
104 cherrypy.session.regenerate()
105 cherrypy.session['user'] = username
106 cherrypy.session.save()
108 cherrypy.log('LOGIN SUCCESSFUL: %s', username)
110 def logout(self, user):
112 if not type(user) is User:
114 # Completely reset user data
115 cherrypy.log.error('%s %s' % (user.name, user.fullname))
118 # Destroy current session in all cases
119 cherrypy.lib.sessions.expire()