(c *gin.Context)
| 50 | } |
| 51 | |
| 52 | func adminOAuthCallback(c *gin.Context) { |
| 53 | r := struct { |
| 54 | State string `json:"state" form:"state" binding:"required"` |
| 55 | Code string `json:"code" form:"code" binding:"required"` |
| 56 | }{} |
| 57 | |
| 58 | if err := c.ShouldBind(&r); err != nil { |
| 59 | abortWithError(c, http.StatusBadRequest, err) |
| 60 | return |
| 61 | } |
| 62 | |
| 63 | authz := getAdminAuth(c) |
| 64 | userInfo, err := authz.HandleLogin(c, r.State, r.Code) |
| 65 | if err != nil { |
| 66 | abortWithError(c, http.StatusForbidden, err) |
| 67 | return |
| 68 | } |
| 69 | |
| 70 | d, err := model.EnsureDeveloper(model.GetDB(c), userInfo.ID, userInfo.Name, userInfo.Email, userInfo.Extra) |
| 71 | if err != nil { |
| 72 | _ = c.Error(err) |
| 73 | abortWithError(c, http.StatusInternalServerError, ErrUpdateDeveloperAccount) |
| 74 | return |
| 75 | } |
| 76 | |
| 77 | // save session |
| 78 | sessionExpireSeconds := int64(getConfig(c).AdminAuth.OAuthExpires.Seconds()) |
| 79 | s, err := model.NewSession(model.GetDB(c), sessionExpireSeconds) |
| 80 | if err != nil { |
| 81 | _ = c.Error(err) |
| 82 | abortWithError(c, http.StatusInternalServerError, ErrCreateSessionFailed) |
| 83 | return |
| 84 | } |
| 85 | |
| 86 | c.Set("session", s) |
| 87 | |
| 88 | s.Set("admin", true) |
| 89 | s.Set("developer_id", d.ID) |
| 90 | s.Set("github_id", userInfo.ID) |
| 91 | s.Set("name", userInfo.Name) |
| 92 | s.Set("email", userInfo.Email) |
| 93 | |
| 94 | responseWithData(c, http.StatusOK, gin.H{ |
| 95 | "token": s.ID, |
| 96 | "name": d.Name, |
| 97 | "email": d.Email, |
| 98 | "extra": d.Extra, |
| 99 | }) |
| 100 | } |
| 101 | |
| 102 | func adminOAuthLogout(c *gin.Context) { |
| 103 | err := model.DeleteSession(model.GetDB(c), getSession(c)) |
nothing calls this directly
no test coverage detected