|
|
|
@ -2,7 +2,7 @@
|
|
|
|
|
|
|
|
|
|
import gc
|
|
|
|
|
|
|
|
|
|
from flask import session
|
|
|
|
|
from flask import session, request
|
|
|
|
|
from flask_restx import Resource, Namespace, reqparse
|
|
|
|
|
|
|
|
|
|
from app.config import settings
|
|
|
|
@ -22,21 +22,29 @@ class SystemAccount(Resource):
|
|
|
|
|
@api_ns_system_account.doc(parser=post_request_parser)
|
|
|
|
|
@api_ns_system_account.response(204, 'Success')
|
|
|
|
|
@api_ns_system_account.response(400, 'Unknown action')
|
|
|
|
|
@api_ns_system_account.response(404, 'Unknown authentication type define in config.ini')
|
|
|
|
|
@api_ns_system_account.response(403, 'Authentication failed')
|
|
|
|
|
@api_ns_system_account.response(406, 'Browser must be closed to invalidate basic authentication')
|
|
|
|
|
@api_ns_system_account.response(500, 'Unknown authentication type define in config.ini')
|
|
|
|
|
def post(self):
|
|
|
|
|
"""Login or logout from Bazarr UI when using form login"""
|
|
|
|
|
args = self.post_request_parser.parse_args()
|
|
|
|
|
if settings.auth.type != 'form':
|
|
|
|
|
return 'Unknown authentication type define in config.ini', 404
|
|
|
|
|
return 'Unknown authentication type define in config.ini', 500
|
|
|
|
|
|
|
|
|
|
action = args.get('action')
|
|
|
|
|
if action == 'login':
|
|
|
|
|
username = args.get('username')
|
|
|
|
|
password = args.get('password')
|
|
|
|
|
if check_credentials(username, password):
|
|
|
|
|
if check_credentials(username, password, request):
|
|
|
|
|
session['logged_in'] = True
|
|
|
|
|
return '', 204
|
|
|
|
|
else:
|
|
|
|
|
session['logged_in'] = False
|
|
|
|
|
return 'Authentication failed', 403
|
|
|
|
|
elif action == 'logout':
|
|
|
|
|
if settings.auth.type == 'basic':
|
|
|
|
|
return 'Browser must be closed to invalidate basic authentication', 406
|
|
|
|
|
else:
|
|
|
|
|
session.clear()
|
|
|
|
|
gc.collect()
|
|
|
|
|
return '', 204
|
|
|
|
|