MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / userSessionInject

Function userSessionInject

cmd/cql-proxy/api/user_oauth.go:402–482  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

400}
401
402func userSessionInject(c *gin.Context) {
403 projectDB, err := getCurrentProjectDB(c)
404
405 if err != nil {
406 _ = c.Error(err)
407 abortWithError(c, http.StatusInternalServerError, ErrLoadProjectDatabaseFailed)
408 return
409 }
410
411 _, miscConfig, err := model.GetProjectMiscConfig(projectDB)
412 if err != nil || !miscConfig.IsEnabled() {
413 _ = c.Error(err)
414 abortWithError(c, http.StatusInternalServerError, ErrProjectIsDisabled)
415 return
416 }
417
418 // load session
419 var token string
420
421 for i := 0; i != 4; i++ {
422 switch i {
423 case 0:
424 // header
425 token = c.GetHeader("X-CQL-Token")
426 case 1:
427 // cookie
428 token, _ = c.Cookie("token")
429 case 2:
430 // get query
431 token = c.Query("token")
432 case 3:
433 // embed in form
434 r := struct {
435 Token string `json:"token" form:"token"`
436 }{}
437 _ = c.ShouldBindQuery(&r)
438 token = r.Token
439 }
440
441 if token != "" {
442 if s, err := model.GetSession(projectDB, token); err == nil {
443 c.Set("session", s)
444 break
445 } else {
446 token = ""
447 }
448 }
449 }
450
451 if token == "" {
452 _ = model.NewEmptySession(c)
453 }
454
455 c.Next()
456
457 if !c.IsAborted() {
458 cfg := getConfig(c)
459

Callers

nothing calls this directly

Calls 15

GetProjectMiscConfigFunction · 0.92
GetSessionFunction · 0.92
NewEmptySessionFunction · 0.92
SaveSessionFunction · 0.92
ExpireSessionsFunction · 0.92
WithFieldsFunction · 0.92
getCurrentProjectDBFunction · 0.85
abortWithErrorFunction · 0.85
getConfigFunction · 0.85
ErrorMethod · 0.80
MustGetMethod · 0.80
InfoMethod · 0.80

Tested by

no test coverage detected