Browse Source

#1494

update
tags/v1.22.2.2^2
Gitea 4 years ago
parent
commit
433673ef5a
2 changed files with 17 additions and 20 deletions
  1. +14
    -9
      modules/auth/wechat/bind.go
  2. +3
    -11
      modules/auth/wechat/event_handle.go

+ 14
- 9
modules/auth/wechat/bind.go View File

@@ -18,28 +18,33 @@ const (
BIND_STATUS_EXPIRED = 9
)

type WechatAccountUsedError struct {
}
const (
BIND_REPLY_SUCCESS = "启智账号认证微信成功"
BIND_REPLY_WECHAT_ACCOUNT_USED = "认证失败,您的微信号已绑定其他启智账号"
BIND_REPLY_OPENI_ACCOUNT_USED = "认证失败,您待认证的启智账号已绑定其他微信号"
BIND_REPLY_FAILED_DEFAULT = "微信认证失败"
)

func (err WechatAccountUsedError) Error() string {
return fmt.Sprint("wechat account has been used")
type WechatBindError struct {
Reply string
}

type OpenIAccountUsedError struct {
func NewWechatBindError(reply string) WechatBindError {
return WechatBindError{Reply: reply}
}

func (err OpenIAccountUsedError) Error() string {
return fmt.Sprint("openI account has been used")
func (err WechatBindError) Error() string {
return fmt.Sprint("wechat bind error,reply=%s", err.Reply)
}

func BindWechat(userId int64, wechatOpenId string) error {
if !IsWechatAccountAvailable(userId, wechatOpenId) {
log.Error("bind wechat failed, because user use wrong wechat account to bind,userId=%d wechatOpenId=%s", userId, wechatOpenId)
return WechatAccountUsedError{}
return NewWechatBindError(BIND_REPLY_WECHAT_ACCOUNT_USED)
}
if !IsUserAvailableForWechatBind(userId, wechatOpenId) {
log.Error("openI account has been used,userId=%d wechatOpenId=%s", userId, wechatOpenId)
return OpenIAccountUsedError{}
return NewWechatBindError(BIND_REPLY_OPENI_ACCOUNT_USED)
}
return models.BindWechatOpenId(userId, wechatOpenId)
}


+ 3
- 11
modules/auth/wechat/event_handle.go View File

@@ -9,12 +9,6 @@ import (
"time"
)

const (
BIND_REPLY_SUCCESS = "启智账号认证微信成功"
BIND_REPLY_WECHAT_ACCOUNT_USED = "认证失败,您的微信号已绑定其他启智账号"
BIND_REPLY_OPENI_ACCOUNT_USED = "认证失败,您待认证的启智账号已绑定其他微信号"
)

//<xml>
// <ToUserName><![CDATA[toUser]]></ToUserName>
// <FromUserName><![CDATA[FromUser]]></FromUserName>
@@ -59,12 +53,10 @@ func HandleSubscribeEvent(we WechatEvent) string {
if qrCache.Status == BIND_STATUS_UNBIND {
err := BindWechat(qrCache.UserId, we.FromUserName)
if err != nil {
if _, ok := err.(WechatAccountUsedError); ok {
return BIND_REPLY_WECHAT_ACCOUNT_USED
}
if _, ok := err.(OpenIAccountUsedError); ok {
return BIND_REPLY_OPENI_ACCOUNT_USED
if err, ok := err.(WechatBindError); ok {
return err.Reply
}
return BIND_REPLY_FAILED_DEFAULT
}
qrCache.Status = BIND_STATUS_BOUND
jsonStr, _ := json.Marshal(qrCache)


Loading…
Cancel
Save