Browse Source

#1494

update
tags/v1.22.2.2^2
Gitea 3 years ago
parent
commit
c3831a31af
4 changed files with 18 additions and 10 deletions
  1. +5
    -5
      models/wechat_bind.go
  2. +2
    -2
      modules/auth/wechat/bind.go
  3. +10
    -1
      routers/authentication/wechat.go
  4. +1
    -2
      routers/routes/routes.go

+ 5
- 5
models/wechat_bind.go View File

@@ -47,7 +47,7 @@ func BindWechatOpenId(userId int64, wechatOpenId string) error {
return sess.Commit()
}

func UnbindWechatOpenId(userId int64) error {
func UnbindWechatOpenId(userId int64, oldWechatOpenID string) error {
sess := x.NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
@@ -55,7 +55,7 @@ func UnbindWechatOpenId(userId int64) error {
}

param := &User{WechatOpenId: ""}
n, err := x.Where("ID = ?", userId).Update(param)
n, err := x.Where("ID = ? AND wechat_open_id =?", userId, oldWechatOpenID).Update(param)
if err != nil {
log.Error("update wechat_open_id failed,e=%v", err)
return err
@@ -64,10 +64,10 @@ func UnbindWechatOpenId(userId int64) error {
log.Error("update wechat_open_id failed,user not exist,userId=%d", userId)
return nil
}
//todo 是否记录原有微信openId
logParam := &WechatBindLog{
UserID: userId,
Action: int(WECHAT_UNBIND),
UserID: userId,
WechatOpenId: oldWechatOpenID,
Action: int(WECHAT_UNBIND),
}
sess.Insert(logParam)
return sess.Commit()


+ 2
- 2
modules/auth/wechat/bind.go View File

@@ -20,6 +20,6 @@ func BindWechat(userId int64, wechatOpenId string) error {
return models.BindWechatOpenId(userId, wechatOpenId)
}

func UnbindWechat(userId int64) error {
return models.UnbindWechatOpenId(userId)
func UnbindWechat(userId int64, oldWechatOpenId string) error {
return models.UnbindWechatOpenId(userId, oldWechatOpenId)
}

+ 10
- 1
routers/authentication/wechat.go View File

@@ -40,7 +40,7 @@ func GetQRCode4Bind(ctx *context.Context) {
})
}

// GetQRCode4Bind get QR code for wechat binding
// GetBindStatus
func GetBindStatus(ctx *context.Context) {
sceneStr := ctx.Query("sceneStr")
val, _ := redis_client.Get(redis_key.WechatBindingUserIdKey(sceneStr))
@@ -65,6 +65,15 @@ func GetBindStatus(ctx *context.Context) {
})
}

// UnbindWechat
func UnbindWechat(ctx *context.Context) {
wechat.UnbindWechat(ctx.User.ID, ctx.User.WechatOpenId)
ctx.JSON(200, map[string]interface{}{
"code": "00",
"msg": "success",
})
}

func createQRCode4Bind(userId int64) (*QRCodeResponse, error) {
sceneStr := gouuid.NewV4().String()
r := wechat.GetWechatQRCode4Bind(sceneStr)


+ 1
- 2
routers/routes/routes.go View File

@@ -396,8 +396,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("/authentication/wechat", func() {
m.Get("/qrCode4Bind", authentication.GetQRCode4Bind)
m.Get("/bindStatus", authentication.GetBindStatus)
// TODO manage redirection
m.Post("/authorize", bindIgnErr(auth.AuthorizationForm{}), user.AuthorizeOAuth)
m.Post("/unbind", authentication.UnbindWechat)
}, reqSignIn)

m.Group("/user/settings", func() {


Loading…
Cancel
Save