diff --git a/cmd/server/assets/codes/issue.html b/cmd/server/assets/codes/issue.html
index ca3ffb2cd..29e36a000 100644
--- a/cmd/server/assets/codes/issue.html
+++ b/cmd/server/assets/codes/issue.html
@@ -23,7 +23,7 @@
-
+
{{template "navbar" .}}
diff --git a/internal/routes/server.go b/internal/routes/server.go
index 854c31e03..16aaa77e6 100644
--- a/internal/routes/server.go
+++ b/internal/routes/server.go
@@ -27,7 +27,6 @@ import (
"github.com/google/exposure-notifications-verification-server/pkg/controller/admin"
"github.com/google/exposure-notifications-verification-server/pkg/controller/apikey"
"github.com/google/exposure-notifications-verification-server/pkg/controller/codes"
- "github.com/google/exposure-notifications-verification-server/pkg/controller/home"
"github.com/google/exposure-notifications-verification-server/pkg/controller/issueapi"
"github.com/google/exposure-notifications-verification-server/pkg/controller/jwks"
"github.com/google/exposure-notifications-verification-server/pkg/controller/login"
@@ -188,24 +187,17 @@ func Server(
}
}
- // TODO: this is a legacy path which is now duplicated on /codes
- // This will be removed in a future release.
+ // Redirect old /home path to /codes/issue. This route is no longer in use,
+ // but the redirect is preserved in case people have their browser open to the
+ // old page.
+ //
+ // TODO: remove in 0.18+.
{
sub := r.PathPrefix("/home").Subrouter()
- sub.Use(requireAuth)
- sub.Use(loadCurrentRealm)
- sub.Use(requireRealm)
- sub.Use(processFirewall)
- sub.Use(requireVerified)
- sub.Use(requireMFA)
- sub.Use(rateLimit)
-
- homeController := home.New(ctx, cfg, db, h)
- sub.Handle("", homeController.HandleHome()).Methods("GET")
- // API for creating new verification codes. Called via AJAX.
- issueapiController := issueapi.New(ctx, cfg, db, limiterStore, h)
- sub.Handle("/issue", issueapiController.HandleIssue()).Methods("POST")
+ sub.Handle("", http.RedirectHandler("/codes/issue", http.StatusPermanentRedirect)).Methods("GET")
+ sub.Handle("/", http.RedirectHandler("/codes/issue", http.StatusPermanentRedirect)).Methods("GET")
+ sub.Handle("/issue", http.RedirectHandler("/codes/issue", http.StatusPermanentRedirect)).Methods("POST")
}
// codes
@@ -222,9 +214,6 @@ func Server(
sub.Handle("", http.RedirectHandler("/codes/issue", http.StatusSeeOther)).Methods("GET")
sub.Handle("/", http.RedirectHandler("/codes/issue", http.StatusSeeOther)).Methods("GET")
- homeController := home.New(ctx, cfg, db, h)
- sub.Handle("/issue", homeController.HandleHome()).Methods("GET")
-
// API for creating new verification codes. Called via AJAX.
issueapiController := issueapi.New(ctx, cfg, db, limiterStore, h)
sub.Handle("/issue", issueapiController.HandleIssue()).Methods("POST")
@@ -337,6 +326,7 @@ func Server(
// codesRoutes are the routes for checking codes.
func codesRoutes(r *mux.Router, c *codes.Controller) {
+ r.Handle("/issue", c.HandleIssue()).Methods("GET")
r.Handle("/status", c.HandleIndex()).Methods("GET")
r.Handle("/{uuid}", c.HandleShow()).Methods("GET")
r.Handle("/{uuid}/expire", c.HandleExpirePage()).Methods("PATCH")
diff --git a/pkg/controller/home/home.go b/pkg/controller/codes/issue.go
similarity index 62%
rename from pkg/controller/home/home.go
rename to pkg/controller/codes/issue.go
index 8d3b05781..5f69bd0a6 100644
--- a/pkg/controller/home/home.go
+++ b/pkg/controller/codes/issue.go
@@ -12,49 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-// Package home defines a web controller for the home page of the verification
-// server. This view allows users to issue OTP codes and tie them to a diagnosis
-// and test date.
-package home
+package codes
import (
- "context"
"fmt"
"html/template"
"net/http"
"time"
- "github.com/google/exposure-notifications-verification-server/pkg/config"
"github.com/google/exposure-notifications-verification-server/pkg/controller"
- "github.com/google/exposure-notifications-verification-server/pkg/database"
- "github.com/google/exposure-notifications-verification-server/pkg/render"
)
-type Controller struct {
- config *config.ServerConfig
- db *database.Database
- h *render.Renderer
-
- pastDaysDuration time.Duration
- displayAllowedDays string
-}
-
-// New creates a new controller for the home page.
-func New(ctx context.Context, config *config.ServerConfig, db *database.Database, h *render.Renderer) *Controller {
- pastDaysDuration := -1 * config.AllowedSymptomAge
- displayAllowedDays := fmt.Sprintf("%.0f", config.AllowedSymptomAge.Hours()/24.0)
-
- return &Controller{
- config: config,
- db: db,
- h: h,
-
- pastDaysDuration: pastDaysDuration,
- displayAllowedDays: displayAllowedDays,
- }
-}
-
-func (c *Controller) HandleHome() http.Handler {
+func (c *Controller) HandleIssue() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
@@ -81,9 +50,11 @@ func (c *Controller) HandleHome() http.Handler {
// Set test date params
now := time.Now().UTC()
+ pastDaysDuration := -1 * c.serverconfig.AllowedSymptomAge
+ displayAllowedDays := fmt.Sprintf("%.0f", c.serverconfig.AllowedSymptomAge.Hours()/24.0)
m["maxDate"] = now.Format("2006-01-02")
- m["minDate"] = now.Add(c.pastDaysDuration).Format("2006-01-02")
- m["maxSymptomDays"] = c.displayAllowedDays
+ m["minDate"] = now.Add(pastDaysDuration).Format("2006-01-02")
+ m["maxSymptomDays"] = displayAllowedDays
m["duration"] = realm.CodeDuration.Duration.String()
m["hasSMSConfig"] = hasSMSConfig
diff --git a/pkg/controller/home/home_test.go b/pkg/controller/codes/issue_test.go
similarity index 96%
rename from pkg/controller/home/home_test.go
rename to pkg/controller/codes/issue_test.go
index a8842903d..f26cfcd5e 100644
--- a/pkg/controller/home/home_test.go
+++ b/pkg/controller/codes/issue_test.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package home_test
+package codes_test
import (
"context"
@@ -28,7 +28,7 @@ import (
"github.com/chromedp/chromedp"
)
-func TestHandleHome_IssueCode(t *testing.T) {
+func TestHandleIssue_IssueCode(t *testing.T) {
t.Parallel()
harness := envstest.NewServer(t)
@@ -81,7 +81,7 @@ func TestHandleHome_IssueCode(t *testing.T) {
chromedp.Navigate(`http://`+harness.Server.Addr()+`/codes/issue`),
// Wait for render.
- chromedp.WaitVisible(`body#home`, chromedp.ByQuery),
+ chromedp.WaitVisible(`body#codes-issue`, chromedp.ByQuery),
// Add a date fields
chromedp.SetValue(`input#test-date`, yesterday, chromedp.ByQuery),