mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 18:01:39 +00:00
feature/1107 integrate dexie db (#1128)
- **feat: remove grant page** - **refactor: remove alert, input, radios, tabs, and video blocks** - **feat: add JSON serialization to DWN config** - **feat: add new Highway gateway component** - **refactor: remove unused chains.yaml and devbox.json** - **refactor: Separate request and response headers into protected and non-protected structs** - **feat: Update the UseSession echo middleware to bind the correct headers and provide methods for updating HTMX context from Go** - **refactor: remove unused headers from session** - **feat: add authorize endpoint** - **feat: create marketing pages**
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/labstack/echo/v4"
|
||||
|
||||
"github.com/onsonr/sonr/pkg/nebula/components/grant"
|
||||
"github.com/onsonr/sonr/pkg/nebula/components/home"
|
||||
"github.com/onsonr/sonr/pkg/nebula/components/login"
|
||||
"github.com/onsonr/sonr/pkg/nebula/components/profile"
|
||||
"github.com/onsonr/sonr/pkg/nebula/components/register"
|
||||
"github.com/onsonr/sonr/pkg/nebula/models"
|
||||
)
|
||||
|
||||
// ╭───────────────────────────────────────────────────────────╮
|
||||
// │ Marketing Pages │
|
||||
// ╰───────────────────────────────────────────────────────────╯
|
||||
|
||||
func Home(c echo.Context) error {
|
||||
mdls, err := models.GetModels()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return render(c, home.View(mdls.Home))
|
||||
}
|
||||
|
||||
func Profile(c echo.Context) error {
|
||||
return render(c, profile.View(c))
|
||||
}
|
||||
|
||||
// ╭───────────────────────────────────────────────────────────╮
|
||||
// │ Authentication Views │
|
||||
// ╰───────────────────────────────────────────────────────────╯
|
||||
func Authorize(c echo.Context) error {
|
||||
return render(c, grant.View(c))
|
||||
}
|
||||
|
||||
func Login(c echo.Context) error {
|
||||
return render(c, login.Modal(c))
|
||||
}
|
||||
|
||||
func Register(c echo.Context) error {
|
||||
return render(c, register.Modal(c))
|
||||
}
|
||||
|
||||
// ╭───────────────────────────────────────────────────────────╮
|
||||
// │ Helper Methods │
|
||||
// ╰───────────────────────────────────────────────────────────╯
|
||||
|
||||
func render(c echo.Context, cmp templ.Component) error {
|
||||
// Create a buffer to store the rendered HTML
|
||||
buf := &bytes.Buffer{}
|
||||
// Render the component to the buffer
|
||||
err := cmp.Render(c.Request().Context(), buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set the content type
|
||||
c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
|
||||
|
||||
// Write the buffered content to the response
|
||||
_, err = c.Response().Write(buf.Bytes())
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package router
|
||||
|
||||
type Status string
|
||||
|
||||
const (
|
||||
StatusOK Status = "ok"
|
||||
StatusError Status = "error"
|
||||
StatusNotFound Status = "not-found"
|
||||
StatusUnauthorized Status = "unauthorized"
|
||||
StatusForbidden Status = "forbidden"
|
||||
StatusInternalServerError Status = "internal-server-error"
|
||||
StatusBadRequest Status = "bad-request"
|
||||
)
|
||||
Reference in New Issue
Block a user