Completed basic handling of authentication settings save process to the database.

This commit is contained in:
Matt Scott 2023-04-10 13:24:42 -04:00
parent 2e30b83545
commit 6a19ed2903
No known key found for this signature in database
GPG Key ID: A9A0AFFC0E079001
3 changed files with 26 additions and 19 deletions

View File

@ -431,6 +431,10 @@ class Setting(db.Model):
if value in ['True', 'False']: if value in ['True', 'False']:
value = strtobool(value) value = strtobool(value)
elif value.isdecimal() and '.' in value:
value = float(value)
elif value.isnumeric():
value = int(value)
result[record.name] = value result[record.name] = value

View File

@ -1836,9 +1836,12 @@ def setting_authentication_api():
result = {'status': 1, 'messages': [], 'data': {}} result = {'status': 1, 'messages': [], 'data': {}}
if request.form.get('commit') == '1': if request.form.get('commit') == '1':
result['messages'].append('Saved successfully.') model = Setting()
else: data = json.loads(request.form.get('data'))
result['messages'].append('Loaded successfully.')
for key, value in data.items():
if key in model.groups['authentication']:
model.set(key, value)
result['data'] = Setting().get_group('authentication') result['data'] = Setting().get_group('authentication')

View File

@ -10,19 +10,19 @@ let AuthenticationSettingsModel = function (user_data, api_url, csrf_token, sele
let defaults = { let defaults = {
// Local Authentication Settings // Local Authentication Settings
local_db_enabled: true, local_db_enabled: 1,
signup_enabled: true, signup_enabled: 1,
pwd_enforce_characters: false, pwd_enforce_characters: 0,
pwd_min_len: 10, pwd_min_len: 10,
pwd_min_lowercase: 3, pwd_min_lowercase: 3,
pwd_min_uppercase: 2, pwd_min_uppercase: 2,
pwd_min_digits: 2, pwd_min_digits: 2,
pwd_min_special: 1, pwd_min_special: 1,
pwd_enforce_complexity: false, pwd_enforce_complexity: 0,
pwd_min_complexity: 11, pwd_min_complexity: 11,
// LDAP Authentication Settings // LDAP Authentication Settings
ldap_enabled: false, ldap_enabled: 0,
ldap_type: 'ldap', ldap_type: 'ldap',
ldap_uri: '', ldap_uri: '',
ldap_base_dn: '', ldap_base_dn: '',
@ -43,54 +43,54 @@ let AuthenticationSettingsModel = function (user_data, api_url, csrf_token, sele
purge: 0, purge: 0,
// Google OAuth2 Settings // Google OAuth2 Settings
google_oauth_enabled: false, google_oauth_enabled: 0,
google_oauth_client_id: '', google_oauth_client_id: '',
google_oauth_client_secret: '', google_oauth_client_secret: '',
google_oauth_scope: '', google_oauth_scope: '',
google_base_url: '', google_base_url: '',
google_oauth_auto_configure: true, google_oauth_auto_configure: 1,
google_oauth_metadata_url: '', google_oauth_metadata_url: '',
google_token_url: '', google_token_url: '',
google_authorize_url: '', google_authorize_url: '',
// GitHub OAuth2 Settings // GitHub OAuth2 Settings
github_oauth_enabled: false, github_oauth_enabled: 0,
github_oauth_key: '', github_oauth_key: '',
github_oauth_secret: '', github_oauth_secret: '',
github_oauth_scope: '', github_oauth_scope: '',
github_oauth_api_url: '', github_oauth_api_url: '',
github_oauth_auto_configure: false, github_oauth_auto_configure: 0,
github_oauth_metadata_url: '', github_oauth_metadata_url: '',
github_oauth_token_url: '', github_oauth_token_url: '',
github_oauth_authorize_url: '', github_oauth_authorize_url: '',
// Azure AD OAuth2 Settings // Azure AD OAuth2 Settings
azure_oauth_enabled: false, azure_oauth_enabled: 0,
azure_oauth_key: '', azure_oauth_key: '',
azure_oauth_secret: '', azure_oauth_secret: '',
azure_oauth_scope: '', azure_oauth_scope: '',
azure_oauth_api_url: '', azure_oauth_api_url: '',
azure_oauth_auto_configure: true, azure_oauth_auto_configure: 1,
azure_oauth_metadata_url: '', azure_oauth_metadata_url: '',
azure_oauth_token_url: '', azure_oauth_token_url: '',
azure_oauth_authorize_url: '', azure_oauth_authorize_url: '',
azure_sg_enabled: false, azure_sg_enabled: 0,
azure_admin_group: '', azure_admin_group: '',
azure_operator_group: '', azure_operator_group: '',
azure_user_group: '', azure_user_group: '',
azure_group_accounts_enabled: false, azure_group_accounts_enabled: 0,
azure_group_accounts_name: '', azure_group_accounts_name: '',
azure_group_accounts_name_re: '', azure_group_accounts_name_re: '',
azure_group_accounts_description: '', azure_group_accounts_description: '',
azure_group_accounts_description_re: '', azure_group_accounts_description_re: '',
// OIDC OAuth2 Settings // OIDC OAuth2 Settings
oidc_oauth_enabled: false, oidc_oauth_enabled: 0,
oidc_oauth_key: '', oidc_oauth_key: '',
oidc_oauth_secret: '', oidc_oauth_secret: '',
oidc_oauth_scope: '', oidc_oauth_scope: '',
oidc_oauth_api_url: '', oidc_oauth_api_url: '',
oidc_oauth_auto_configure: true, oidc_oauth_auto_configure: 1,
oidc_oauth_metadata_url: '', oidc_oauth_metadata_url: '',
oidc_oauth_token_url: '', oidc_oauth_token_url: '',
oidc_oauth_authorize_url: '', oidc_oauth_authorize_url: '',
@ -150,7 +150,7 @@ let AuthenticationSettingsModel = function (user_data, api_url, csrf_token, sele
$.ajax({ $.ajax({
url: self.api_url, url: self.api_url,
type: 'POST', type: 'POST',
data: {_csrf_token: csrf_token, commit: 1, data: JSON.parse(ko.toJSON(self))}, data: {_csrf_token: csrf_token, commit: 1, data: ko.toJSON(self)},
dataType: 'json', dataType: 'json',
success: self.onDataSaved success: self.onDataSaved
}); });