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

Function GitHubOAuth

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

Source from the content-addressed store, hash-verified

79}
80
81func GitHubOAuth(c *gin.Context) {
82 session := sessions.Default(c)
83 state := c.Query("state")
84 if state == "" || session.Get("oauth_state") == nil || state != session.Get("oauth_state").(string) {
85 c.JSON(http.StatusForbidden, gin.H{
86 "success": false,
87 "message": "state is empty or not same",
88 })
89 return
90 }
91 username := session.Get("username")
92 if username != nil {
93 GitHubBind(c)
94 return
95 }
96
97 if !common.GitHubOAuthEnabled {
98 c.JSON(http.StatusOK, gin.H{
99 "success": false,
100 "message": "管理员未开启通过 GitHub 登录以及注册",
101 })
102 return
103 }
104 code := c.Query("code")
105 githubUser, err := getGitHubUserInfoByCode(code)
106 if err != nil {
107 common.ApiError(c, err)
108 return
109 }
110 user := model.User{
111 GitHubId: githubUser.Login,
112 }
113 // IsGitHubIdAlreadyTaken is unscoped
114 if model.IsGitHubIdAlreadyTaken(user.GitHubId) {
115 // FillUserByGitHubId is scoped
116 err := user.FillUserByGitHubId()
117 if err != nil {
118 c.JSON(http.StatusOK, gin.H{
119 "success": false,
120 "message": err.Error(),
121 })
122 return
123 }
124 // if user.Id == 0 , user has been deleted
125 if user.Id == 0 {
126 c.JSON(http.StatusOK, gin.H{
127 "success": false,
128 "message": "用户已注销",
129 })
130 return
131 }
132 } else {
133 if common.RegisterEnabled {
134 user.Username = "github_" + strconv.Itoa(model.GetMaxUserId()+1)
135 if githubUser.Name != "" {
136 user.DisplayName = githubUser.Name
137 } else {
138 user.DisplayName = "GitHub User"

Callers

nothing calls this directly

Calls 11

FillUserByGitHubIdMethod · 0.95
InsertMethod · 0.95
ApiErrorFunction · 0.92
IsGitHubIdAlreadyTakenFunction · 0.92
GetMaxUserIdFunction · 0.92
GetUserIdByAffCodeFunction · 0.92
GitHubBindFunction · 0.85
getGitHubUserInfoByCodeFunction · 0.85
setupLoginFunction · 0.85
GetMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected