From 0b823c2c7a5956e2119043001691c1e457d2fd1a Mon Sep 17 00:00:00 2001 From: Ralph Comia Date: Fri, 20 Oct 2023 20:32:54 +0800 Subject: [PATCH 1/2] add helpers for adding admin pass and email address to credential.yml --- helpers/add_authemail.py | 26 ++++++++++++++++++++++++++ helpers/edit_authadmin_password.py | 24 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100755 helpers/add_authemail.py create mode 100644 helpers/edit_authadmin_password.py diff --git a/helpers/add_authemail.py b/helpers/add_authemail.py new file mode 100755 index 00000000..3096871c --- /dev/null +++ b/helpers/add_authemail.py @@ -0,0 +1,26 @@ +import streamlit_authenticator as stauth +import ruamel.yaml as yaml +import os + +# enter email address +new_email = input("Enter dashboard email >> ") + +# if user enter no email address, exit setup! +if len(new_email) == 0: + print("\nNo email added, please try again!\n") + exit() + + +# load the YAML file +yaml_file = "../credentials.yml" +with open(yaml_file, "r") as file: + data = yaml.safe_load(file) + +# update the admin password on credentials.yml +data["preauthorized"]["emails"].append(new_email) + +# write the updated data back to the file +with open(yaml_file, "w") as file: + yaml.dump(data, file, Dumper=yaml.RoundTripDumper) + +print("Email has been added") diff --git a/helpers/edit_authadmin_password.py b/helpers/edit_authadmin_password.py new file mode 100644 index 00000000..b2230c01 --- /dev/null +++ b/helpers/edit_authadmin_password.py @@ -0,0 +1,24 @@ +import streamlit_authenticator as stauth +import ruamel.yaml as yaml +import os + +# enter admin password or use default t3st01 +new_password = input("Enter dashboard password >> ") +new_password = new_password or "t3st01" + +# extract the hash password from the List +hash_password = stauth.Hasher([new_password]).generate()[0] + +# load the YAML file +yaml_file = "../credentials.yml" +with open(yaml_file, "r") as file: + data = yaml.safe_load(file) + +# update the admin password on credentials.yml +data["credentials"]["usernames"]["admin"]["password"] = hash_password + +# write the updated data back to the file +with open(yaml_file, "w") as file: + yaml.dump(data, file, Dumper=yaml.RoundTripDumper) + +print("Admin password has been updated! ") From 7e12d89db79aeb3be42429f76520008db406b745 Mon Sep 17 00:00:00 2001 From: rapcmia <73840223+rapcmia@users.noreply.github.com> Date: Fri, 20 Oct 2023 20:35:34 +0800 Subject: [PATCH 2/2] Update add_authemail.py --- helpers/add_authemail.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/helpers/add_authemail.py b/helpers/add_authemail.py index 3096871c..39b8bc07 100755 --- a/helpers/add_authemail.py +++ b/helpers/add_authemail.py @@ -10,17 +10,16 @@ print("\nNo email added, please try again!\n") exit() - # load the YAML file yaml_file = "../credentials.yml" with open(yaml_file, "r") as file: data = yaml.safe_load(file) -# update the admin password on credentials.yml +# append the email address to credentials.yml data["preauthorized"]["emails"].append(new_email) # write the updated data back to the file with open(yaml_file, "w") as file: yaml.dump(data, file, Dumper=yaml.RoundTripDumper) -print("Email has been added") +print("Email has been successfully added!")