mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
* feat(did): remove account types * feat: Refactor Property to Proof in zkprop.go * feat: add ZKP proof mechanism for verifications * fix: return bool and error from pinInitialVault * feat: implement KeyshareSet for managing user and validator keyshares * feat: Update Credential type in protobuf * feat: update credential schema with sign count * feat: migrate and modules to middleware * refactor: rename vault module to ORM * chore(dwn): add service worker registration to index template * feat: integrate service worker for offline functionality * refactor(did): use DIDNamespace enum for verification method in proto reflection * refactor: update protobuf definitions to support Keyshare * feat: expose did keeper in app keepers * Add Motr Web App * refactor: rename motr/handlers/discovery.go to motr/handlers/openid.go * refactor: move session related code to middleware * feat: add database operations for managing assets, chains, and credentials * feat: add htmx support for UI updates * refactor: extract common helper scripts * chore: remove unused storage GUI components * refactor: Move frontend rendering to dedicated handlers * refactor: rename to * refactor: move alert implementation to templ * feat: add alert component with icon, title, and message * feat: add new RequestHeaders struct to store request headers * Feature/create home view (#9) * refactor: move view logic to new htmx handler * refactor: remove unnecessary dependencies * refactor: remove unused dependencies * feat(devbox): integrate air for local development * feat: implement openid connect discovery document * refactor: rename to * refactor(did): update service handling to support DNS discovery * feat: add support for user and validator keyshares * refactor: move keyshare signing logic to signer
72 lines
1.3 KiB
Go
72 lines
1.3 KiB
Go
package mdw
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/donseba/go-htmx"
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/onsonr/sonr/internal/db"
|
|
"github.com/segmentio/ksuid"
|
|
)
|
|
|
|
// UseSession establishes a Session Cookie.
|
|
func UseSession(next echo.HandlerFunc) echo.HandlerFunc {
|
|
return func(c echo.Context) error {
|
|
sc := newSession(c)
|
|
bindRequestHeaders(sc)
|
|
return next(sc)
|
|
}
|
|
}
|
|
|
|
// GetSession returns the current Session
|
|
func GetSession(c echo.Context) *Session {
|
|
return c.(*Session)
|
|
}
|
|
|
|
type Session struct {
|
|
echo.Context
|
|
htmx *htmx.HTMX
|
|
dB *db.DB
|
|
}
|
|
|
|
func (c *Session) ID() string {
|
|
return readCookie(c, "session")
|
|
}
|
|
|
|
func (c *Session) Htmx() *htmx.HTMX {
|
|
return c.htmx
|
|
}
|
|
|
|
func (c *Session) DB() *db.DB {
|
|
return c.dB
|
|
}
|
|
|
|
func newSession(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)
|
|
}
|