implement CLI password recovery (hacky :omg:)

+ rewrite migrations logic
+ rename encode_password to hash_password
+ update image sizes (add medium size)
+ rename image endpoints
This commit is contained in:
cwilvx
2024-05-11 21:26:03 +03:00
parent 1e857c1e89
commit b40f05cc7c
21 changed files with 306 additions and 152 deletions
+55 -8
View File
@@ -2,6 +2,7 @@
Handles arguments passed to the program.
"""
from getpass import getpass
import os.path
import sys
@@ -10,27 +11,37 @@ import PyInstaller.__main__ as bundler
from app import settings
from app.logger import log
from app.print_help import HELP_MESSAGE
from app.utils.auth import hash_password
from app.utils.paths import getFlaskOpenApiPath
from app.utils.xdg_utils import get_xdg_config_dir
from app.utils.wintools import is_windows
from app.db.sqlite.auth import SQLiteAuthMethods as authdb
ALLARGS = settings.ALLARGS
ARGS = sys.argv[1:]
class ProcessArgs:
"""
Processes the arguments passed to the program.
"""
def __init__(self) -> None:
# resolve config path
self.handle_config_path() # 1
# handles that exit
self.handle_password_recovery()
self.handle_build()
self.handle_host()
self.handle_port()
self.handle_config_path()
self.handle_periodic_scan()
self.handle_periodic_scan_interval()
self.handle_help()
self.handle_version()
# non-exiting handles
self.handle_host()
self.handle_port()
self.handle_periodic_scan()
self.handle_periodic_scan_interval()
@staticmethod
def handle_build():
"""
@@ -57,12 +68,13 @@ class ProcessArgs:
value = settings.Info.get(key)
if not value:
log.error(f"WARNING: {key} not set in environment")
log.error(f"WARNING: {key} not resolved. Exiting ...")
sys.exit(0)
lines.append(f'{key} = "{value}"\n')
try:
# write the info to the config file
with open("./app/configs.py", "w", encoding="utf-8") as file:
# copy the api keys to the config file
file.writelines(lines)
@@ -189,3 +201,38 @@ class ProcessArgs:
f"COMMIT#: {settings.Info.GIT_CURRENT_BRANCH}/{settings.Info.GIT_LATEST_COMMIT_HASH}"
)
sys.exit(0)
@staticmethod
def handle_password_recovery():
if ALLARGS.pswd in ARGS:
print("SWING MUSIC v2.0.0 ")
print("PASSWORD RECOVERY \n")
username: str = ""
password: str = ""
# collect username
try:
username = input("Enter username: ")
except KeyboardInterrupt:
print("\nOperation cancelled! Exiting ...")
sys.exit(0)
username = username.strip()
user = authdb.get_user_by_username(username)
if not user:
print(f"User {username} not found")
sys.exit(0)
# collect password
try:
password = getpass("Enter new password: ")
except KeyboardInterrupt:
print("\nOperation cancelled! Exiting ...")
sys.exit(0)
password = hash_password(password)
user = authdb.update_user({"id": user.id, "password": password})
sys.exit(0)