feat: add rule for SMS and Email provider (#2733)

* add phonecoderule

* feat:add phone code rule

* feat: add email rule

* fix: merge
This commit is contained in:
zhuying1999 2024-02-23 00:09:37 +08:00 committed by GitHub
parent 44abfb3430
commit 042a8d0ad6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 52 additions and 6 deletions

View File

@ -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

View File

@ -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) {

View File

@ -223,6 +223,26 @@ class ProviderTable extends React.Component {
<Option key="Always" value="Always">{i18next.t("application:Always")}</Option>
</Select>
);
} else if (record.provider?.category === "SMS" || record.provider?.category === "Email") {
if (text === "None") {
text = "all";
}
return (
<Select virtual={false} style={{width: "100%"}}
value={text}
defaultValue="all"
onChange={value => {
this.updateField(table, index, "rule", value);
}}>
<Option key="all" value="all">{"All"}</Option>
<Option key="signup" value="signup">{"Signup"}</Option>
<Option key="login" value="login">{"Login"}</Option>
<Option key="forget" value="forget">{"Forget Password"}</Option>
<Option key="reset" value="reset">{"Reset Password"}</Option>
<Option key="mfaSetup" value="mfaSetup">{"Set MFA"}</Option>
<Option key="mfaAuth" value="mfaAuth">{"MFA Auth"}</Option>
</Select>
);
} else {
return null;
}