Files
new-api-custom/service/account_security.go
T
cneicy ceddfd3d6b feat: sync deployed v1.0.0-rc.38-custom.42
Sync production source including routing, billing, Astra detection and public uptime. Update custom build instructions and license packaging.
2026-09-26 04:49:11 +08:00

42 lines
1.5 KiB
Go

package service
import (
"fmt"
"html"
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/model"
"github.com/QuantumNous/new-api/oauth"
"github.com/QuantumNous/new-api/setting/system_setting"
)
func UnbindAccountOAuth(identity AuthIdentity, providerID int) error {
enabled := model.AccountLoginMethods{
Password: common.PasswordLoginEnabled,
Passkey: system_setting.PasskeySettingsSnapshot().Enabled,
WeChat: common.WeChatAuthEnabled,
}
for _, provider := range oauth.GetAllProviders() {
if !provider.IsEnabled() {
continue
}
if custom, ok := provider.(*oauth.GenericOAuthProvider); ok {
enabled.CustomProviderIDs = append(enabled.CustomProviderIDs, custom.GetProviderId())
} else {
enabled.OAuthColumns = append(enabled.OAuthColumns, provider.ProviderUserIDColumn())
}
}
return model.UnbindUserOAuthForSession(identity, providerID, enabled)
}
// NotifyAccountSecurityChange never includes credentials or tokens. The caller
// records delivery failure independently from the already-committed change.
func NotifyAccountSecurityChange(email, event string) error {
if email == "" {
return nil
}
subject := common.SystemName + " — Account security notification"
content := fmt.Sprintf("<p>Your account security settings have changed: %s.</p><p>If you did not make this change, open your account security settings, revoke other login sessions, and contact your administrator.</p>", html.EscapeString(event))
return common.SendEmail(subject, email, content)
}