diff --git a/internal/routes/app.go b/internal/routes/app.go index b0074e0..8133f6e 100644 --- a/internal/routes/app.go +++ b/internal/routes/app.go @@ -17,10 +17,9 @@ type PageView struct { Refresh bool } -// NewApp initializes the template renderer and the session cookie. -// Returns a new HTTP application server. +// NewServer sets up the HTTP server routes and starts the HTTP server. func NewServer(container *services.Container) { - // Static + // Handle static files fileServer := http.FileServer(http.Dir("./web/static")) http.Handle("/resources/", http.StripPrefix("/resources", fileServer)) http.Handle("/robots.txt", fileServer) diff --git a/internal/routes/crawl.go b/internal/routes/crawl.go index 364a97f..8c7d2d5 100644 --- a/internal/routes/crawl.go +++ b/internal/routes/crawl.go @@ -27,34 +27,30 @@ type crawlHandler struct { } // handleCrawl handles the crawling of a project. -// It expects a query parameter "pid" containing the project ID to be crawled. +// It expects a query parameter "pid" containing the project id to be crawled. // In case the project requieres BasicAuth it will redirect the user to the BasicAuth // credentials URL. Otherwise, it starts a new crawler. func (h *crawlHandler) handleCrawl(w http.ResponseWriter, r *http.Request) { pid, err := strconv.Atoi(r.URL.Query().Get("pid")) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } user, ok := h.CookieSession.GetUser(r.Context()) if !ok { http.Redirect(w, r, "/signout", http.StatusSeeOther) - return } p, err := h.ProjectService.FindProject(pid, user.Id) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } if p.BasicAuth { http.Redirect(w, r, "/crawl/auth?id="+strconv.Itoa(pid), http.StatusSeeOther) - return } @@ -72,27 +68,26 @@ func (h *crawlHandler) handleCrawl(w http.ResponseWriter, r *http.Request) { } // handleStopCrawl handles the crawler stopping. -// It expects a query paramater "pid" containinng the project ID that is being crawled. +// It expects a query paramater "pid" containinng the project id that is being crawled. // Aftar making sure the user owns the project it is stopped. +// In case the request is made via ajax with the X-Requested-With header it will return +// a json response, otherwise it will redirect the user back to the live crawl page. func (h *crawlHandler) handleStopCrawl(w http.ResponseWriter, r *http.Request) { pid, err := strconv.Atoi(r.URL.Query().Get("pid")) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } user, ok := h.CookieSession.GetUser(r.Context()) if !ok { http.Redirect(w, r, "/signout", http.StatusSeeOther) - return } p, err := h.ProjectService.FindProject(pid, user.Id) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -103,7 +98,6 @@ func (h *crawlHandler) handleStopCrawl(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "hlication/json") w.WriteHeader(http.StatusCreated) json.NewEncoder(w).Encode(data) - return } @@ -111,10 +105,9 @@ func (h *crawlHandler) handleStopCrawl(w http.ResponseWriter, r *http.Request) { } // handleCrawlAuth handles the crawling of a project with BasicAuth. -// It expects a query parameter "pid" containing the project ID to be crawled. +// It expects a query parameter "pid" containing the project id to be crawled. // A form will be presented to the user to input the BasicAuth credentials, once the // form is submitted a crawler with BasicAuth is started. -// // The function handles both GET and POST HTTP methods. // GET: Renders the auth form. // POST: Processes the auth form data and starts the crawler. @@ -122,21 +115,18 @@ func (h *crawlHandler) handleCrawlAuth(w http.ResponseWriter, r *http.Request) { pid, err := strconv.Atoi(r.URL.Query().Get("pid")) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } user, ok := h.CookieSession.GetUser(r.Context()) if !ok { http.Redirect(w, r, "/signout", http.StatusSeeOther) - return } p, err := h.ProjectService.FindProject(pid, user.Id) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -144,7 +134,6 @@ func (h *crawlHandler) handleCrawlAuth(w http.ResponseWriter, r *http.Request) { err := r.ParseForm() if err != nil { http.Redirect(w, r, "/crawl/auth", http.StatusSeeOther) - return } @@ -175,39 +164,36 @@ func (h *crawlHandler) handleCrawlAuth(w http.ResponseWriter, r *http.Request) { } // handleCrawlLive handles the request for the live crawling of a project. -// It expects a query parameter "pid" containing the project ID to be crawled. +// It expects a query parameter "pid" containing the project id to be crawled. +// This handler renders a page that will connect via websockets to display the progress +// of the crawl. func (h *crawlHandler) handleCrawlLive(w http.ResponseWriter, r *http.Request) { pid, err := strconv.Atoi(r.URL.Query().Get("pid")) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } user, ok := h.CookieSession.GetUser(r.Context()) if !ok { http.Redirect(w, r, "/signout", http.StatusSeeOther) - return } pv, err := h.ProjectViewService.GetProjectView(pid, user.Id) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } if pv.Crawl.IssuesEnd.Valid { http.Redirect(w, r, "/dashboard?pid="+strconv.Itoa(pid), http.StatusSeeOther) - return } configURL, err := url.Parse(h.Config.HTTPServer.URL) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -227,27 +213,24 @@ func (h *crawlHandler) handleCrawlLive(w http.ResponseWriter, r *http.Request) { } // handleCrawlWs handles the live crawling of a project using websockets. -// It expects a query parameter "pid" containing the project ID. +// It expects a query parameter "pid" containing the project id. // It upgrades the connection to websockets and sends the crawler messages through it. func (h *crawlHandler) handleCrawlWs(w http.ResponseWriter, r *http.Request) { pid, err := strconv.Atoi(r.URL.Query().Get("pid")) if err != nil { w.WriteHeader(http.StatusBadRequest) - return } user, ok := h.CookieSession.GetUser(r.Context()) if !ok { w.WriteHeader(http.StatusUnauthorized) - return } p, err := h.ProjectService.FindProject(pid, user.Id) if err != nil { w.WriteHeader(http.StatusUnauthorized) - return } @@ -257,15 +240,13 @@ func (h *crawlHandler) handleCrawlWs(w http.ResponseWriter, r *http.Request) { WriteBufferSize: 1024, CheckOrigin: func(r *http.Request) bool { origin := r.Header.Get("Origin") - return origin == h.Config.HTTPServer.URL }, } conn, err := upgrader.Upgrade(w, r, nil) if err != nil { - log.Println(err) - + log.Printf("crawlWS upgrader error: %v", err) return } defer conn.Close() @@ -275,6 +256,7 @@ func (h *crawlHandler) handleCrawlWs(w http.ResponseWriter, r *http.Request) { connLock := &sync.RWMutex{} + // Subscribe to the pubsub broker to keep track of the crawl's progress. subscriber := h.PubSubBroker.NewSubscriber(fmt.Sprintf("crawl-%d", p.Id), func(i *models.Message) error { pubsubMessage := i wsMessage := struct { diff --git a/internal/routes/dashboard.go b/internal/routes/dashboard.go index c5237b2..55085fb 100644 --- a/internal/routes/dashboard.go +++ b/internal/routes/dashboard.go @@ -12,48 +12,42 @@ type dashboardHandler struct { *services.Container } -type DashboardView struct { - ProjectView *models.ProjectView - MediaChart *models.Chart - StatusChart *models.Chart - Crawls []models.Crawl - CanonicalCount *models.CanonicalCount - AltCount *models.AltCount - SchemeCount *models.SchemeCount - StatusCodeByDepth []models.StatusCodeByDepth -} - -// handleDashboard handles the dashboard of a project. -// It expects a query parameter "pid" containing the project ID. +// handleDashboard handles the dashboard of a project with all the needed data to render +// the charts. It expects a query parameter "pid" containing the project id. func (h *dashboardHandler) handleDashboard(w http.ResponseWriter, r *http.Request) { user, ok := h.CookieSession.GetUser(r.Context()) if !ok { http.Redirect(w, r, "/signout", http.StatusSeeOther) - return } pid, err := strconv.Atoi(r.URL.Query().Get("pid")) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } pv, err := h.ProjectViewService.GetProjectView(pid, user.Id) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } if pv.Crawl.TotalURLs == 0 { http.Redirect(w, r, "/", http.StatusSeeOther) - return } - data := DashboardView{ + data := struct { + ProjectView *models.ProjectView + MediaChart *models.Chart + StatusChart *models.Chart + Crawls []models.Crawl + CanonicalCount *models.CanonicalCount + AltCount *models.AltCount + SchemeCount *models.SchemeCount + StatusCodeByDepth []models.StatusCodeByDepth + }{ ProjectView: pv, MediaChart: h.ReportService.GetMediaCount(pv.Crawl.Id), StatusChart: h.ReportService.GetStatusCount(pv.Crawl.Id), diff --git a/internal/routes/explorer.go b/internal/routes/explorer.go index 7a87729..e73f6f0 100644 --- a/internal/routes/explorer.go +++ b/internal/routes/explorer.go @@ -15,7 +15,7 @@ type explorerHandler struct { // handleExplorer handles the URL explorer request. // It performas a search of pagereports based on the "term" parameter. In case the "term" parameter // is empty, it loads all the pagereports. -// It expects a query parameter "pid" containing the project ID, the "p" parameter containing the current +// It expects a query parameter "pid" containing the project id, the "p" parameter containing the current // page in the paginator, and the "term" parameter used to perform the pagereport search. func (h *explorerHandler) handleExplorer(w http.ResponseWriter, r *http.Request) { // Get user from the request's context diff --git a/internal/routes/export.go b/internal/routes/export.go index 38aa2be..a81e876 100644 --- a/internal/routes/export.go +++ b/internal/routes/export.go @@ -18,6 +18,7 @@ type exportHandler struct { } // handleExport handles the export request and renders the the export template. +// It expects a "pid" query parameter with the project's id. func (h *exportHandler) handleExport(w http.ResponseWriter, r *http.Request) { pid, err := strconv.Atoi(r.URL.Query().Get("pid")) if err != nil { @@ -50,25 +51,23 @@ func (h *exportHandler) handleExport(w http.ResponseWriter, r *http.Request) { } // handleDownloadCSV exports the pagereports of a specific project as a CSV file by issue type. +// It expects a "pid" query parameter with the project's id. func (h *exportHandler) handleDownloadCSV(w http.ResponseWriter, r *http.Request) { pid, err := strconv.Atoi(r.URL.Query().Get("pid")) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } user, ok := h.CookieSession.GetUser(r.Context()) if !ok { http.Redirect(w, r, "/signout", http.StatusSeeOther) - return } pv, err := h.ProjectViewService.GetProjectView(pid, user.Id) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -89,25 +88,23 @@ func (h *exportHandler) handleDownloadCSV(w http.ResponseWriter, r *http.Request } // handleSitemap exports the crawled urls of a specific project as a sitemap.xml file. +// It expects a "pid" query parameter with the project's id. func (h *exportHandler) handleSitemap(w http.ResponseWriter, r *http.Request) { pid, err := strconv.Atoi(r.URL.Query().Get("pid")) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } user, ok := h.CookieSession.GetUser(r.Context()) if !ok { http.Redirect(w, r, "/signout", http.StatusSeeOther) - return } pv, err := h.ProjectViewService.GetProjectView(pid, user.Id) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -126,26 +123,24 @@ func (h *exportHandler) handleSitemap(w http.ResponseWriter, r *http.Request) { } // handleExportResources exports the resources of a specific project. -// The URL query parameter t specifys the type of resources to be exported. +// It expects a "pid" query parameter with the project's id as well as a query +// parameter "t" specifys the type of resources to be exported. func (h *exportHandler) handleExportResources(w http.ResponseWriter, r *http.Request) { pid, err := strconv.Atoi(r.URL.Query().Get("pid")) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } user, ok := h.CookieSession.GetUser(r.Context()) if !ok { http.Redirect(w, r, "/signout", http.StatusSeeOther) - return } pv, err := h.ProjectViewService.GetProjectView(pid, user.Id) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -166,13 +161,10 @@ func (h *exportHandler) handleExportResources(w http.ResponseWriter, r *http.Req e, ok := m[t] if !ok { http.Redirect(w, r, "/", http.StatusSeeOther) - return } fileName := pv.Project.Host + " " + t + " " + time.Now().Format("2006-01-02") - w.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s.csv\"", fileName)) - e(w, &pv.Crawl) } diff --git a/internal/routes/issues.go b/internal/routes/issues.go index 5e7b900..1a91732 100644 --- a/internal/routes/issues.go +++ b/internal/routes/issues.go @@ -13,32 +13,28 @@ type issueHandler struct { } // handleIssues handles the issues view of a project. -// It expects a query parameter "pid" containing the project ID. +// It expects a query parameter "pid" containing the project id. func (h *issueHandler) handleIssues(w http.ResponseWriter, r *http.Request) { user, ok := h.CookieSession.GetUser(r.Context()) if !ok { http.Redirect(w, r, "/signout", http.StatusSeeOther) - return } pid, err := strconv.Atoi(r.URL.Query().Get("pid")) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } pv, err := h.ProjectViewService.GetProjectView(pid, user.Id) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } if pv.Crawl.TotalURLs == 0 { http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -57,27 +53,24 @@ func (h *issueHandler) handleIssues(w http.ResponseWriter, r *http.Request) { } // handleIssuesView handles the view of project's specific issue type. -// It expects a query parameter "pid" containing the project ID and an "eid" parameter +// It expects a query parameter "pid" containing the project id and an "eid" parameter // containing the issue type. func (h *issueHandler) handleIssuesView(w http.ResponseWriter, r *http.Request) { user, ok := h.CookieSession.GetUser(r.Context()) if !ok { http.Redirect(w, r, "/signout", http.StatusSeeOther) - return } eid := r.URL.Query().Get("eid") if eid == "" { http.Redirect(w, r, "/", http.StatusSeeOther) - return } pid, err := strconv.Atoi(r.URL.Query().Get("pid")) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -89,14 +82,12 @@ func (h *issueHandler) handleIssuesView(w http.ResponseWriter, r *http.Request) pv, err := h.ProjectViewService.GetProjectView(pid, user.Id) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } paginatorView, err := h.IssueService.GetPaginatedReportsByIssue(pv.Crawl.Id, page, eid) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } diff --git a/internal/routes/project.go b/internal/routes/project.go index 9dd6778..bff274b 100644 --- a/internal/routes/project.go +++ b/internal/routes/project.go @@ -45,11 +45,11 @@ func (h *projectHandler) handleHome(w http.ResponseWriter, r *http.Request) { } // handleProjectAdd handles the form for adding a new project. +// This handler handles both, the GET and POST requests. func (h *projectHandler) handleProjectAdd(w http.ResponseWriter, r *http.Request) { user, ok := h.CookieSession.GetUser(r.Context()) if !ok { http.Redirect(w, r, "/signout", http.StatusSeeOther) - return } @@ -66,7 +66,6 @@ func (h *projectHandler) handleProjectAdd(w http.ResponseWriter, r *http.Request if err != nil { log.Printf("serveProjectAdd ParseForm: %v\n", err) http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -111,7 +110,6 @@ func (h *projectHandler) handleProjectAdd(w http.ResponseWriter, r *http.Request if err != nil { data.Error = true h.Renderer.RenderTemplate(w, "project_add", pageView) - return } @@ -130,7 +128,6 @@ func (h *projectHandler) handleProjectAdd(w http.ResponseWriter, r *http.Request if err != nil { data.Error = true h.Renderer.RenderTemplate(w, "project_add", pageView) - return } @@ -142,26 +139,23 @@ func (h *projectHandler) handleProjectAdd(w http.ResponseWriter, r *http.Request } // handleDeleteProject handles the deletion of a project. -// It expects a query parameter "pid" containing the project ID to be deleted. +// It expects a query parameter "pid" containing the project id to be deleted. func (h *projectHandler) handleDeleteProject(w http.ResponseWriter, r *http.Request) { pid, err := strconv.Atoi(r.URL.Query().Get("pid")) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } user, ok := h.CookieSession.GetUser(r.Context()) if !ok { http.Redirect(w, r, "/signout", http.StatusSeeOther) - return } p, err := h.ProjectService.FindProject(pid, user.Id) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -171,26 +165,24 @@ func (h *projectHandler) handleDeleteProject(w http.ResponseWriter, r *http.Requ } // handleProjectEdit handles the edition of a project. -// It expects a query parameter "pid" containing the project ID to be edited. +// It expects a query parameter "pid" containing the project id to be edited. +// Thes handler handles both, the GET and POST requests. func (h *projectHandler) handleProjectEdit(w http.ResponseWriter, r *http.Request) { pid, err := strconv.Atoi(r.URL.Query().Get("pid")) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } user, ok := h.CookieSession.GetUser(r.Context()) if !ok { http.Redirect(w, r, "/signout", http.StatusSeeOther) - return } p, err := h.ProjectService.FindProject(pid, user.Id) if err != nil { http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -254,12 +246,10 @@ func (h *projectHandler) handleProjectEdit(w http.ResponseWriter, r *http.Reques if err != nil { data.Error = true h.Renderer.RenderTemplate(w, "project_edit", pageView) - return } http.Redirect(w, r, "/", http.StatusSeeOther) - return } diff --git a/internal/routes/resource.go b/internal/routes/resource.go index f2f72d9..b71f348 100644 --- a/internal/routes/resource.go +++ b/internal/routes/resource.go @@ -15,11 +15,10 @@ type resourceHandler struct { } // handleResourcesView handles the HTTP request for the resources view page. -// // It expects the following query parameters: -// - "pid" containing the project ID. -// - "rid" the ID of the resource to be loaded. -// - "eid" the ID of the issue type from wich the user loaded this resource. +// - "pid" containing the project id. +// - "rid" the id of the resource to be loaded. +// - "eid" the id of the issue type from wich the user loaded this resource. // - "ep" the explorer page number from which the user loaded this resource. // - "t" the tab to be loaded, which defaults to the details tab. // - "p" the number of page to be loaded, in case the resource page has pagination. @@ -27,7 +26,6 @@ func (h *resourceHandler) handleResourcesView(w http.ResponseWriter, r *http.Req user, ok := h.CookieSession.GetUser(r.Context()) if !ok { http.Redirect(w, r, "/signout", http.StatusSeeOther) - return } @@ -35,7 +33,6 @@ func (h *resourceHandler) handleResourcesView(w http.ResponseWriter, r *http.Req if err != nil { log.Printf("serveResourcesView pid: %v\n", err) http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -43,7 +40,6 @@ func (h *resourceHandler) handleResourcesView(w http.ResponseWriter, r *http.Req if err != nil { log.Printf("serveResourcesView rid: %v\n", err) http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -52,7 +48,6 @@ func (h *resourceHandler) handleResourcesView(w http.ResponseWriter, r *http.Req if eid == "" && ep == "" { log.Println("serveResourcesView: no eid or ep parameter set") http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -70,7 +65,6 @@ func (h *resourceHandler) handleResourcesView(w http.ResponseWriter, r *http.Req if err != nil { log.Printf("serveResourcesView GetProjectView: %v\n", err) http.Redirect(w, r, "/", http.StatusSeeOther) - return } diff --git a/internal/routes/user.go b/internal/routes/user.go index 1c9f3a0..01056e9 100644 --- a/internal/routes/user.go +++ b/internal/routes/user.go @@ -14,7 +14,6 @@ type userHandler struct { // handleSignup handles the signup functionality for the application. // It allows users to sign up by providing their email and password. // Upon successful signup, the user is automatically signed in and redirected to the home page. -// // The function handles both GET and POST HTTP methods. // GET: Renders the signup form. // POST: Processes the signup form data, performs signup, signs the user in, and redirects to the home page. @@ -34,7 +33,6 @@ func (h *userHandler) handleSignup(w http.ResponseWriter, r *http.Request) { if err != nil { log.Printf("serveSignup ParseForm: %v", err) http.Redirect(w, r, "/signup", http.StatusSeeOther) - return } @@ -46,7 +44,6 @@ func (h *userHandler) handleSignup(w http.ResponseWriter, r *http.Request) { log.Printf("serveSignup SignUp: %v", err) data.Error = true h.Renderer.RenderTemplate(w, "signup", pageView) - return } @@ -59,7 +56,6 @@ func (h *userHandler) handleSignup(w http.ResponseWriter, r *http.Request) { } // handleDeleteUser handles the HTTP GET and POST requests for the delete user account functionality. -// // The function handles both GET and POST HTTP methods. // GET: it renders the delete page with the appropriate data. // POST: it sign's out the user and deletes the account including all its associated data. @@ -67,7 +63,6 @@ func (h *userHandler) handleDeleteUser(w http.ResponseWriter, r *http.Request) { user, ok := h.CookieSession.GetUser(r.Context()) if !ok { http.Redirect(w, r, "/signout", http.StatusSeeOther) - return } @@ -92,11 +87,8 @@ func (h *userHandler) handleDeleteUser(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodPost { h.CookieSession.DestroySession(w, r) - h.UserService.DeleteUser(user) - http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -104,7 +96,6 @@ func (h *userHandler) handleDeleteUser(w http.ResponseWriter, r *http.Request) { } // handleSignin handles the HTTP GET and POST requests for the sign-in functionality. -// // The function handles both GET and POST HTTP methods. // GET: it renders the sign-in page with the appropriate data. // POST: it validates the user's credentials and creates a session if the sign-in is successful. @@ -124,7 +115,6 @@ func (h *userHandler) handleSignin(w http.ResponseWriter, r *http.Request) { if err != nil { log.Printf("serveSignin ParseForm: %v\n", err) http.Redirect(w, r, "/signin", http.StatusSeeOther) - return } @@ -134,9 +124,7 @@ func (h *userHandler) handleSignin(w http.ResponseWriter, r *http.Request) { u, err := h.UserService.SignIn(data.Email, password) if err == nil { h.CookieSession.SetSession(u.Id, w, r) - http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -148,7 +136,6 @@ func (h *userHandler) handleSignin(w http.ResponseWriter, r *http.Request) { } // handleAccount handles the HTTP POST and GET requests for the account management functionality. -// // The function handles both GET and POST HTTP methods. // POST: it allows users to change their credentials by verifying the current password and // updating the password with a new one. @@ -157,7 +144,6 @@ func (h *userHandler) handleAccount(w http.ResponseWriter, r *http.Request) { user, ok := h.CookieSession.GetUser(r.Context()) if !ok { http.Redirect(w, r, "/signout", http.StatusSeeOther) - return } @@ -176,7 +162,6 @@ func (h *userHandler) handleAccount(w http.ResponseWriter, r *http.Request) { err := r.ParseForm() if err != nil { http.Redirect(w, r, "/signin", http.StatusSeeOther) - return } @@ -187,9 +172,7 @@ func (h *userHandler) handleAccount(w http.ResponseWriter, r *http.Request) { if err != nil { data.Error = true data.ErrorMessage = "Current password is not correct." - h.Renderer.RenderTemplate(w, "account", pageView) - return } @@ -197,14 +180,11 @@ func (h *userHandler) handleAccount(w http.ResponseWriter, r *http.Request) { if err != nil { data.Error = true data.ErrorMessage = "New password is not valid." - h.Renderer.RenderTemplate(w, "account", pageView) - return } http.Redirect(w, r, "/", http.StatusSeeOther) - return } @@ -215,6 +195,5 @@ func (h *userHandler) handleAccount(w http.ResponseWriter, r *http.Request) { // It clears the session data related to authenticated user. func (h *userHandler) handleSignout(w http.ResponseWriter, r *http.Request) { h.CookieSession.DestroySession(w, r) - http.Redirect(w, r, "/", http.StatusSeeOther) } diff --git a/web/templates/crawl_live.html b/web/templates/crawl_live.html index 4142f3b..270ba0d 100644 --- a/web/templates/crawl_live.html +++ b/web/templates/crawl_live.html @@ -140,7 +140,7 @@