mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 21:09:11 +00:00
* feat: add new supported attestation formats to genesis * feat: refactor keyType to keytype enum * refactor: remove unused imports and code * refactor: update main.go to use src package * refactor: move web-related structs from to * refactor: move client middleware package to root * refactor: remove unused IndexedDB dependency * feat: update worker implementation to use * feat: add Caddyfile and Caddy configuration for vault service * refactor(config): move keyshare and address to Motr config * fix: validate service origin in AllocateVault * chore: remove IndexedDB configuration * feat: add support for IPNS-based vault access
52 lines
897 B
Go
52 lines
897 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/donseba/go-htmx"
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/segmentio/ksuid"
|
|
)
|
|
|
|
type Session struct {
|
|
echo.Context
|
|
htmx *htmx.HTMX
|
|
}
|
|
|
|
func (c *Session) Htmx() *htmx.HTMX {
|
|
return c.htmx
|
|
}
|
|
|
|
func (c *Session) ID() string {
|
|
return ReadCookie(c, "session")
|
|
}
|
|
|
|
func initSession(c echo.Context) *Session {
|
|
s := &Session{Context: c}
|
|
if val := ReadCookie(c, "session"); val == "" {
|
|
id := ksuid.New().String()
|
|
WriteCookie(c, "session", id)
|
|
}
|
|
return s
|
|
}
|
|
|
|
func ReadCookie(c echo.Context, key string) string {
|
|
cookie, err := c.Cookie(key)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
if cookie == nil {
|
|
return ""
|
|
}
|
|
return cookie.Value
|
|
}
|
|
|
|
func WriteCookie(c echo.Context, key string, value string) {
|
|
cookie := new(http.Cookie)
|
|
cookie.Name = key
|
|
cookie.Value = value
|
|
cookie.Expires = time.Now().Add(24 * time.Hour)
|
|
c.SetCookie(cookie)
|
|
}
|