Skip to content

Commit 651c0f4

Browse files
committed
Add a kitspace session endpoint
1 parent 862e827 commit 651c0f4

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

routers/web/auth/kitspace_auth.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"code.gitea.io/gitea/modules/log"
1111
"code.gitea.io/gitea/modules/password"
1212
"code.gitea.io/gitea/modules/setting"
13+
"code.gitea.io/gitea/modules/structs"
1314
"code.gitea.io/gitea/modules/web"
1415
"code.gitea.io/gitea/services/auth"
1516
"code.gitea.io/gitea/services/forms"
@@ -187,3 +188,28 @@ func KitspaceSignIn(ctx *context.Context) {
187188

188189
ctx.JSON(http.StatusOK, response)
189190
}
191+
192+
193+
func GetKitspaceSession(ctx *context.Context) {
194+
// swagger:operation GET /user/kitspace/session
195+
// ---
196+
// summary: get currently signed in user (if any) and csrf token
197+
// consumes:
198+
// - application/json
199+
// produces:
200+
// - application/json
201+
// responses:
202+
// "200":
203+
// "$ref": "success"
204+
205+
var user *structs.User
206+
if ctx.User != nil && ctx.IsSigned {
207+
user = convert.ToUser(ctx.User, ctx.User)
208+
}
209+
210+
response := make(map[string]interface{})
211+
response["user"] = user
212+
response["csrf"] = ctx.Data["CsrfToken"]
213+
214+
ctx.JSON(http.StatusOK, response)
215+
}

routers/web/web.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ func RegisterRoutes(m *web.Route) {
262262
m.Get("/milestones", reqSignIn, reqMilestonesDashboardPageEnabled, user.Milestones)
263263

264264
// ***** START: User *****
265+
m.Get("/user/kitspace/session", auth.GetKitspaceSession)
265266
m.Group("/user", func() {
266267
m.Group("/kitspace", func() {
267268
m.Post("/sign_up", bindIgnErr(forms.RegisterForm{}), auth.KitspaceSignUp)

0 commit comments

Comments
 (0)