MCPcopy Index your code
hub / github.com/aiprodcoder/MIXAPI / GitHubBind

Function GitHubBind

controller/github.go:175–219  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

173}
174
175func GitHubBind(c *gin.Context) {
176 if !common.GitHubOAuthEnabled {
177 c.JSON(http.StatusOK, gin.H{
178 "success": false,
179 "message": "管理员未开启通过 GitHub 登录以及注册",
180 })
181 return
182 }
183 code := c.Query("code")
184 githubUser, err := getGitHubUserInfoByCode(code)
185 if err != nil {
186 common.ApiError(c, err)
187 return
188 }
189 user := model.User{
190 GitHubId: githubUser.Login,
191 }
192 if model.IsGitHubIdAlreadyTaken(user.GitHubId) {
193 c.JSON(http.StatusOK, gin.H{
194 "success": false,
195 "message": "该 GitHub 账户已被绑定",
196 })
197 return
198 }
199 session := sessions.Default(c)
200 id := session.Get("id")
201 // id := c.GetInt("id") // critical bug!
202 user.Id = id.(int)
203 err = user.FillUserById()
204 if err != nil {
205 common.ApiError(c, err)
206 return
207 }
208 user.GitHubId = githubUser.Login
209 err = user.Update(false)
210 if err != nil {
211 common.ApiError(c, err)
212 return
213 }
214 c.JSON(http.StatusOK, gin.H{
215 "success": true,
216 "message": "bind",
217 })
218 return
219}
220
221func GenerateOAuthCode(c *gin.Context) {
222 session := sessions.Default(c)

Callers 1

GitHubOAuthFunction · 0.85

Calls 6

FillUserByIdMethod · 0.95
UpdateMethod · 0.95
ApiErrorFunction · 0.92
IsGitHubIdAlreadyTakenFunction · 0.92
getGitHubUserInfoByCodeFunction · 0.85
GetMethod · 0.80

Tested by

no test coverage detected