diff --git a/server/main.go b/server/main.go index 8e36c9d..4319a7b 100644 --- a/server/main.go +++ b/server/main.go @@ -51,7 +51,6 @@ func main() { r.Html.Private.Handle("GET /group/{groupReference}", route.ExpectUser(route.GroupPage)) r.Html.Private.HandleFunc("POST /logout", route.LogoutPost) - r.Json.Public.HandleFunc("POST /register", route.RegisterPostJson) r.Json.Public.HandleFunc("GET /", routing.NotFoundJson) r.Json.Private.Handle("GET /users", route.ExpectUser(route.UsersJson)) diff --git a/server/routing/not_found.go b/server/routing/not_found.go index 10cb0f9..8cba1a1 100644 --- a/server/routing/not_found.go +++ b/server/routing/not_found.go @@ -5,7 +5,7 @@ import ( ) func NotFoundJson(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "application/json; charset=utf-8") w.WriteHeader(http.StatusNotFound) _, _ = w.Write([]byte(`{"GeneralError":"Not Found"}`)) - w.Header().Add("Content-Type", "application/json") } diff --git a/server/routing/register.go b/server/routing/register.go index 6eea8dd..38c454c 100644 --- a/server/routing/register.go +++ b/server/routing/register.go @@ -45,27 +45,9 @@ func (ctx *Context) RegisterPost(w http.ResponseWriter, r *http.Request) { if props != nil { ctx.RedirectWithFlash(w, r, "/register", "register_props", &props) + _ = json.NewEncoder(w).Encode(props) return } ctx.RedirectWithFlash(w, r, "/", "successful_registration", true) } - -type registerJsonParams struct { - Username string - NewPassword string - ConfirmPassword string -} - -func (ctx *Context) RegisterPostJson(w http.ResponseWriter, r *http.Request) { - var params registerJsonParams - err := decodeJsonParams(r, ¶ms) - if err != nil { - writeGeneralError(w, "Failed to decode json params: "+err.Error(), http.StatusBadRequest) - return - } - - props := api.Register(params.Username, params.NewPassword, params.ConfirmPassword) - - _ = json.NewEncoder(w).Encode(props) -}