fix: check if the token is shared before removing

This commit is contained in:
JustSong
2022-11-22 15:11:02 +08:00
parent b616fc8d84
commit d0c2c27071
2 changed files with 23 additions and 6 deletions
+11
View File
@@ -2,6 +2,7 @@ package model
import (
"errors"
"message-pusher/channel"
"message-pusher/common"
"strings"
)
@@ -168,6 +169,16 @@ func IsUsernameAlreadyTaken(username string) bool {
return DB.Where("username = ?", username).Find(&User{}).RowsAffected == 1
}
func IsWeChatTestAccountTokenShared(item *channel.WeChatTestAccountTokenStoreItem) bool {
return DB.Where("wechat_test_account_id = ? and wechat_test_account_secret = ?",
item.AppID, item.AppSecret).Find(&User{}).RowsAffected != 1
}
func IsWeChatCorpAccountTokenShared(item *channel.WeChatCorpAccountTokenStoreItem) bool {
return DB.Where("wechat_corp_account_id = ? and wechat_corp_account_secret = ? and wechat_corp_account_agent_id = ?",
item.CorpId, item.CorpSecret, item.AgentId).Find(&User{}).RowsAffected != 1
}
func ResetUserPasswordByEmail(email string, password string) error {
hashedPassword, err := common.Password2Hash(password)
if err != nil {