mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 04:10:20 +08:00
feat: fix the Email provider fails to match bug in GetProviderByCategoryAndRule()
This commit is contained in:
@ -38,6 +38,19 @@ func (application *Application) GetProviderByCategory(category string) (*Provide
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func isProviderItemCountryCodeMatched(providerItem *ProviderItem, countryCode string) bool {
|
||||
if len(providerItem.CountryCode) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, countryCode2 := range providerItem.CountryCode {
|
||||
if countryCode2 == "" || countryCode2 == "All" || countryCode2 == "all" || countryCode2 == countryCode {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (application *Application) GetProviderByCategoryAndRule(category string, method string, countryCode string) (*Provider, error) {
|
||||
providers, err := GetProviders(application.Organization)
|
||||
if err != nil {
|
||||
@ -54,15 +67,13 @@ func (application *Application) GetProviderByCategoryAndRule(category string, me
|
||||
}
|
||||
|
||||
for _, providerItem := range application.Providers {
|
||||
includeCode := false
|
||||
if providerItem.CountryCode != nil {
|
||||
for _, item := range providerItem.CountryCode {
|
||||
if item == countryCode || item == "All" || item == "" {
|
||||
includeCode = true
|
||||
}
|
||||
if providerItem.Provider != nil && providerItem.Provider.Category == "SMS" {
|
||||
if !isProviderItemCountryCodeMatched(providerItem, countryCode) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if (providerItem.Rule == method || (providerItem.Rule == "All" || providerItem.Rule == "" || providerItem.Rule == "None")) && includeCode {
|
||||
|
||||
if providerItem.Rule == method || providerItem.Rule == "" || providerItem.Rule == "All" || providerItem.Rule == "all" || providerItem.Rule == "None" {
|
||||
if provider, ok := m[providerItem.Name]; ok {
|
||||
return provider, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user