Modularized JSON storage

user_template and other files are now accessed via JSONStorage, which
has dictionary like attributes for each file which can be used like a
dictionary, without the need to manually read and write the file. This
was done so that other storage types (e.g a database) can be added in
future.
This commit is contained in:
2020-06-14 17:58:18 +01:00
parent 39a27eb762
commit f4f18d41ea
5 changed files with 197 additions and 184 deletions

View File

@@ -4,7 +4,7 @@ from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from jellyfin_accounts.email import Mailgun, Smtp
from jellyfin_accounts.web_api import jf
from __main__ import config
from __main__ import config, data_store
from __main__ import email_log as log
@@ -42,17 +42,18 @@ class Handler(FileSystemEventHandler):
reset = json.load(f)
log.info(f'New password reset for {reset["UserName"]}')
try:
with open(config['files']['emails'], 'r') as f:
emails = json.load(f)
id = jf.getUsers(reset['UserName'], public=False)['Id']
address = emails[id]
method = config['email']['method']
if method == 'mailgun':
email = Mailgun(address)
elif method == 'smtp':
email = Smtp(address)
if email.construct_reset(reset):
email.send()
id = jf.getUsers(reset['UserName'], public=False)['Id']
address = data_store.emails[id]
if address != '':
method = config['email']['method']
if method == 'mailgun':
email = Mailgun(address)
elif method == 'smtp':
email = Smtp(address)
if email.construct_reset(reset):
email.send()
else:
raise IndexError
except (FileNotFoundError,
json.decoder.JSONDecodeError,
IndexError) as e: