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
|
|
|
|
|
2018-05-09 02:35:47 +00:00
|
|
|
import attr
|
2016-07-25 02:44:51 +00:00
|
|
|
|
2018-05-09 02:35:47 +00:00
|
|
|
from subiquitycore.utils import crypt_password
|
2016-06-22 19:19:54 +00:00
|
|
|
|
|
|
|
|
2018-05-09 02:35:47 +00:00
|
|
|
log = logging.getLogger('subiquitycore.models.identity')
|
2016-06-22 19:19:54 +00:00
|
|
|
|
|
|
|
|
2018-05-09 02:35:47 +00:00
|
|
|
@attr.s
|
|
|
|
class User(object):
|
|
|
|
realname = attr.ib()
|
|
|
|
username = attr.ib()
|
|
|
|
password = attr.ib()
|
2016-06-22 19:19:54 +00:00
|
|
|
|
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
|
|
|
|
"""
|
|
|
|
|
2017-11-14 21:30:09 +00:00
|
|
|
def __init__(self):
|
2016-11-01 23:44:04 +00:00
|
|
|
self._user = None
|
2017-11-19 23:51:59 +00:00
|
|
|
self._hostname = None
|
2016-06-22 19:19:54 +00:00
|
|
|
|
|
|
|
def add_user(self, result):
|
2018-05-09 02:35:47 +00:00
|
|
|
result = result.copy()
|
|
|
|
self._hostname = result.pop('hostname')
|
|
|
|
self._user = User(**result)
|
2016-06-22 19:19:54 +00:00
|
|
|
|
2017-11-19 23:51:59 +00:00
|
|
|
@property
|
|
|
|
def hostname(self):
|
|
|
|
return self._hostname
|
|
|
|
|
2016-06-22 19:19:54 +00:00
|
|
|
@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):
|
2018-05-09 02:35:47 +00:00
|
|
|
return "<LocalUser: {} {}>".format(self.user, self.hostname)
|