mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
- **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**
68 lines
2.6 KiB
Go
68 lines
2.6 KiB
Go
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
|
|
}
|