diff --git a/controllers/verification.go b/controllers/verification.go index ae7a533e..132f3ba0 100644 --- a/controllers/verification.go +++ b/controllers/verification.go @@ -164,7 +164,7 @@ func (c *ApiController) SendVerificationCode() { c.SetSession(MfaDestSession, vform.Dest) } - provider, err = application.GetEmailProvider() + provider, err = application.GetEmailProvider(vform.Method) if err != nil { c.ResponseError(err.Error()) return @@ -210,7 +210,7 @@ func (c *ApiController) SendVerificationCode() { vform.CountryCode = mfaProps.CountryCode } - provider, err = application.GetSmsProvider() + provider, err = application.GetSmsProvider(vform.Method) if err != nil { c.ResponseError(err.Error()) return diff --git a/object/application_item.go b/object/application_item.go index 7125593d..c668d1e9 100644 --- a/object/application_item.go +++ b/object/application_item.go @@ -38,12 +38,38 @@ func (application *Application) GetProviderByCategory(category string) (*Provide return nil, nil } -func (application *Application) GetEmailProvider() (*Provider, error) { - return application.GetProviderByCategory("Email") +func (application *Application) GetProviderByCategoryAndRule(category string, method string) (*Provider, error) { + providers, err := GetProviders(application.Organization) + if err != nil { + return nil, err + } + + m := map[string]*Provider{} + for _, provider := range providers { + if provider.Category != category { + continue + } + + m[provider.Name] = provider + } + + for _, providerItem := range application.Providers { + if providerItem.Rule == method || providerItem.Rule == "all" { + if provider, ok := m[providerItem.Name]; ok { + return provider, nil + } + } + } + + return nil, nil } -func (application *Application) GetSmsProvider() (*Provider, error) { - return application.GetProviderByCategory("SMS") +func (application *Application) GetEmailProvider(method string) (*Provider, error) { + return application.GetProviderByCategoryAndRule("Email", method) +} + +func (application *Application) GetSmsProvider(method string) (*Provider, error) { + return application.GetProviderByCategoryAndRule("SMS", method) } func (application *Application) GetStorageProvider() (*Provider, error) { diff --git a/web/src/table/ProviderTable.js b/web/src/table/ProviderTable.js index c9383cac..a492a661 100644 --- a/web/src/table/ProviderTable.js +++ b/web/src/table/ProviderTable.js @@ -223,6 +223,26 @@ class ProviderTable extends React.Component { ); + } else if (record.provider?.category === "SMS" || record.provider?.category === "Email") { + if (text === "None") { + text = "all"; + } + return ( + + ); } else { return null; }