2015-08-18 18:34:59 +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/>.
|
|
|
|
|
|
|
|
""" Welcome
|
|
|
|
|
|
|
|
Welcome provides user with language selection
|
|
|
|
|
|
|
|
"""
|
|
|
|
import logging
|
2015-09-02 19:21:14 +00:00
|
|
|
from urwid import (Pile, Columns, Text, ListBox)
|
2015-08-18 18:34:59 +00:00
|
|
|
from subiquity.ui.buttons import done_btn, cancel_btn
|
Implement username field protection
man 8 useradd says:
It is usually recommended to only use usernames that begin with a
lower case letter or an underscore, followed by lower case
letters, digits, underscores, or dashes. They can end with a
dollar sign. In regular expression terms: [a-z_][a-z0-9_-]*[$]?
On Debian, the only constraints are that usernames must neither
start with a dash ('-') nor plus ('+') nor tilde ('~') nor
contain a colon (':'), a comma (','), or a whitespace (space: ' ',
end of line: '\n', tabulation: '\t', etc.). Note that using a
slash ('/') may break the default algorithm for the definition
of the user's home directory.
Usernames may only be up to 32 characters long.
In this patch we implement most of this. Subset of the regular
expression suggested above is used to limit input into the username
field. We've not yet determined how to provide a fixed width widget
so at this time, user can input more than 32 characters, but upon
selectin done, we raise and error and reset the state.
Signed-off-by: Ryan Harper <ryan.harper@canonical.com>
2015-10-23 20:21:13 +00:00
|
|
|
from subiquity.ui.interactive import (PasswordEditor,
|
2015-11-03 20:00:05 +00:00
|
|
|
RealnameEditor,
|
Implement username field protection
man 8 useradd says:
It is usually recommended to only use usernames that begin with a
lower case letter or an underscore, followed by lower case
letters, digits, underscores, or dashes. They can end with a
dollar sign. In regular expression terms: [a-z_][a-z0-9_-]*[$]?
On Debian, the only constraints are that usernames must neither
start with a dash ('-') nor plus ('+') nor tilde ('~') nor
contain a colon (':'), a comma (','), or a whitespace (space: ' ',
end of line: '\n', tabulation: '\t', etc.). Note that using a
slash ('/') may break the default algorithm for the definition
of the user's home directory.
Usernames may only be up to 32 characters long.
In this patch we implement most of this. Subset of the regular
expression suggested above is used to limit input into the username
field. We've not yet determined how to provide a fixed width widget
so at this time, user can input more than 32 characters, but upon
selectin done, we raise and error and reset the state.
Signed-off-by: Ryan Harper <ryan.harper@canonical.com>
2015-10-23 20:21:13 +00:00
|
|
|
UsernameEditor)
|
2015-08-18 18:34:59 +00:00
|
|
|
from subiquity.ui.utils import Padding, Color
|
|
|
|
from subiquity.view import ViewPolicy
|
|
|
|
|
|
|
|
log = logging.getLogger("subiquity.views.identity")
|
|
|
|
|
2015-11-03 20:00:05 +00:00
|
|
|
USERNAME_MAXLEN = 32
|
|
|
|
REALNAME_MAXLEN = 160
|
|
|
|
|
2015-08-18 18:34:59 +00:00
|
|
|
|
|
|
|
class IdentityView(ViewPolicy):
|
|
|
|
def __init__(self, model, signal):
|
|
|
|
self.model = model
|
|
|
|
self.signal = signal
|
|
|
|
self.items = []
|
2015-11-03 20:00:05 +00:00
|
|
|
self.realname = RealnameEditor(caption="")
|
Implement username field protection
man 8 useradd says:
It is usually recommended to only use usernames that begin with a
lower case letter or an underscore, followed by lower case
letters, digits, underscores, or dashes. They can end with a
dollar sign. In regular expression terms: [a-z_][a-z0-9_-]*[$]?
On Debian, the only constraints are that usernames must neither
start with a dash ('-') nor plus ('+') nor tilde ('~') nor
contain a colon (':'), a comma (','), or a whitespace (space: ' ',
end of line: '\n', tabulation: '\t', etc.). Note that using a
slash ('/') may break the default algorithm for the definition
of the user's home directory.
Usernames may only be up to 32 characters long.
In this patch we implement most of this. Subset of the regular
expression suggested above is used to limit input into the username
field. We've not yet determined how to provide a fixed width widget
so at this time, user can input more than 32 characters, but upon
selectin done, we raise and error and reset the state.
Signed-off-by: Ryan Harper <ryan.harper@canonical.com>
2015-10-23 20:21:13 +00:00
|
|
|
self.username = UsernameEditor(caption="")
|
2015-08-27 14:28:48 +00:00
|
|
|
self.password = PasswordEditor(caption="")
|
2015-09-28 15:03:01 +00:00
|
|
|
self.error = Text("", align="center")
|
2015-08-27 14:28:48 +00:00
|
|
|
self.confirm_password = PasswordEditor(caption="")
|
2015-08-18 18:34:59 +00:00
|
|
|
|
|
|
|
body = [
|
2015-08-27 14:28:48 +00:00
|
|
|
Padding.center_50(self._build_model_inputs()),
|
2015-08-18 18:34:59 +00:00
|
|
|
Padding.line_break(""),
|
2015-09-28 15:03:01 +00:00
|
|
|
Padding.center_50(Color.info_error(self.error)),
|
|
|
|
Padding.line_break(""),
|
2015-08-24 15:51:10 +00:00
|
|
|
Padding.center_15(self._build_buttons()),
|
2015-08-18 18:34:59 +00:00
|
|
|
]
|
2015-08-27 14:28:48 +00:00
|
|
|
super().__init__(ListBox(body))
|
2015-08-18 18:34:59 +00:00
|
|
|
|
|
|
|
def _build_buttons(self):
|
|
|
|
cancel = cancel_btn(on_press=self.cancel)
|
|
|
|
done = done_btn(on_press=self.done)
|
|
|
|
|
|
|
|
buttons = [
|
2015-08-24 15:51:10 +00:00
|
|
|
Color.button(done, focus_map='button focus'),
|
|
|
|
Color.button(cancel, focus_map='button focus')
|
2015-08-18 18:34:59 +00:00
|
|
|
]
|
|
|
|
return Pile(buttons)
|
|
|
|
|
|
|
|
def _build_model_inputs(self):
|
|
|
|
sl = [
|
2015-09-11 18:12:26 +00:00
|
|
|
Columns(
|
|
|
|
[
|
|
|
|
("weight", 0.2, Text("Real Name", align="right")),
|
|
|
|
("weight", 0.3,
|
|
|
|
Color.string_input(self.realname,
|
|
|
|
focus_map="string_input focus"))
|
|
|
|
],
|
|
|
|
dividechars=4
|
|
|
|
),
|
2015-08-27 14:28:48 +00:00
|
|
|
Columns(
|
|
|
|
[
|
|
|
|
("weight", 0.2, Text("Username", align="right")),
|
|
|
|
("weight", 0.3,
|
|
|
|
Color.string_input(self.username,
|
|
|
|
focus_map="string_input focus"))
|
|
|
|
],
|
|
|
|
dividechars=4
|
|
|
|
),
|
|
|
|
Columns(
|
|
|
|
[
|
|
|
|
("weight", 0.2, Text("Password", align="right")),
|
|
|
|
("weight", 0.3,
|
|
|
|
Color.string_input(self.password,
|
|
|
|
focus_map="string_input focus"))
|
|
|
|
],
|
|
|
|
dividechars=4
|
|
|
|
),
|
|
|
|
Columns(
|
|
|
|
[
|
|
|
|
("weight", 0.2, Text("Confirm Password", align="right")),
|
|
|
|
("weight", 0.3,
|
|
|
|
Color.string_input(self.confirm_password,
|
|
|
|
focus_map="string_input focus"))
|
|
|
|
],
|
|
|
|
dividechars=4
|
|
|
|
)
|
2015-08-18 18:34:59 +00:00
|
|
|
]
|
|
|
|
return Pile(sl)
|
|
|
|
|
|
|
|
def done(self, result):
|
2015-11-03 20:00:05 +00:00
|
|
|
if len(self.password.value) < 1:
|
|
|
|
self.error.set_text("Password must be set")
|
|
|
|
self.password.value = ""
|
|
|
|
self.confirm_password.value = ""
|
|
|
|
return
|
|
|
|
|
2015-09-28 15:03:01 +00:00
|
|
|
if self.password.value != self.confirm_password.value:
|
|
|
|
self.error.set_text("Passwords do not match.")
|
|
|
|
self.password.value = ""
|
|
|
|
self.confirm_password.value = ""
|
|
|
|
return
|
Implement username field protection
man 8 useradd says:
It is usually recommended to only use usernames that begin with a
lower case letter or an underscore, followed by lower case
letters, digits, underscores, or dashes. They can end with a
dollar sign. In regular expression terms: [a-z_][a-z0-9_-]*[$]?
On Debian, the only constraints are that usernames must neither
start with a dash ('-') nor plus ('+') nor tilde ('~') nor
contain a colon (':'), a comma (','), or a whitespace (space: ' ',
end of line: '\n', tabulation: '\t', etc.). Note that using a
slash ('/') may break the default algorithm for the definition
of the user's home directory.
Usernames may only be up to 32 characters long.
In this patch we implement most of this. Subset of the regular
expression suggested above is used to limit input into the username
field. We've not yet determined how to provide a fixed width widget
so at this time, user can input more than 32 characters, but upon
selectin done, we raise and error and reset the state.
Signed-off-by: Ryan Harper <ryan.harper@canonical.com>
2015-10-23 20:21:13 +00:00
|
|
|
|
2015-11-03 20:00:05 +00:00
|
|
|
if len(self.realname.value) < 1:
|
|
|
|
self.error.set_text("Realname missing.")
|
|
|
|
self.realname.value = ""
|
|
|
|
return
|
|
|
|
|
|
|
|
if len(self.realname.value) > REALNAME_MAXLEN:
|
|
|
|
self.error.set_text("Realname too long, must be < " +
|
|
|
|
str(REALNAME_MAXLEN))
|
|
|
|
self.realname.value = ""
|
|
|
|
return
|
|
|
|
|
|
|
|
if len(self.username.value) < 1:
|
|
|
|
self.error.set_text("Username missing.")
|
|
|
|
self.username.value = ""
|
|
|
|
return
|
|
|
|
|
|
|
|
if len(self.username.value) > USERNAME_MAXLEN:
|
|
|
|
self.error.set_text("Username too long, must be < " +
|
|
|
|
str(USERNAME_MAXLEN))
|
Implement username field protection
man 8 useradd says:
It is usually recommended to only use usernames that begin with a
lower case letter or an underscore, followed by lower case
letters, digits, underscores, or dashes. They can end with a
dollar sign. In regular expression terms: [a-z_][a-z0-9_-]*[$]?
On Debian, the only constraints are that usernames must neither
start with a dash ('-') nor plus ('+') nor tilde ('~') nor
contain a colon (':'), a comma (','), or a whitespace (space: ' ',
end of line: '\n', tabulation: '\t', etc.). Note that using a
slash ('/') may break the default algorithm for the definition
of the user's home directory.
Usernames may only be up to 32 characters long.
In this patch we implement most of this. Subset of the regular
expression suggested above is used to limit input into the username
field. We've not yet determined how to provide a fixed width widget
so at this time, user can input more than 32 characters, but upon
selectin done, we raise and error and reset the state.
Signed-off-by: Ryan Harper <ryan.harper@canonical.com>
2015-10-23 20:21:13 +00:00
|
|
|
self.username.value = ""
|
|
|
|
return
|
|
|
|
|
2015-09-21 21:40:26 +00:00
|
|
|
cpassword = self.model.encrypt_password(self.password.value)
|
|
|
|
log.debug("*crypted* User input: {} {} {}".format(
|
|
|
|
self.username.value, cpassword, cpassword))
|
2015-08-18 18:34:59 +00:00
|
|
|
result = {
|
2015-09-11 18:12:26 +00:00
|
|
|
"realname": self.realname.value,
|
2015-08-18 18:34:59 +00:00
|
|
|
"username": self.username.value,
|
2015-09-21 21:40:26 +00:00
|
|
|
"password": cpassword,
|
|
|
|
"confirm_password": cpassword,
|
2015-08-18 18:34:59 +00:00
|
|
|
}
|
2015-09-21 21:40:26 +00:00
|
|
|
|
2015-08-18 18:34:59 +00:00
|
|
|
log.debug("User input: {}".format(result))
|
2015-09-25 02:30:04 +00:00
|
|
|
self.signal.emit_signal('installprogress:curtin-install', result)
|
2015-08-18 18:34:59 +00:00
|
|
|
|
|
|
|
def cancel(self, button):
|
2015-10-29 20:58:51 +00:00
|
|
|
self.signal.prev_signal()
|