def delete_user(): """ Delete a user """ userid = get_user_id() if userid == "": return ptext = util.sprintf("delete_user: Are you REALLY REALLY REALLY sure that you want to delete user {%s}? (y/Y=yes; anything else=no): ", userid) yesorno = prompt(ptext) if yesorno in ("y", "Y"): with app.app_context(): # Open database dbpath = app.config["DBPATH"] util.dbopen(dbpath) # User exists? row = util.dbuser_get(userid) if row is None: app.logger.error("delete_user: User {%s} does not exist", userid) util.dbclose() return # Remove user if util.dbuser_remove(userid): app.logger.info("delete_user: User {%s} deleted", userid) # Close database util.dbclose() else: print("delete_user: Cancelled")
def reset_password(): """ Reset a user's password to RESET_PASSWORD """ userid = get_user_id() if userid == "": return ptext = util.sprintf("reset_password: Are you REALLY REALLY REALLY sure that you want to reset the password of user {%s}? (y/Y=yes; anything else=no): ", userid) yesorno = prompt(ptext) if yesorno in ("y", "Y"): with app.app_context(): # Open database dbpath = app.config["DBPATH"] util.dbopen(dbpath) # Reset password hashed_password = util.hash_a_secret(RESET_PASSWORD) # Update the user's password if util.dbuser_update_password(userid, hashed_password): app.logger.info("reset_password: User {%s} password set to {%s}", userid, RESET_PASSWORD) # Close database util.dbclose() else: print("reset_password: Cancelled")
ssl_key_file = app.config["SSL_KEY_FILE"] app.logger.info("SSL_KEY_FILE = %s", ssl_key_file) if not os.path.isfile(ssl_key_file): with app.app_context(): util.oops("SSL key file {%s} inaccessible", ssl_key_file) # Get and process Web Server SSL certificate file parameter ssl_crt_file = app.config["SSL_CRT_FILE"] app.logger.info("SSL_CRT_FILE = %s", ssl_crt_file) if not os.path.isfile(ssl_crt_file): with app.app_context(): util.oops("SSL CRT file {%s} inaccessible", ssl_crt_file) # Open database dbpath = app.config["DBPATH"] app.logger.info("DBPATH = %s", dbpath) with app.app_context(): util.dbopen(dbpath) # Establish session parameters app.config["SECRET_KEY"] = os.urandom(24) app.logger.info("PERMANENT_SESSION_LIFETIME = %d", app.config["PERMANENT_SESSION_LIFETIME"]) SESSION_COOKIE_NAME = app.config["SESSION_COOKIE_NAME"] app.logger.info("SESSION_COOKIE_NAME = %s", str(app.config["SESSION_COOKIE_NAME"])) # Get the remaining configuration parameters app.logger.info("DEBUG = %s", str(app.config["DEBUG"])) str_port = app.config["PORT"] app.logger.info("PORT = %s", str_port) pid_path = app.config["PID_PATH"] app.logger.info("PID_PATH = %s", pid_path) # Validate TCP port number as numeric anplutod in range tcp_port = -1