|
|
@@ -38,7 +38,7 @@ func (err WechatBindError) Error() string { |
|
|
|
} |
|
|
|
|
|
|
|
func BindWechat(userId int64, wechatOpenId string) error { |
|
|
|
if !IsWechatAccountAvailable(userId, wechatOpenId) { |
|
|
|
if !IsWechatAccountUsed(userId, wechatOpenId) { |
|
|
|
log.Error("bind wechat failed, because user use wrong wechat account to bind,userId=%d wechatOpenId=%s", userId, wechatOpenId) |
|
|
|
return NewWechatBindError(BIND_REPLY_WECHAT_ACCOUNT_USED) |
|
|
|
} |
|
|
@@ -60,9 +60,9 @@ func IsUserAvailableForWechatBind(userId int64, wechatOpenId string) bool { |
|
|
|
return currentOpenId == "" || currentOpenId == wechatOpenId |
|
|
|
} |
|
|
|
|
|
|
|
//IsWechatAccountAvailable if wechat account used by another account,return false |
|
|
|
//IsWechatAccountUsed if wechat account used by another account,return false |
|
|
|
//if wechat account not used or used by the given user,return true |
|
|
|
func IsWechatAccountAvailable(userId int64, wechatOpenId string) bool { |
|
|
|
func IsWechatAccountUsed(userId int64, wechatOpenId string) bool { |
|
|
|
user := models.GetUserByWechatOpenId(wechatOpenId) |
|
|
|
if user != nil && user.WechatOpenId != "" && user.ID != userId { |
|
|
|
return false |
|
|
|