mirror of
https://github.com/morpheus65535/bazarr
synced 2025-03-01 09:05:57 +00:00
WIP
This commit is contained in:
parent
5831c415b6
commit
7332acd67a
4 changed files with 45 additions and 32 deletions
|
@ -3,6 +3,8 @@
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import rarfile
|
import rarfile
|
||||||
|
import json
|
||||||
|
import hashlib
|
||||||
|
|
||||||
from cork import Cork
|
from cork import Cork
|
||||||
from config import settings, configure_captcha_func
|
from config import settings, configure_captcha_func
|
||||||
|
@ -88,22 +90,27 @@ if not os.path.exists(os.path.join(args.config_dir, 'config', 'releases.txt')):
|
||||||
|
|
||||||
config_file = os.path.normpath(os.path.join(args.config_dir, 'config', 'config.ini'))
|
config_file = os.path.normpath(os.path.join(args.config_dir, 'config', 'config.ini'))
|
||||||
|
|
||||||
if not os.path.exists(os.path.normpath(os.path.join(args.config_dir, 'config', 'users.json'))):
|
# Reset form login password for Bazarr after migration from 0.8.x to 0.9. Password will be equal to username.
|
||||||
cork = Cork(os.path.normpath(os.path.join(args.config_dir, 'config')), initialize=True)
|
if settings.auth.type == 'form' and \
|
||||||
|
os.path.exists(os.path.normpath(os.path.join(args.config_dir, 'config', 'users.json'))):
|
||||||
cork._store.roles[''] = 100
|
username = False
|
||||||
cork._store.save_roles()
|
with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'users.json'))) as json_file:
|
||||||
|
try:
|
||||||
tstamp = str(time.time())
|
data = json.load(json_file)
|
||||||
username = password = ''
|
username = next(iter(data))
|
||||||
cork._store.users[username] = {
|
except:
|
||||||
'role': '',
|
logging.error('BAZARR is unable to migrate credentials. You should disable login by modifying config.ini '
|
||||||
'hash': cork._hash(username, password),
|
'file and settings [auth]-->type = None')
|
||||||
'email_addr': username,
|
if username:
|
||||||
'desc': username,
|
settings.auth.username = username
|
||||||
'creation_date': tstamp
|
settings.auth.password = hashlib.md5(username.encode('utf-8')).hexdigest()
|
||||||
}
|
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
|
||||||
cork._store.save_users()
|
settings.write(handle)
|
||||||
|
os.remove(os.path.normpath(os.path.join(args.config_dir, 'config', 'users.json')))
|
||||||
|
os.remove(os.path.normpath(os.path.join(args.config_dir, 'config', 'roles.json')))
|
||||||
|
os.remove(os.path.normpath(os.path.join(args.config_dir, 'config', 'register.json')))
|
||||||
|
logging.info('BAZARR your login credentials have been migrated successfully and your password is now equal '
|
||||||
|
'to your username. Please change it as sson as possible in settings.')
|
||||||
|
|
||||||
|
|
||||||
def init_binaries():
|
def init_binaries():
|
||||||
|
|
|
@ -105,6 +105,9 @@ def login_required(f):
|
||||||
@app.route('/login/', methods=["GET", "POST"])
|
@app.route('/login/', methods=["GET", "POST"])
|
||||||
def login_page():
|
def login_page():
|
||||||
error = ''
|
error = ''
|
||||||
|
password_reset = False
|
||||||
|
if settings.auth.password == hashlib.md5(settings.auth.username.encode('utf-8')).hexdigest():
|
||||||
|
password_reset = True
|
||||||
try:
|
try:
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
if check_credentials(request.form['username'], request.form['password']):
|
if check_credentials(request.form['username'], request.form['password']):
|
||||||
|
@ -117,7 +120,7 @@ def login_page():
|
||||||
error = "Invalid credentials, try again."
|
error = "Invalid credentials, try again."
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
return render_template("login.html", error=error)
|
return render_template("login.html", error=error, password_reset=password_reset)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# flash(e)
|
# flash(e)
|
||||||
|
|
|
@ -307,6 +307,7 @@
|
||||||
<script src="{{ url_for('static',filename='js/jquery.typeahead.min.js') }}"></script>
|
<script src="{{ url_for('static',filename='js/jquery.typeahead.min.js') }}"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
{% if not request.endpoint == 'login_page' %}
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
BadgesAjax();
|
BadgesAjax();
|
||||||
$(window).on('load resize', function () {
|
$(window).on('load resize', function () {
|
||||||
|
@ -403,9 +404,6 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
{% if request.endpoint == 'login_page' %}
|
|
||||||
// Apikey excluded from login_page
|
|
||||||
{% else %}
|
|
||||||
// Add apikey to all AJAX requests.
|
// Add apikey to all AJAX requests.
|
||||||
$.ajaxSetup({
|
$.ajaxSetup({
|
||||||
data: {
|
data: {
|
||||||
|
@ -417,7 +415,6 @@
|
||||||
originalOptions.data.append("apikey", "{{ settings.auth.apikey }}");
|
originalOptions.data.append("apikey", "{{ settings.auth.apikey }}");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
$(window).on('beforeunload', function () {
|
$(window).on('beforeunload', function () {
|
||||||
events.close();
|
events.close();
|
||||||
|
@ -453,6 +450,7 @@
|
||||||
async: true
|
async: true
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
{% endif %}
|
||||||
</script>
|
</script>
|
||||||
{% endblock tail_js %}
|
{% endblock tail_js %}
|
||||||
{% block tail %}
|
{% block tail %}
|
||||||
|
|
|
@ -31,6 +31,11 @@
|
||||||
<h6 class="text-danger"> {{ error }} </h6>
|
<h6 class="text-danger"> {{ error }} </h6>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if password_reset %}
|
||||||
|
<div class="alert alert-warning">
|
||||||
|
<h6 class="text-warning">Your password have been reset and is equal to your username. You should change it as soon as possible in settings.</h6>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
<div class="form-group text-center m-t-20">
|
<div class="form-group text-center m-t-20">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<button class="btn btn-info btn-lg btn-block text-uppercase waves-effect waves-light"
|
<button class="btn btn-info btn-lg btn-block text-uppercase waves-effect waves-light"
|
||||||
|
|
Loading…
Reference in a new issue