subiquity/subiquitycore/models/identity.py

59 lines
1.5 KiB
Python
Raw Normal View History

# 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
2018-05-09 02:35:47 +00:00
from subiquitycore.utils import crypt_password
2018-05-09 02:35:47 +00:00
log = logging.getLogger('subiquitycore.models.identity')
2018-05-09 02:35:47 +00:00
@attr.s
class User(object):
realname = attr.ib()
username = attr.ib()
password = attr.ib()
class IdentityModel(object):
""" Model representing user identity
"""
def __init__(self):
2016-11-01 23:44:04 +00:00
self._user = None
self._hostname = None
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)
@property
def hostname(self):
return self._hostname
@property
def user(self):
return self._user
def encrypt_password(self, passinput):
return crypt_password(passinput)
def __repr__(self):
2018-05-09 02:35:47 +00:00
return "<LocalUser: {} {}>".format(self.user, self.hostname)