Skip to content

Commit

Permalink
Fix default methods using friendly name, add indicator for default mf…
Browse files Browse the repository at this point in the history
…a method, fix reordering of issuer/domain
  • Loading branch information
NHAS committed Nov 23, 2024
1 parent 0446dbc commit 3349ffc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions adminui2/src/pages/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { useToast } from 'vue-toastification'
import { useToastError } from '@/composables/useToastError'
import { useAuthStore } from '@/stores/auth'
import { getMFAMethods, getGeneralSettings, getLoginSettings, updateGeneralSettings, updateLoginSettings, type GeneralSettingsResponseDTO as GeneralSettingsDTO, type LoginSettingsResponseDTO as LoginSettingsDTO } from '@/api'
import { getMFAMethods, getGeneralSettings, getLoginSettings, updateGeneralSettings, updateLoginSettings, type GeneralSettingsResponseDTO as GeneralSettingsDTO, type LoginSettingsResponseDTO as LoginSettingsDTO } from '@/api'
import { useApi } from '@/composables/useApi'
import PageLoading from '@/components/PageLoading.vue'
import { type MFAMethodDTO } from '@/api'
const authStore = useAuthStore()
const { loggedInUser } = storeToRefs(authStore)
Expand Down Expand Up @@ -64,13 +65,17 @@ async function saveLoginSettings() {
toast.error(resp.message ?? 'Failed')
return
} else {
toast.success('Saved general settings')
toast.success('Saved login settings')
}
} catch (e) {
catcher(e, 'failed to save general settings: ')
catcher(e, 'failed to save login settings: ')
}
}
function filterMfaMethods(enabledMethods: string[], allMethods: MFAMethodDTO[]): MFAMethodDTO[] {
return allMethods.filter((x) => enabledMethods.indexOf(x.method) != -1)
}
</script>

Expand Down Expand Up @@ -153,15 +158,17 @@ async function saveLoginSettings() {
<label for="default_method" class="label font-bold">Default MFA Method</label>
<select class="select select-bordered " name="default_method"
v-model="loginSettingsData.default_mfa_method">
<option v-for="method in loginSettingsData.enabled_mfa_methods"
:selected="method == loginSettingsData.default_mfa_method" :value="method">{{ method }}</option>
<option v-for="method in filterMfaMethods(loginSettingsData.enabled_mfa_methods, mfaTypes ?? [])"
:selected="method.method == loginSettingsData.default_mfa_method" :value="method.method">{{ method.friendly_name }}</option>
</select>
</div>

<div class="flex flex-col">
<div v-for="method in mfaTypes" class="form-control w-full">
<label :for=method.method class="label cursor-pointer">
<span class="label-text">{{ method.friendly_name }}</span>
<span class="flex flex-grow"></span>
<span v-if="method.method == loginSettingsData.default_mfa_method" class="text-gray-400 mr-4">DEFAULT</span>
<input :name=method.method type="checkbox" class="toggle toggle-primary" :value="method.method"
v-model="loginSettingsData.enabled_mfa_methods"
:checked="loginSettingsData.enabled_mfa_methods.indexOf(method.method) != -1" />
Expand Down
4 changes: 2 additions & 2 deletions internal/data/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,14 @@ func GetLoginSettings() (s LoginSettings, err error) {
}

if response.Responses[5].GetResponseRange().Count == 1 {
err = json.Unmarshal(response.Responses[5].GetResponseRange().Kvs[0].Value, &s.Issuer)
err = json.Unmarshal(response.Responses[5].GetResponseRange().Kvs[0].Value, &s.Domain)
if err != nil {
return s, err
}
}

if response.Responses[6].GetResponseRange().Count == 1 {
err = json.Unmarshal(response.Responses[6].GetResponseRange().Kvs[0].Value, &s.Domain)
err = json.Unmarshal(response.Responses[6].GetResponseRange().Kvs[0].Value, &s.Issuer)
if err != nil {
return s, err
}
Expand Down

0 comments on commit 3349ffc

Please sign in to comment.