feat: Support more flexible login method control (#2566)

This commit is contained in:
HGZ-20
2024-01-02 21:11:52 +08:00
committed by GitHub
parent 3373174c65
commit e3f28e8b4c
56 changed files with 737 additions and 190 deletions

View File

@ -342,7 +342,28 @@ func (c *ApiController) Login() {
return
}
var application *object.Application
application, err = object.GetApplication(fmt.Sprintf("admin/%s", authForm.Application))
if err != nil {
c.ResponseError(err.Error(), nil)
return
}
if application == nil {
c.ResponseError(fmt.Sprintf(c.T("auth:The application: %s does not exist"), authForm.Application))
return
}
verificationCodeType := object.GetVerifyType(authForm.Username)
if verificationCodeType == object.VerifyTypeEmail && !application.IsCodeSigninViaEmailEnabled() {
c.ResponseError(c.T("auth:The login method: login with email is not enabled for the application"))
return
}
if verificationCodeType == object.VerifyTypePhone && !application.IsCodeSigninViaSmsEnabled() {
c.ResponseError(c.T("auth:The login method: login with SMS is not enabled for the application"))
return
}
var checkDest string
if verificationCodeType == object.VerifyTypePhone {
authForm.CountryCode = user.GetCountryCode(authForm.CountryCode)
@ -378,7 +399,7 @@ func (c *ApiController) Login() {
c.ResponseError(fmt.Sprintf(c.T("auth:The application: %s does not exist"), authForm.Application))
return
}
if !application.EnablePassword {
if !application.IsPasswordEnabled() {
c.ResponseError(c.T("auth:The login method: login with password is not enabled for the application"))
return
}