2023-09-10 15:39:34 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"git.ekzyis.com/ekzyis/delphi.market/db"
|
2023-10-04 11:36:54 +00:00
|
|
|
"git.ekzyis.com/ekzyis/delphi.market/server/router/context"
|
2023-09-10 15:39:34 +00:00
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
2023-10-04 11:36:54 +00:00
|
|
|
func HandleCheckSession(sc context.ServerContext) echo.HandlerFunc {
|
2023-09-10 15:39:34 +00:00
|
|
|
return func(c echo.Context) error {
|
|
|
|
var (
|
|
|
|
cookie *http.Cookie
|
|
|
|
s db.Session
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if cookie, err = c.Cookie("session"); err != nil {
|
2023-11-04 13:31:48 +00:00
|
|
|
return c.JSON(http.StatusBadRequest, map[string]string{"reason": "cookie required"})
|
2023-09-10 15:39:34 +00:00
|
|
|
}
|
|
|
|
s = db.Session{SessionId: cookie.Value}
|
2023-10-04 11:36:54 +00:00
|
|
|
if err = sc.Db.FetchSession(&s); err == sql.ErrNoRows {
|
2023-11-04 13:31:48 +00:00
|
|
|
return c.JSON(http.StatusBadRequest, map[string]string{"reason": "session not found"})
|
2023-09-10 15:39:34 +00:00
|
|
|
} else if err != nil {
|
2023-11-04 13:31:48 +00:00
|
|
|
return c.JSON(http.StatusInternalServerError, nil)
|
2023-09-10 15:39:34 +00:00
|
|
|
}
|
2023-12-02 22:30:48 +00:00
|
|
|
return c.JSON(http.StatusOK, map[string]any{"pubkey": s.Pubkey, "msats": s.Msats})
|
2023-09-10 15:39:34 +00:00
|
|
|
}
|
|
|
|
}
|