From 437905543424568c535940dbd9af6929fcf8ed04 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sun, 4 Nov 2018 14:30:02 +0100 Subject: [PATCH] Minor API fixes Signed-off-by: Knut Ahlers --- api_funcs.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/api_funcs.go b/api_funcs.go index 38986d0..1febad8 100644 --- a/api_funcs.go +++ b/api_funcs.go @@ -34,7 +34,7 @@ func apiChangeLoginPassword(ctx context.Context, res http.ResponseWriter, r *htt username = mux.Vars(r)["user"] ) - if err := json.NewDecoder(r.Body).Decode(input); err != nil { + if err := json.NewDecoder(r.Body).Decode(&input); err != nil { return nil, http.StatusBadRequest, wrapAPIError(err, "Unable to decode login data") } @@ -132,7 +132,7 @@ func apiLogin(ctx context.Context, res http.ResponseWriter, r *http.Request, ses output = map[string]interface{}{"success": true} ) - if err := json.NewDecoder(r.Body).Decode(input); err != nil { + if err := json.NewDecoder(r.Body).Decode(&input); err != nil { return nil, http.StatusBadRequest, wrapAPIError(err, "Unable to decode login data") } @@ -212,7 +212,7 @@ func apiRegister(ctx context.Context, res http.ResponseWriter, r *http.Request, output = map[string]interface{}{"success": true} ) - if err := json.NewDecoder(r.Body).Decode(input); err != nil { + if err := json.NewDecoder(r.Body).Decode(&input); err != nil { return nil, http.StatusBadRequest, wrapAPIError(err, "Unable to decode request") } @@ -240,6 +240,9 @@ func apiRegister(ctx context.Context, res http.ResponseWriter, r *http.Request, return nil, http.StatusInternalServerError, wrapAPIError(err, "Could not write data file") } + // Log-in the newly created user + sess.Users[input.Username] = userStateLoggedin + return output, http.StatusOK, nil } @@ -259,7 +262,7 @@ func apiSetUserData(ctx context.Context, res http.ResponseWriter, r *http.Reques username = mux.Vars(r)["user"] ) - if err := json.NewDecoder(r.Body).Decode(input); err != nil { + if err := json.NewDecoder(r.Body).Decode(&input); err != nil { return nil, http.StatusBadRequest, wrapAPIError(err, "Unable to decode request") } @@ -315,7 +318,7 @@ func apiValidateMFA(ctx context.Context, res http.ResponseWriter, r *http.Reques user = mux.Vars(r)["user"] ) - if err := json.NewDecoder(r.Body).Decode(input); err != nil { + if err := json.NewDecoder(r.Body).Decode(&input); err != nil { return nil, http.StatusBadRequest, wrapAPIError(err, "Unable to decode login data") }