From 4db4e2c122161655d7085379a5629f84d8606126 Mon Sep 17 00:00:00 2001 From: Yader Velasquez Date: Thu, 15 Feb 2024 11:33:44 -0600 Subject: [PATCH] Add inactive domain handler References: https://todo.code.netlandish.com/~netlandish/links/48 --- core/routes.go | 12 ++++++++++++ domain/middleware.go | 7 +------ templates/inactive_domain.html | 9 +++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 templates/inactive_domain.html diff --git a/core/routes.go b/core/routes.go index cd9bbe4..c9fef38 100644 --- a/core/routes.go +++ b/core/routes.go @@ -37,6 +37,7 @@ type Service struct { // RegisterRoutes ... func (s *Service) RegisterRoutes() { s.eg.GET("/", s.Homepage).Name = "index" + s.eg.GET("/inactive", s.InactiveDomain).Name = s.RouteName("inactive_domain") s.eg.GET("/:slug", s.OrgLinksList).Name = s.RouteName("org_link_list") s.eg.GET("/recent", s.OrgLinksList).Name = s.RouteName("recent_link_list") s.eg.GET("/popular", s.PopularLinkList).Name = s.RouteName("popular_link_list") @@ -90,6 +91,17 @@ func (s *Service) RegisterRoutes() { s.eg.GET("/tag-autocomplete", s.TagAutocomplete).Name = s.RouteName("tag_autocomplete") } +func (s *Service) InactiveDomain(c echo.Context) error { + gctx := c.(*server.Context) + lt := localizer.GetSessionLocalizer(c) + pd := localizer.NewPageData(lt.Translate("Inactive Domain")) + pd.Data["msg"] = lt.Translate("The domain is inactive") + pd.Data["please_upgrade"] = lt.Translate("Please upgrade your account to reactivate it") + slug := links.PullOrgSlug(c) + gMap := gobwebs.Map{"pd": pd, "slug": slug} + return gctx.Render(http.StatusOK, "inactive_domain.html", gMap) +} + func (s *Service) Homepage(c echo.Context) error { // If user custom domain, don't parse homepage. Just show the assigned // org public list diff --git a/domain/middleware.go b/domain/middleware.go index 0d26028..af9986b 100644 --- a/domain/middleware.go +++ b/domain/middleware.go @@ -4,14 +4,12 @@ import ( "context" "errors" "fmt" - "links/internal/localizer" "links/models" "net/http" "net/url" "strings" "github.com/labstack/echo/v4" - "netlandish.com/x/gobwebs/messages" "netlandish.com/x/gobwebs/server" ) @@ -44,11 +42,8 @@ func badDomainRedirect(c echo.Context) error { nextURL := &url.URL{ Scheme: gctx.Server.Config.Scheme, Host: mainDomain, + Path: c.Echo().Reverse("core:inactive_domain"), } - lt := localizer.GetSessionLocalizer(c) - // XXX This needs to change. See: https://todo.code.netlandish.com/~netlandish/links/48 - messages.Error( - c, lt.Translate("The domain is currently inactive. Please subscribe to activate this domain")) return c.Redirect(http.StatusMovedPermanently, nextURL.String()) } diff --git a/templates/inactive_domain.html b/templates/inactive_domain.html new file mode 100644 index 0000000..c24f29b --- /dev/null +++ b/templates/inactive_domain.html @@ -0,0 +1,9 @@ +{{template "base" .}} +
+

{{.pd.Title}}

+
+
+

{{.pd.Data.msg}}

+

{{.pd.Data.please_upgrade}}

+
+{{template "base_footer" .}} -- 2.45.2