feat: redirect to register page if no users exist

fixes #130
This commit is contained in:
Jordan Knott
2021-10-06 14:20:36 -05:00
parent eab33bfd9a
commit 8b1de30204
8 changed files with 73 additions and 41 deletions

View File

@ -102,6 +102,7 @@ func NewRouter(dbConnection *sqlx.DB, emailConfig utils.EmailConfig, securityCon
mux.Mount("/uploads/", http.StripPrefix("/uploads/", imgServer))
mux.Post("/auth/confirm", taskcafeHandler.ConfirmUser)
mux.Post("/auth/register", taskcafeHandler.RegisterUser)
mux.Get("/settings", taskcafeHandler.PublicSettings)
})
auth := AuthenticationMiddleware{*repository}
r.Group(func(mux chi.Router) {

View File

@ -0,0 +1,23 @@
package route
import (
"encoding/json"
"net/http"
log "github.com/sirupsen/logrus"
)
type PublicSettingsResponse struct {
IsConfigured bool `json:"isConfigured"`
AllowPublicRegistration bool `json:"allowPublicRegistration"`
}
func (h *TaskcafeHandler) PublicSettings(w http.ResponseWriter, r *http.Request) {
userExists, err := h.repo.HasAnyUser(r.Context())
if err != nil {
log.WithError(err).Error("issue checking if user accounts exist")
w.WriteHeader(http.StatusInternalServerError)
return
}
json.NewEncoder(w).Encode(PublicSettingsResponse{IsConfigured: userExists, AllowPublicRegistration: false})
}