2015-08-18 16:50:58 +00:00
|
|
|
# Copyright 2015 Canonical, Ltd.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import logging
|
2016-06-30 18:17:01 +00:00
|
|
|
from subiquitycore.utils import crypt_password
|
2015-08-18 16:50:58 +00:00
|
|
|
|
|
|
|
|
2016-06-30 18:17:01 +00:00
|
|
|
log = logging.getLogger('subiquitycore.models.identity')
|
2015-08-18 16:50:58 +00:00
|
|
|
|
2016-07-25 02:44:51 +00:00
|
|
|
|
2016-06-22 19:19:54 +00:00
|
|
|
class LocalUser(object):
|
|
|
|
def __init__(self, result):
|
|
|
|
self._realname = result.get('realname')
|
|
|
|
self._username = result.get('username')
|
|
|
|
self._password = result.get('password')
|
|
|
|
self._cpassword = result.get('confirm_password')
|
|
|
|
self._ssh_import_id = None
|
|
|
|
if 'ssh_import_id' in result:
|
|
|
|
self._ssh_import_id = result.get('ssh_import_id')
|
|
|
|
|
|
|
|
@property
|
|
|
|
def realname(self):
|
|
|
|
return self._realname
|
|
|
|
|
|
|
|
@property
|
|
|
|
def username(self):
|
|
|
|
return self._username
|
|
|
|
|
|
|
|
@property
|
|
|
|
def password(self):
|
|
|
|
return self._password
|
|
|
|
|
|
|
|
@property
|
|
|
|
def cpassword(self):
|
|
|
|
return self._cpassword
|
|
|
|
|
|
|
|
@property
|
|
|
|
def ssh_import_id(self):
|
|
|
|
return self._ssh_import_id
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "%s <%s>" % (self._realname, self._username)
|
|
|
|
|
2015-08-18 16:50:58 +00:00
|
|
|
|
2017-01-13 01:55:20 +00:00
|
|
|
class IdentityModel(object):
|
2015-08-18 16:50:58 +00:00
|
|
|
""" Model representing user identity
|
|
|
|
"""
|
|
|
|
|
2016-06-22 19:19:54 +00:00
|
|
|
def __init__(self, opts):
|
|
|
|
self.opts = opts
|
2016-11-01 23:44:04 +00:00
|
|
|
self._user = None
|
2016-06-22 19:19:54 +00:00
|
|
|
|
|
|
|
def add_user(self, result):
|
|
|
|
if result:
|
|
|
|
self._user = LocalUser(result)
|
|
|
|
else:
|
|
|
|
self._user = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def user(self):
|
|
|
|
return self._user
|
|
|
|
|
2015-09-21 21:40:26 +00:00
|
|
|
def encrypt_password(self, passinput):
|
|
|
|
return crypt_password(passinput)
|
2015-08-18 16:50:58 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
2016-06-22 19:19:54 +00:00
|
|
|
return "<LocalUser: {}>".format(self.user)
|