mirror of
https://github.com/hrfee/jellyfin-accounts.git
synced 2025-12-08 11:39:33 +00:00
Add setup wizard
Added a setup wizard that appears on first run, or when no config dir is found.
This commit is contained in:
@@ -177,3 +177,7 @@ class Smtp(Email):
|
||||
err = f'{self.address}: Failed to send via smtp: '
|
||||
err += type(e).__name__
|
||||
log.error(err)
|
||||
try:
|
||||
log.error(e.smtp_error)
|
||||
except:
|
||||
pass
|
||||
|
||||
76
jellyfin_accounts/setup.py
Normal file
76
jellyfin_accounts/setup.py
Normal file
@@ -0,0 +1,76 @@
|
||||
from flask import request, jsonify, render_template
|
||||
from configparser import RawConfigParser
|
||||
from jellyfin_accounts.jf_api import Jellyfin
|
||||
from __main__ import config, config_path, app, first_run
|
||||
from __main__ import web_log as log
|
||||
import os
|
||||
|
||||
if first_run:
|
||||
def resp(success=True, code=500):
|
||||
if success:
|
||||
r = jsonify({'success': True})
|
||||
r.status_code = 200
|
||||
else:
|
||||
r = jsonify({'success': False})
|
||||
r.status_code = code
|
||||
return r
|
||||
|
||||
def tempJF(server):
|
||||
return Jellyfin(server,
|
||||
config['jellyfin']['client'],
|
||||
config['jellyfin']['version'],
|
||||
config['jellyfin']['device'] + '_temp',
|
||||
config['jellyfin']['device_id'] + '_temp')
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(e):
|
||||
return render_template('404.html'), 404
|
||||
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
def setup():
|
||||
return render_template('setup.html')
|
||||
|
||||
|
||||
@app.route('/<path:path>')
|
||||
def static_proxy(path):
|
||||
if 'html' not in path:
|
||||
return app.send_static_file(path)
|
||||
else:
|
||||
return render_template('404.html'), 404
|
||||
|
||||
|
||||
@app.route('/modifyConfig', methods=['POST'])
|
||||
def modifyConfig():
|
||||
log.info('Config modification requested')
|
||||
data = request.get_json()
|
||||
temp_config = RawConfigParser(comment_prefixes='/',
|
||||
allow_no_value=True)
|
||||
temp_config.read(config_path)
|
||||
for section in data:
|
||||
if section in temp_config:
|
||||
for item in data[section]:
|
||||
if item in temp_config[section]:
|
||||
temp_config[section][item] = data[section][item]
|
||||
data[section][item] = True
|
||||
log.debug(f'{section}/{item} modified')
|
||||
else:
|
||||
data[section][item] = False
|
||||
log.debug(f'{section}/{item} does not exist in config')
|
||||
with open(config_path, 'w') as config_file:
|
||||
temp_config.write(config_file)
|
||||
log.debug('Config written')
|
||||
os._exit(1)
|
||||
return resp()
|
||||
|
||||
|
||||
@app.route('/testJF', methods=['GET', 'POST'])
|
||||
def testJF():
|
||||
data = request.get_json()
|
||||
tempjf = tempJF(data['jfHost'])
|
||||
try:
|
||||
tempjf.authenticate(data['jfUser'],
|
||||
data['jfPassword'])
|
||||
tempjf.getUsers(public=False)
|
||||
return resp()
|
||||
except:
|
||||
return resp(False)
|
||||
@@ -20,7 +20,7 @@ def admin():
|
||||
|
||||
@app.route('/<path:path>')
|
||||
def static_proxy(path):
|
||||
if 'form.html' not in path and 'admin.html' not in path:
|
||||
if 'html' not in path:
|
||||
return app.send_static_file(path)
|
||||
return render_template('404.html',
|
||||
contactMessage=config['ui']['contact_message']), 404
|
||||
|
||||
@@ -266,30 +266,6 @@ def get_token():
|
||||
return jsonify({'token': token.decode('ascii')})
|
||||
|
||||
|
||||
@app.route('/modifyConfig', methods=['POST'])
|
||||
@auth.login_required
|
||||
def modifyConfig():
|
||||
log.info('Config modification requested')
|
||||
data = request.get_json()
|
||||
temp_config = RawConfigParser(comment_prefixes='/',
|
||||
allow_no_value=True)
|
||||
temp_config.read(config_path)
|
||||
for section in data:
|
||||
if section in temp_config:
|
||||
for item in data[section]:
|
||||
if item in temp_config[section]:
|
||||
temp_config[section][item] = data[section][item]
|
||||
data[section][item] = True
|
||||
log.debug(f'{section}/{item} modified')
|
||||
else:
|
||||
data[section][item] = False
|
||||
log.debug(f'{section}/{item} does not exist in config')
|
||||
with open(config_path, 'w') as config_file:
|
||||
temp_config.write(config_file)
|
||||
log.debug('Config written')
|
||||
return jsonify(data)
|
||||
|
||||
|
||||
@app.route('/getUsers', methods=['GET', 'POST'])
|
||||
@auth.login_required
|
||||
def getUsers():
|
||||
@@ -333,4 +309,4 @@ def modifyUsers():
|
||||
except:
|
||||
return resp(success=False)
|
||||
|
||||
|
||||
import jellyfin_accounts.setup
|
||||
|
||||
Reference in New Issue
Block a user