2024-12-05 20:36:58 -05:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
2024-12-10 13:47:07 -05:00
|
|
|
"github.com/onsonr/sonr/internal/vault/context"
|
2024-12-05 20:36:58 -05:00
|
|
|
)
|
|
|
|
|
|
2024-12-13 15:10:27 -05:00
|
|
|
func RenderIndex(c echo.Context) error {
|
2024-12-10 13:40:41 -05:00
|
|
|
// TODO: Create views
|
2024-12-13 15:10:27 -05:00
|
|
|
if isReturning(c) {
|
2024-12-10 13:33:01 -05:00
|
|
|
// return response.TemplEcho(c, index.InitialView())
|
2024-12-05 20:36:58 -05:00
|
|
|
}
|
2024-12-10 13:40:41 -05:00
|
|
|
// TODO: Add authorization check
|
2024-12-05 20:36:58 -05:00
|
|
|
if isExpired(c) {
|
2024-12-10 13:33:01 -05:00
|
|
|
// return response.TemplEcho(c, index.ReturningView())
|
2024-12-05 20:36:58 -05:00
|
|
|
}
|
|
|
|
|
return c.Render(http.StatusOK, "index.templ", nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ╭─────────────────────────────────────────────────────────╮
|
|
|
|
|
// │ Utility Functions │
|
|
|
|
|
// ╰─────────────────────────────────────────────────────────╯
|
|
|
|
|
|
|
|
|
|
// Expired users have either a user handle or vault address
|
|
|
|
|
func isExpired(c echo.Context) bool {
|
2024-12-10 13:47:07 -05:00
|
|
|
noAuth := !context.HasAuthorization(c)
|
|
|
|
|
hasUserHandle := context.HasUserHandle(c)
|
|
|
|
|
hasVaultAddress := context.HasVaultAddress(c)
|
2024-12-05 20:36:58 -05:00
|
|
|
return noAuth && hasUserHandle || noAuth && hasVaultAddress
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returning users have a valid authorization, and either a user handle or vault address
|
|
|
|
|
func isReturning(c echo.Context) bool {
|
2024-12-10 13:47:07 -05:00
|
|
|
hasAuth := context.HasAuthorization(c)
|
|
|
|
|
hasUserHandle := context.HasUserHandle(c)
|
|
|
|
|
hasVaultAddress := context.HasVaultAddress(c)
|
2024-12-05 20:36:58 -05:00
|
|
|
return hasAuth && (hasUserHandle || hasVaultAddress)
|
|
|
|
|
}
|