feat: move user bindings to dedicated management modal

This commit is contained in:
Seefs
2026-02-23 14:51:55 +08:00
parent 016812baa6
commit 9a5f8222bd
6 changed files with 629 additions and 67 deletions

View File

@@ -536,6 +536,37 @@ func (user *User) Edit(updatePassword bool) error {
return updateUserCache(*user)
}
func (user *User) ClearBinding(bindingType string) error {
if user.Id == 0 {
return errors.New("user id is empty")
}
bindingColumnMap := map[string]string{
"email": "email",
"github": "github_id",
"discord": "discord_id",
"oidc": "oidc_id",
"wechat": "wechat_id",
"telegram": "telegram_id",
"linuxdo": "linux_do_id",
}
column, ok := bindingColumnMap[bindingType]
if !ok {
return errors.New("invalid binding type")
}
if err := DB.Model(&User{}).Where("id = ?", user.Id).Update(column, "").Error; err != nil {
return err
}
if err := DB.Where("id = ?", user.Id).First(user).Error; err != nil {
return err
}
return updateUserCache(*user)
}
func (user *User) Delete() error {
if user.Id == 0 {
return errors.New("id 为空!")