feat: remove register json post endpoint

This commit is contained in:
Teajey 2024-11-21 09:36:14 +09:00
parent 994f4ee64a
commit 5a4097f4fe
Signed by: Teajey
GPG Key ID: 970E790FE834A713
3 changed files with 2 additions and 21 deletions

View File

@ -51,7 +51,6 @@ func main() {
r.Html.Private.Handle("GET /group/{groupReference}", route.ExpectUser(route.GroupPage)) r.Html.Private.Handle("GET /group/{groupReference}", route.ExpectUser(route.GroupPage))
r.Html.Private.HandleFunc("POST /logout", route.LogoutPost) 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.Public.HandleFunc("GET /", routing.NotFoundJson)
r.Json.Private.Handle("GET /users", route.ExpectUser(route.UsersJson)) r.Json.Private.Handle("GET /users", route.ExpectUser(route.UsersJson))

View File

@ -5,7 +5,7 @@ import (
) )
func NotFoundJson(w http.ResponseWriter, r *http.Request) { func NotFoundJson(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
_, _ = w.Write([]byte(`{"GeneralError":"Not Found"}`)) _, _ = w.Write([]byte(`{"GeneralError":"Not Found"}`))
w.Header().Add("Content-Type", "application/json")
} }

View File

@ -45,27 +45,9 @@ func (ctx *Context) RegisterPost(w http.ResponseWriter, r *http.Request) {
if props != nil { if props != nil {
ctx.RedirectWithFlash(w, r, "/register", "register_props", &props) ctx.RedirectWithFlash(w, r, "/register", "register_props", &props)
_ = json.NewEncoder(w).Encode(props)
return return
} }
ctx.RedirectWithFlash(w, r, "/", "successful_registration", true) 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, &params)
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)
}