forked from mirrors/homebox
cleanup user implementation
This commit is contained in:
parent
9501eb398a
commit
a9f53a4671
6 changed files with 39 additions and 35 deletions
|
@ -38,11 +38,6 @@ func (ctrl *BaseController) HandleBase(ready ReadyFunc, versions ...string) http
|
|||
Message: "Welcome to the Go API Template Application!",
|
||||
}
|
||||
|
||||
err := server.Respond(w, http.StatusOK, server.Wrap(data))
|
||||
|
||||
if err != nil {
|
||||
ctrl.log.Error(err, nil)
|
||||
server.RespondInternalServerError(w)
|
||||
}
|
||||
server.Respond(w, http.StatusOK, server.Wrap(data))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,11 +10,6 @@ import (
|
|||
"github.com/hay-kot/content/backend/pkgs/server"
|
||||
)
|
||||
|
||||
var (
|
||||
HeaderFormData = "application/x-www-form-urlencoded"
|
||||
HeaderJSON = "application/json"
|
||||
)
|
||||
|
||||
// HandleAuthLogin godoc
|
||||
// @Summary User Login
|
||||
// @Tags Authentication
|
||||
|
@ -29,7 +24,7 @@ func (ctrl *V1Controller) HandleAuthLogin() http.HandlerFunc {
|
|||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
loginForm := &types.LoginForm{}
|
||||
|
||||
if r.Header.Get("Content-Type") == HeaderFormData {
|
||||
if r.Header.Get("Content-Type") == server.ContentFormUrlEncoded {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
server.Respond(w, http.StatusBadRequest, server.Wrap(err))
|
||||
|
@ -39,7 +34,7 @@ func (ctrl *V1Controller) HandleAuthLogin() http.HandlerFunc {
|
|||
|
||||
loginForm.Username = r.PostFormValue("username")
|
||||
loginForm.Password = r.PostFormValue("password")
|
||||
} else if r.Header.Get("Content-Type") == HeaderJSON {
|
||||
} else if r.Header.Get("Content-Type") == server.ContentJSON {
|
||||
err := server.Decode(r, loginForm)
|
||||
|
||||
if err != nil {
|
||||
|
@ -66,17 +61,10 @@ func (ctrl *V1Controller) HandleAuthLogin() http.HandlerFunc {
|
|||
return
|
||||
}
|
||||
|
||||
err = server.Respond(w, http.StatusOK, types.TokenResponse{
|
||||
server.Respond(w, http.StatusOK, types.TokenResponse{
|
||||
BearerToken: "Bearer " + newToken.Raw,
|
||||
ExpiresAt: newToken.ExpiresAt,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
ctrl.log.Error(err, logger.Props{
|
||||
"user": loginForm.Username,
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,10 +118,6 @@ func (ctrl *V1Controller) HandleAuthRefresh() http.HandlerFunc {
|
|||
return
|
||||
}
|
||||
|
||||
err = server.Respond(w, http.StatusOK, newToken)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
server.Respond(w, http.StatusOK, newToken)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,14 +28,14 @@ func (ctrl *V1Controller) HandleUserRegistration() http.HandlerFunc {
|
|||
return
|
||||
}
|
||||
|
||||
usr, err := ctrl.svc.User.RegisterUser(r.Context(), regData)
|
||||
_, err := ctrl.svc.User.RegisterUser(r.Context(), regData)
|
||||
if err != nil {
|
||||
ctrl.log.Error(err, nil)
|
||||
server.RespondError(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
_ = server.Respond(w, http.StatusOK, server.Wrap(usr))
|
||||
server.Respond(w, http.StatusNoContent, nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,11 +52,11 @@ func (ctrl *V1Controller) HandleUserSelf() http.HandlerFunc {
|
|||
usr, err := ctrl.svc.User.GetSelf(r.Context(), token)
|
||||
if usr.ID == uuid.Nil || err != nil {
|
||||
ctrl.log.Error(errors.New("no user within request context"), nil)
|
||||
server.RespondInternalServerError(w)
|
||||
server.RespondServerError(w)
|
||||
return
|
||||
}
|
||||
|
||||
_ = server.Respond(w, http.StatusOK, server.Wrap(usr))
|
||||
server.Respond(w, http.StatusOK, server.Wrap(usr))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ func (ctrl *V1Controller) HandleUserUpdate() http.HandlerFunc {
|
|||
return
|
||||
}
|
||||
|
||||
_ = server.Respond(w, http.StatusOK, server.Wrap(newData))
|
||||
server.Respond(w, http.StatusOK, server.Wrap(newData))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue