mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-30 00:46:42 +00:00
feat: move user bindings to dedicated management modal
This commit is contained in:
@@ -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 为空!")
|
||||
|
||||
Reference in New Issue
Block a user