(c *gin.Context)
| 121 | } |
| 122 | |
| 123 | func WeChatBind(c *gin.Context) { |
| 124 | if !common.WeChatAuthEnabled { |
| 125 | c.JSON(http.StatusOK, gin.H{ |
| 126 | "message": "管理员未开启通过微信登录以及注册", |
| 127 | "success": false, |
| 128 | }) |
| 129 | return |
| 130 | } |
| 131 | code := c.Query("code") |
| 132 | wechatId, err := getWeChatIdByCode(code) |
| 133 | if err != nil { |
| 134 | c.JSON(http.StatusOK, gin.H{ |
| 135 | "message": err.Error(), |
| 136 | "success": false, |
| 137 | }) |
| 138 | return |
| 139 | } |
| 140 | if model.IsWeChatIdAlreadyTaken(wechatId) { |
| 141 | c.JSON(http.StatusOK, gin.H{ |
| 142 | "success": false, |
| 143 | "message": "该微信账号已被绑定", |
| 144 | }) |
| 145 | return |
| 146 | } |
| 147 | session := sessions.Default(c) |
| 148 | id := session.Get("id") |
| 149 | user := model.User{ |
| 150 | Id: id.(int), |
| 151 | } |
| 152 | err = user.FillUserById() |
| 153 | if err != nil { |
| 154 | common.ApiError(c, err) |
| 155 | return |
| 156 | } |
| 157 | user.WeChatId = wechatId |
| 158 | err = user.Update(false) |
| 159 | if err != nil { |
| 160 | common.ApiError(c, err) |
| 161 | return |
| 162 | } |
| 163 | c.JSON(http.StatusOK, gin.H{ |
| 164 | "success": true, |
| 165 | "message": "", |
| 166 | }) |
| 167 | return |
| 168 | } |
nothing calls this directly
no test coverage detected