def ask_for_password(): global my_password FOO.change_flow(True) while FOO.flow_control_is(True): my_password = FOO.question(""" Now please enter your custom password. Create a new one if you don't have one already. Password: """) if not FOO.ANNOYANCE and my_password: FOO.text(""" Oops, sorry! That was plain-text. Don't worry, this is no error, it's just that \ I can't help it, because there's no cross-platform Python \ function that I know of which has predictable 'asterisk' behavior.""", """ Also, you're the developer, it's up to you to create your desired behavior. I'm \ but a humble automatic TUTORIAL.""", end = "") FOO.ANNOYANCE = True elif not my_password: if not FOO.ANNOYANCE2: FOO.text(""" Really!? No password? Well, we've got a badass here, your call.""", end = "") FOO.ANNOYANCE2 = True else: FOO.text("<blank password>", end = "", skip = True) FOO.yn_question(""" Do you want to change your password?""")
def store_keys_routine(): FOO.text(""" So, we'll store the keys you provided. """) try: store_keys except NameError: FOO.text("""\ First we need to import store_keys, which is found in src/security/key_handling.py """) #################################### ## imports are important from src.security.key_handling import store_keys FOO.echo_import (store_keys) FOO.text("", end = "") #################################### FOO.text(""" Now I will call >> store_keys({username},{{...}},'***') # <- Your keys and password go here This function has other optional fields. Most relevantly context='OGS' is default \ behavior, but it can be changed to 'OGS_Beta for testing.'""".format(username = repr(username))) while not FOO.flow_control_is(True): try: store_keys(username, keys, my_password) FOO.text(""" We've successfully stored your keys. Now you can simply use your username and \ password to retrieve them every time. """) FOO.change_flow(True) except ValueError as e: FOO.text(""" Something about your keys doesn't look right... I got this error message: {error} """.format(error = e)) ask_for_keys(force_change = True)
def ask_for_keys(force_change = False): ## Asks for keys, what else? global client_id, client_secret, password, keys if force_change: FOO.change_flow(True) else: FOO.yn_question ("""\ Do you want to set up new keys?""") while FOO.flow_control_is(True): FOO.text(""" Please type in your keys as asked""", skip = True) client_id = FOO.question ("... Client ID ..: ") client_secret = FOO.question (". Client Secret : ") password = FOO.question ("... Password ...: ") keys = {'client_id': client_id, 'client_secret': client_secret, 'password': password} FOO.yn_question ("""\ Do you want to make any changes to the previous keys?""") FOO.text(""" Alright! It seems you have your keys ready and you're good to go! """)
First I'll call >> get_keys_directory({username}) which will look into keys_loc.json . Beware the possible KeysDirectoryNotFound. """.format(username = repr(username)), end = "") ############################# ## This is a good way to start checking, ## although in most cases you'll know beforehand if the keys are there ############################# try: directory = get_keys_directory(username) FOO.change_flow(True) FOO.text("\n\nSo, apparently, you've been here before. Good!") except KeysDirectoryNotFound: FOO.text("""\n Alas! I couldn't find any valid directory belonging to you. But don't you worry, we'll get there.""") ############################# ## And thus we set the keys directory ## this can be anywhere on your disk ############################# if not FOO.flow_control_is(True): directory = FOO.question(""" Please type a valid directory where you want to store your keys. Full path: """)