fix: check if the token is shared before removing
This commit is contained in:
+12
-6
@@ -92,7 +92,6 @@ func TokenStoreRemoveItem(item TokenStoreItem) {
|
||||
}
|
||||
|
||||
func TokenStoreUpdateUser(cleanUser *model.User, originUser *model.User) {
|
||||
// TODO: check if this token is shared!
|
||||
if cleanUser.WeChatTestAccountId == originUser.WeChatTestAccountId {
|
||||
cleanUser.WeChatTestAccountId = ""
|
||||
}
|
||||
@@ -111,7 +110,9 @@ func TokenStoreUpdateUser(cleanUser *model.User, originUser *model.User) {
|
||||
if cleanUser.WeChatTestAccountSecret != "" {
|
||||
newWeChatTestAccountTokenStoreItem.AppSecret = cleanUser.WeChatTestAccountSecret
|
||||
}
|
||||
TokenStoreRemoveItem(&oldWeChatTestAccountTokenStoreItem)
|
||||
if !model.IsWeChatTestAccountTokenShared(&oldWeChatTestAccountTokenStoreItem) {
|
||||
TokenStoreRemoveItem(&oldWeChatTestAccountTokenStoreItem)
|
||||
}
|
||||
TokenStoreAddItem(&newWeChatTestAccountTokenStoreItem)
|
||||
}
|
||||
if cleanUser.WeChatCorpAccountId == originUser.WeChatCorpAccountId {
|
||||
@@ -139,25 +140,30 @@ func TokenStoreUpdateUser(cleanUser *model.User, originUser *model.User) {
|
||||
if cleanUser.WeChatCorpAccountAgentId != "" {
|
||||
newWeChatCorpAccountTokenStoreItem.AgentId = cleanUser.WeChatCorpAccountAgentId
|
||||
}
|
||||
TokenStoreRemoveItem(&oldWeChatCorpAccountTokenStoreItem)
|
||||
if !model.IsWeChatCorpAccountTokenShared(&oldWeChatCorpAccountTokenStoreItem) {
|
||||
TokenStoreRemoveItem(&oldWeChatCorpAccountTokenStoreItem)
|
||||
}
|
||||
TokenStoreAddItem(&newWeChatCorpAccountTokenStoreItem)
|
||||
}
|
||||
}
|
||||
|
||||
// TokenStoreRemoveUser user must be filled
|
||||
func TokenStoreRemoveUser(user *model.User) {
|
||||
// TODO: check if this token is shared!
|
||||
testAccountTokenStoreItem := WeChatTestAccountTokenStoreItem{
|
||||
AppID: user.WeChatTestAccountId,
|
||||
AppSecret: user.WeChatTestAccountSecret,
|
||||
}
|
||||
TokenStoreRemoveItem(&testAccountTokenStoreItem)
|
||||
if !model.IsWeChatTestAccountTokenShared(&testAccountTokenStoreItem) {
|
||||
TokenStoreRemoveItem(&testAccountTokenStoreItem)
|
||||
}
|
||||
corpAccountTokenStoreItem := WeChatCorpAccountTokenStoreItem{
|
||||
CorpId: user.WeChatCorpAccountId,
|
||||
CorpSecret: user.WeChatCorpAccountSecret,
|
||||
AgentId: user.WeChatCorpAccountAgentId,
|
||||
}
|
||||
TokenStoreRemoveItem(&corpAccountTokenStoreItem)
|
||||
if !model.IsWeChatCorpAccountTokenShared(&corpAccountTokenStoreItem) {
|
||||
TokenStoreRemoveItem(&corpAccountTokenStoreItem)
|
||||
}
|
||||
}
|
||||
|
||||
func TokenStoreGetToken(key string) string {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user