mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-08 00:50:28 +08:00
feat: fix issue that admin cannot enable MFA for user (#2702)
This commit is contained in:
@ -110,7 +110,7 @@ func (c *ApiController) MfaSetupVerify() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
config.Secret = secret.(string)
|
config.Secret = secret.(string)
|
||||||
} else if mfaType == object.EmailType || mfaType == object.SmsType {
|
} else if mfaType == object.SmsType {
|
||||||
dest := c.GetSession(MfaDestSession)
|
dest := c.GetSession(MfaDestSession)
|
||||||
if dest == nil {
|
if dest == nil {
|
||||||
c.ResponseError("destination is missing")
|
c.ResponseError("destination is missing")
|
||||||
@ -123,6 +123,13 @@ func (c *ApiController) MfaSetupVerify() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
config.CountryCode = countryCode.(string)
|
config.CountryCode = countryCode.(string)
|
||||||
|
} else if mfaType == object.EmailType {
|
||||||
|
dest := c.GetSession(MfaDestSession)
|
||||||
|
if dest == nil {
|
||||||
|
c.ResponseError("destination is missing")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
config.Secret = dest.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
mfaUtil := object.GetMfaUtil(mfaType, config)
|
mfaUtil := object.GetMfaUtil(mfaType, config)
|
||||||
@ -175,19 +182,30 @@ func (c *ApiController) MfaSetupEnable() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
config.Secret = secret.(string)
|
config.Secret = secret.(string)
|
||||||
} else if mfaType == object.EmailType || mfaType == object.SmsType {
|
} else if mfaType == object.EmailType {
|
||||||
dest := c.GetSession(MfaDestSession)
|
if user.Email == "" {
|
||||||
if dest == nil {
|
dest := c.GetSession(MfaDestSession)
|
||||||
c.ResponseError("destination is missing")
|
if dest == nil {
|
||||||
return
|
c.ResponseError("destination is missing")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
user.Email = dest.(string)
|
||||||
}
|
}
|
||||||
config.Secret = dest.(string)
|
} else if mfaType == object.SmsType {
|
||||||
countryCode := c.GetSession(MfaCountryCodeSession)
|
if user.Phone == "" {
|
||||||
if countryCode == nil {
|
dest := c.GetSession(MfaDestSession)
|
||||||
c.ResponseError("country code is missing")
|
if dest == nil {
|
||||||
return
|
c.ResponseError("destination is missing")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
user.Phone = dest.(string)
|
||||||
|
countryCode := c.GetSession(MfaCountryCodeSession)
|
||||||
|
if countryCode == nil {
|
||||||
|
c.ResponseError("country code is missing")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
user.CountryCode = countryCode.(string)
|
||||||
}
|
}
|
||||||
config.CountryCode = countryCode.(string)
|
|
||||||
}
|
}
|
||||||
recoveryCodes := c.GetSession(MfaRecoveryCodesSession)
|
recoveryCodes := c.GetSession(MfaRecoveryCodesSession)
|
||||||
if recoveryCodes == nil {
|
if recoveryCodes == nil {
|
||||||
|
@ -52,21 +52,10 @@ func (mfa *SmsMfa) Enable(user *User) error {
|
|||||||
|
|
||||||
if mfa.MfaType == SmsType {
|
if mfa.MfaType == SmsType {
|
||||||
user.MfaPhoneEnabled = true
|
user.MfaPhoneEnabled = true
|
||||||
columns = append(columns, "mfa_phone_enabled")
|
columns = append(columns, "mfa_phone_enabled", "phone", "country_code")
|
||||||
|
|
||||||
if user.Phone == "" {
|
|
||||||
user.Phone = mfa.Secret
|
|
||||||
user.CountryCode = mfa.CountryCode
|
|
||||||
columns = append(columns, "phone", "country_code")
|
|
||||||
}
|
|
||||||
} else if mfa.MfaType == EmailType {
|
} else if mfa.MfaType == EmailType {
|
||||||
user.MfaEmailEnabled = true
|
user.MfaEmailEnabled = true
|
||||||
columns = append(columns, "mfa_email_enabled")
|
columns = append(columns, "mfa_email_enabled", "email")
|
||||||
|
|
||||||
if user.Email == "" {
|
|
||||||
user.Email = mfa.Secret
|
|
||||||
columns = append(columns, "email")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := UpdateUser(user.GetId(), user, columns, false)
|
_, err := UpdateUser(user.GetId(), user, columns, false)
|
||||||
|
Reference in New Issue
Block a user