WSL identity controller and view
This controller and view inherits from the subiquity identity, but remove the "hostname" field. We are using composition over inheritance for identityController as the UI builder is basing on the order of declared elements as class variable and we can’t override that in the metaclass when inheriting.
This commit is contained in:
parent
73e1ab7901
commit
d8e0026df5
|
@ -0,0 +1,14 @@
|
|||
# Copyright 2021 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/>.
|
|
@ -0,0 +1,38 @@
|
|||
# Copyright 2015-2021 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
|
||||
|
||||
from subiquity.client.controllers import IdentityController
|
||||
from subiquity.common.types import IdentityData
|
||||
from system_setup.ui.views import WSLIdentityView
|
||||
|
||||
log = logging.getLogger('system_setup.client.controllers.identity')
|
||||
|
||||
|
||||
class WSLIdentityController(IdentityController):
|
||||
|
||||
async def make_ui(self):
|
||||
data = await self.endpoint.GET()
|
||||
return WSLIdentityView(self, data)
|
||||
|
||||
def run_answers(self):
|
||||
if all(elem in self.answers for elem in
|
||||
['realname', 'username', 'password']):
|
||||
identity = IdentityData(
|
||||
realname=self.answers['realname'],
|
||||
username=self.answers['username'],
|
||||
crypted_password=self.answers['password'])
|
||||
self.done(identity)
|
|
@ -0,0 +1,14 @@
|
|||
# Copyright 2021 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/>.
|
|
@ -0,0 +1,20 @@
|
|||
# Copyright 2021 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/>.
|
||||
|
||||
from .identity import WSLIdentityView
|
||||
|
||||
__all__ = [
|
||||
'WSLIdentityView',
|
||||
]
|
|
@ -0,0 +1,82 @@
|
|||
# Copyright 2021 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/>.
|
||||
|
||||
from urwid import (
|
||||
connect_signal,
|
||||
)
|
||||
|
||||
|
||||
from subiquity.common.types import IdentityData
|
||||
from subiquity.ui.views.identity import IdentityForm, IdentityView, setup_password_validation
|
||||
from subiquitycore.ui.form import Form
|
||||
from subiquitycore.ui.utils import screen
|
||||
from subiquitycore.utils import crypt_password
|
||||
from subiquitycore.view import BaseView
|
||||
|
||||
|
||||
class WSLIdentityForm(Form):
|
||||
|
||||
realname = IdentityForm.realname
|
||||
username = IdentityForm.username
|
||||
password = IdentityForm.password
|
||||
confirm_password = IdentityForm.confirm_password
|
||||
|
||||
def __init__(self, initial):
|
||||
self.identityForm = IdentityForm([], initial)
|
||||
super().__init__(initial=initial)
|
||||
|
||||
def validate_realname(self):
|
||||
self.identityForm.validate_realname()
|
||||
|
||||
def validate_username(self):
|
||||
self.identityForm.validate_username()
|
||||
|
||||
def validate_password(self):
|
||||
self.identityForm.validate_password()
|
||||
|
||||
def validate_confirm_password(self):
|
||||
self.identityForm.validate_confirm_password()
|
||||
|
||||
|
||||
class WSLIdentityView(BaseView):
|
||||
title = IdentityView.title
|
||||
excerpt = _("Enter the username and password you will use to log in.")
|
||||
|
||||
def __init__(self, controller, identity_data):
|
||||
self.controller = controller
|
||||
|
||||
initial = {
|
||||
'realname': identity_data.realname,
|
||||
'username': identity_data.username,
|
||||
}
|
||||
|
||||
self.form = WSLIdentityForm(initial)
|
||||
|
||||
connect_signal(self.form, 'submit', self.done)
|
||||
setup_password_validation(self.form, _("passwords"))
|
||||
|
||||
super().__init__(
|
||||
screen(
|
||||
self.form.as_rows(),
|
||||
[self.form.done_btn],
|
||||
excerpt=_(self.excerpt),
|
||||
focus_buttons=False))
|
||||
|
||||
def done(self, result):
|
||||
self.controller.done(IdentityData(
|
||||
realname=self.form.realname.value,
|
||||
username=self.form.username.value,
|
||||
crypted_password=crypt_password(self.form.password.value),
|
||||
))
|
Loading…
Reference in New Issue