mirror of
https://github.com/hrfee/jellyfin-accounts.git
synced 2026-02-03 08:01:12 +00:00
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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user