@ -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) {
|
||||
|
23
internal/route/settings.go
Normal file
23
internal/route/settings.go
Normal 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})
|
||||
}
|
Reference in New Issue
Block a user