From 2b5b1ad83da34b73ae50dcccbf6e7f291e38b06b Mon Sep 17 00:00:00 2001 From: Rafael Fontenelle Date: Sun, 4 Apr 2021 11:28:54 -0300 Subject: Fix misspellings --- archinstall/lib/user_interaction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index 630862ee..8cdbbe8c 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -151,7 +151,7 @@ def ask_for_main_filesystem_format(): def generic_select(options, input_text="Select one of the above by index or absolute value: ", sort=True): """ A generic select function that does not output anything - other than the options and their indexs. As an example: + other than the options and their indexes. As an example: generic_select(["first", "second", "third option"]) 1: first -- cgit v1.2.3-54-g00ecf From 992ee851d4d57cdd11f490123f94c2c23f8c1e76 Mon Sep 17 00:00:00 2001 From: SecondThundeR Date: Sun, 4 Apr 2021 22:12:31 +0300 Subject: Add lowercase conversion for usernames --- archinstall/lib/user_interaction.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index 8cdbbe8c..e5cdb670 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -49,7 +49,7 @@ def print_large_list(options, padding=5, margin_bottom=0, separator=': '): def ask_for_superuser_account(prompt='Create a required super-user with sudo privileges: ', forced=False): while 1: - new_user = input(prompt).strip(' ') + new_user = input(prompt).strip(' ').lower() if not new_user and forced: # TODO: make this text more generic? @@ -67,7 +67,7 @@ def ask_for_additional_users(prompt='Any additional users to install (leave blan super_users = {} while 1: - new_user = input(prompt).strip(' ') + new_user = input(prompt).strip(' ').lower() if not new_user: break password = get_password(prompt=f'Password for user {new_user}: ') -- cgit v1.2.3-54-g00ecf From 69a873084593c32b2766315c02a1ddbcdac731d9 Mon Sep 17 00:00:00 2001 From: Zach Osman Date: Sun, 4 Apr 2021 16:14:13 -0400 Subject: Removing background color definitions for all log functions --- archinstall/lib/user_interaction.py | 5 ++--- examples/guided.py | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index 8cdbbe8c..e7243a25 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -22,7 +22,7 @@ def get_password(prompt="Enter a password: "): while (passwd := getpass.getpass(prompt)): passwd_verification = getpass.getpass(prompt='And one more time for verification: ') if passwd != passwd_verification: - log(' * Passwords did not match * ', bg='black', fg='red') + log(' * Passwords did not match * ', fg='red') continue if len(passwd.strip()) <= 0: @@ -54,7 +54,7 @@ def ask_for_superuser_account(prompt='Create a required super-user with sudo pri if not new_user and forced: # TODO: make this text more generic? # It's only used to create the first sudo user when root is disabled in guided.py - log(' * Since root is disabled, you need to create a least one (super) user!', bg='black', fg='red') + log(' * Since root is disabled, you need to create a least one (super) user!', fg='red') continue elif not new_user and not forced: raise UserError("No superuser was created.") @@ -108,7 +108,6 @@ def ask_to_configure_network(): log( "You need to enter a valid IP in IP-config mode.", level=LOG_LEVELS.Warning, - bg='black', fg='red' ) diff --git a/examples/guided.py b/examples/guided.py index 2e553c4d..a92343f7 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -176,7 +176,6 @@ def ask_user_questions(): if not imported._prep_function(): archinstall.log( ' * Profile\'s preparation requirements was not fulfilled.', - bg='black', fg='red' ) exit(1) -- cgit v1.2.3-54-g00ecf From 5de1154ce9708f770bacae5faa2ef3c3eea4c2e2 Mon Sep 17 00:00:00 2001 From: SecondThundeR Date: Mon, 5 Apr 2021 18:38:21 +0300 Subject: Replace lowercase conversion with correct checking --- archinstall/lib/user_interaction.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index e5cdb670..30008fad 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -1,4 +1,4 @@ -import getpass, pathlib, os, shutil +import getpass, pathlib, os, shutil, re from .exceptions import * from .profiles import Profile from .locale_helpers import search_keyboard_layout @@ -49,8 +49,15 @@ def print_large_list(options, padding=5, margin_bottom=0, separator=': '): def ask_for_superuser_account(prompt='Create a required super-user with sudo privileges: ', forced=False): while 1: - new_user = input(prompt).strip(' ').lower() - + new_user = input(prompt).strip(' ') + + if not re.match('[a-z_][a-z0-9_-]*[$]?', new_user) or len(new_user) > 32: + log( + "The username you entered is invalid. Try again", + level=LOG_LEVELS.Warning, + fg='red' + ) + continue if not new_user and forced: # TODO: make this text more generic? # It's only used to create the first sudo user when root is disabled in guided.py @@ -67,9 +74,16 @@ def ask_for_additional_users(prompt='Any additional users to install (leave blan super_users = {} while 1: - new_user = input(prompt).strip(' ').lower() + new_user = input(prompt).strip(' ') if not new_user: break + if not re.match('[a-z_][a-z0-9_-]*[$]?', new_user) or len(new_user) > 32: + log( + "The username you entered is invalid. Try again", + level=LOG_LEVELS.Warning, + fg='red' + ) + continue password = get_password(prompt=f'Password for user {new_user}: ') if input("Should this user be a sudo (super) user (y/N): ").strip(' ').lower() in ('y', 'yes'): -- cgit v1.2.3-54-g00ecf From ed2187ee709e40e9da50cec9f0eaf45e77d6a8e9 Mon Sep 17 00:00:00 2001 From: SecondThundeR Date: Mon, 5 Apr 2021 19:22:48 +0300 Subject: Update regex rule and move check to a function --- archinstall/lib/user_interaction.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index 30008fad..a337066e 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -18,6 +18,16 @@ def get_terminal_width(): def get_longest_option(options): return max([len(x) for x in options]) +def check_for_correct_username(username): + if re.match(r'^[a-z_][a-z0-9_-]*\$?$', username) and len(username) <= 32: + return True + log( + "The username you entered is invalid. Try again", + level=LOG_LEVELS.Warning, + fg='red' + ) + return False + def get_password(prompt="Enter a password: "): while (passwd := getpass.getpass(prompt)): passwd_verification = getpass.getpass(prompt='And one more time for verification: ') @@ -51,12 +61,7 @@ def ask_for_superuser_account(prompt='Create a required super-user with sudo pri while 1: new_user = input(prompt).strip(' ') - if not re.match('[a-z_][a-z0-9_-]*[$]?', new_user) or len(new_user) > 32: - log( - "The username you entered is invalid. Try again", - level=LOG_LEVELS.Warning, - fg='red' - ) + if not check_for_correct_username(new_user): continue if not new_user and forced: # TODO: make this text more generic? @@ -77,12 +82,7 @@ def ask_for_additional_users(prompt='Any additional users to install (leave blan new_user = input(prompt).strip(' ') if not new_user: break - if not re.match('[a-z_][a-z0-9_-]*[$]?', new_user) or len(new_user) > 32: - log( - "The username you entered is invalid. Try again", - level=LOG_LEVELS.Warning, - fg='red' - ) + if not check_for_correct_username(new_user): continue password = get_password(prompt=f'Password for user {new_user}: ') -- cgit v1.2.3-54-g00ecf From 924b369233e28c11c8bfec423fa25dc9d84e61de Mon Sep 17 00:00:00 2001 From: SecondThundeR Date: Mon, 5 Apr 2021 23:13:27 +0300 Subject: Fix incorrect behavior for empty sudo username --- archinstall/lib/user_interaction.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index a337066e..44c0cb13 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -61,8 +61,6 @@ def ask_for_superuser_account(prompt='Create a required super-user with sudo pri while 1: new_user = input(prompt).strip(' ') - if not check_for_correct_username(new_user): - continue if not new_user and forced: # TODO: make this text more generic? # It's only used to create the first sudo user when root is disabled in guided.py @@ -70,6 +68,8 @@ def ask_for_superuser_account(prompt='Create a required super-user with sudo pri continue elif not new_user and not forced: raise UserError("No superuser was created.") + elif not check_for_correct_username(new_user): + continue password = get_password(prompt=f'Password for user {new_user}: ') return {new_user: {"!password" : password}} -- cgit v1.2.3-54-g00ecf