Skip to content

Commit 20797f2

Browse files
kasbahAbdulrhmnGhanem
authored andcommitted
Add a kitspace session endpoint
1 parent 096794c commit 20797f2

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

routers/web/auth/kitspace_auth.go

Lines changed: 25 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,27 @@ func KitspaceSignIn(ctx *context.Context) {
187188

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

routers/web/web.go

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

297297
// ***** START: User *****
298+
m.Get("/user/kitspace/session", auth.GetKitspaceSession)
298299
m.Group("/user", func() {
299300
m.Group("/kitspace", func() {
300301
m.Post("/sign_up", bindIgnErr(forms.RegisterForm{}), auth.KitspaceSignUp)

0 commit comments

Comments
 (0)