(c *gin.Context)
| 155 | } |
| 156 | |
| 157 | func LinuxdoOAuth(c *gin.Context) { |
| 158 | session := sessions.Default(c) |
| 159 | |
| 160 | errorCode := c.Query("error") |
| 161 | if errorCode != "" { |
| 162 | errorDescription := c.Query("error_description") |
| 163 | c.JSON(http.StatusOK, gin.H{ |
| 164 | "success": false, |
| 165 | "message": errorDescription, |
| 166 | }) |
| 167 | return |
| 168 | } |
| 169 | |
| 170 | state := c.Query("state") |
| 171 | if state == "" || session.Get("oauth_state") == nil || state != session.Get("oauth_state").(string) { |
| 172 | c.JSON(http.StatusForbidden, gin.H{ |
| 173 | "success": false, |
| 174 | "message": "state is empty or not same", |
| 175 | }) |
| 176 | return |
| 177 | } |
| 178 | |
| 179 | username := session.Get("username") |
| 180 | if username != nil { |
| 181 | LinuxDoBind(c) |
| 182 | return |
| 183 | } |
| 184 | |
| 185 | if !common.LinuxDOOAuthEnabled { |
| 186 | c.JSON(http.StatusOK, gin.H{ |
| 187 | "success": false, |
| 188 | "message": "管理员未开启通过 Linux DO 登录以及注册", |
| 189 | }) |
| 190 | return |
| 191 | } |
| 192 | |
| 193 | code := c.Query("code") |
| 194 | linuxdoUser, err := getLinuxdoUserInfoByCode(code, c) |
| 195 | if err != nil { |
| 196 | common.ApiError(c, err) |
| 197 | return |
| 198 | } |
| 199 | |
| 200 | user := model.User{ |
| 201 | LinuxDOId: strconv.Itoa(linuxdoUser.Id), |
| 202 | } |
| 203 | |
| 204 | // Check if user exists |
| 205 | if model.IsLinuxDOIdAlreadyTaken(user.LinuxDOId) { |
| 206 | err := user.FillUserByLinuxDOId() |
| 207 | if err != nil { |
| 208 | c.JSON(http.StatusOK, gin.H{ |
| 209 | "success": false, |
| 210 | "message": err.Error(), |
| 211 | }) |
| 212 | return |
| 213 | } |
| 214 | if user.Id == 0 { |
nothing calls this directly
no test coverage detected