From 615aae6bdd9f1617fff7598fc507bb4d0d5dcb54 Mon Sep 17 00:00:00 2001 From: Jeremy Wharton Date: Mon, 26 Jul 2021 11:11:44 -0500 Subject: [PATCH] web/satellite: Remove activated account page Error message for attempting to activate an already-activated account is removed from its own page and incorporated into the login page in an identical manner to the message that appears upon successful activation. Change-Id: I29cd2685a7808fa71d34a439c86a38eb5fc3e199 --- satellite/console/consoleweb/server.go | 13 +--- satellite/console/consoleweb/server_test.go | 60 ++++++++++++++++ web/satellite/src/views/LoginArea.vue | 21 ++++-- web/satellite/static/activation/activated.css | 68 ------------------- .../static/activation/activated.html | 33 --------- 5 files changed, 76 insertions(+), 119 deletions(-) create mode 100644 satellite/console/consoleweb/server_test.go delete mode 100644 web/satellite/static/activation/activated.css delete mode 100644 web/satellite/static/activation/activated.html diff --git a/satellite/console/consoleweb/server.go b/satellite/console/consoleweb/server.go index 4512dbcbe..ed18d533d 100644 --- a/satellite/console/consoleweb/server.go +++ b/satellite/console/consoleweb/server.go @@ -160,7 +160,6 @@ type Server struct { usageReport *template.Template resetPassword *template.Template success *template.Template - activated *template.Template } } @@ -559,7 +558,7 @@ func (server *Server) accountActivationHandler(w http.ResponseWriter, r *http.Re zap.Error(err)) if console.ErrEmailUsed.Has(err) { - server.serveError(w, http.StatusConflict) + http.Redirect(w, r, server.config.ExternalAddress+"login?activated=false", http.StatusTemporaryRedirect) return } @@ -767,11 +766,6 @@ func (server *Server) serveError(w http.ResponseWriter, status int) { if err != nil { server.log.Error("cannot parse pageNotFound template", zap.Error(Error.Wrap(err))) } - case http.StatusConflict: - err := server.templates.activated.Execute(w, nil) - if err != nil { - server.log.Error("cannot parse already activated template", zap.Error(Error.Wrap(err))) - } } } @@ -827,11 +821,6 @@ func (server *Server) initializeTemplates() (err error) { server.log.Error("dist folder is not generated. use 'npm run build' command", zap.Error(err)) } - server.templates.activated, err = template.ParseFiles(filepath.Join(server.config.StaticDir, "static", "activation", "activated.html")) - if err != nil { - return Error.Wrap(err) - } - server.templates.success, err = template.ParseFiles(filepath.Join(server.config.StaticDir, "static", "resetPassword", "success.html")) if err != nil { return Error.Wrap(err) diff --git a/satellite/console/consoleweb/server_test.go b/satellite/console/consoleweb/server_test.go new file mode 100644 index 000000000..39e952f42 --- /dev/null +++ b/satellite/console/consoleweb/server_test.go @@ -0,0 +1,60 @@ +// Copyright (C) 2021 Storj Labs, Inc. +// See LICENSE for copying information. + +package consoleweb_test + +import ( + "net/http" + "testing" + + "github.com/stretchr/testify/require" + + "storj.io/common/testcontext" + "storj.io/storj/private/testplanet" + "storj.io/storj/satellite/console" +) + +func TestActivationRouting(t *testing.T) { + testplanet.Run(t, testplanet.Config{ + SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 0, + }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { + sat := planet.Satellites[0] + service := sat.API.Console.Service + + regToken, err := service.CreateRegToken(ctx, 1) + require.NoError(t, err) + + user, err := service.CreateUser(ctx, console.CreateUser{ + FullName: "User", + Email: "u@mail.test", + Password: "123a123", + }, regToken.Secret) + require.NoError(t, err) + + activationToken, err := service.GenerateActivationToken(ctx, user.ID, user.Email) + require.NoError(t, err) + + checkActivationRedirect := func(testMsg, redirectURL string) { + url := "http://" + sat.API.Console.Listener.Addr().String() + "/activation/?token=" + activationToken + + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody) + require.NoError(t, err, testMsg) + + result, err := http.DefaultClient.Do(req) + require.NoError(t, err, testMsg) + + require.Equal(t, http.StatusTemporaryRedirect, result.StatusCode, testMsg) + require.Equal(t, redirectURL, result.Header.Get("Location"), testMsg) + require.NoError(t, result.Body.Close(), testMsg) + } + + http.DefaultClient.CheckRedirect = func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + } + + loginURL := "http://" + sat.API.Console.Listener.Addr().String() + "/login" + + checkActivationRedirect("Activation - Fresh Token", loginURL+"?activated=true") + checkActivationRedirect("Activation - Used Token", loginURL+"?activated=false") + }) +} diff --git a/web/satellite/src/views/LoginArea.vue b/web/satellite/src/views/LoginArea.vue index 0d949383b..0fac4c65b 100644 --- a/web/satellite/src/views/LoginArea.vue +++ b/web/satellite/src/views/LoginArea.vue @@ -8,8 +8,11 @@