GET /api/session
(w http.ResponseWriter, r *http.Request)
| 26 | |
| 27 | // GET /api/session |
| 28 | func (api *API) GetSession(w http.ResponseWriter, r *http.Request) error { |
| 29 | userCount, err := api.database.CountUsers() |
| 30 | if err != nil { |
| 31 | return err |
| 32 | } |
| 33 | |
| 34 | // if 0 users in database, dashboard is public |
| 35 | if userCount == 0 { |
| 36 | return respond(w, http.StatusOK, envelope{Data: true}) |
| 37 | } |
| 38 | |
| 39 | // if existing session, assume logged-in |
| 40 | session, _ := api.sessions.Get(r, "auth") |
| 41 | if !session.IsNew { |
| 42 | return respond(w, http.StatusOK, envelope{Data: true}) |
| 43 | } |
| 44 | |
| 45 | // otherwise: not logged-in yet |
| 46 | return respond(w, http.StatusOK, envelope{Data: false}) |
| 47 | } |
| 48 | |
| 49 | // URL: POST /api/session |
| 50 | func (api *API) CreateSession(w http.ResponseWriter, r *http.Request) error { |
nothing calls this directly
no test coverage detected