2016-09-26 18:48:55 +00:00
|
|
|
package service
|
2016-08-28 03:59:17 +00:00
|
|
|
|
|
|
|
import (
|
2017-03-15 15:55:30 +00:00
|
|
|
"context"
|
2016-08-28 03:59:17 +00:00
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
2017-01-06 22:38:39 +00:00
|
|
|
"github.com/pkg/errors"
|
2016-08-28 03:59:17 +00:00
|
|
|
)
|
|
|
|
|
2017-01-17 16:43:59 +00:00
|
|
|
func decodeEnableUserRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var req enableUserRequest
|
|
|
|
if err = json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
req.ID = id
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeAdminUserRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var req adminUserRequest
|
|
|
|
if err = json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
req.ID = id
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2016-09-01 04:51:38 +00:00
|
|
|
func decodeCreateUserRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
2016-08-28 03:59:17 +00:00
|
|
|
var req createUserRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2016-09-01 04:51:38 +00:00
|
|
|
func decodeGetUserRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
2016-09-04 05:13:42 +00:00
|
|
|
id, err := idFromRequest(r, "id")
|
2016-09-01 04:51:38 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-08-28 03:59:17 +00:00
|
|
|
}
|
2016-09-04 05:13:42 +00:00
|
|
|
return getUserRequest{ID: id}, nil
|
2016-09-01 04:51:38 +00:00
|
|
|
}
|
|
|
|
|
2016-10-13 18:21:47 +00:00
|
|
|
func decodeListUsersRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
opt, err := listOptionsFromRequest(r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return listUsersRequest{ListOptions: opt}, nil
|
|
|
|
}
|
|
|
|
|
2016-09-15 14:52:17 +00:00
|
|
|
func decodeModifyUserRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
2016-09-04 05:13:42 +00:00
|
|
|
id, err := idFromRequest(r, "id")
|
2016-09-01 04:51:38 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-09-15 14:52:17 +00:00
|
|
|
var req modifyUserRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
|
2016-09-01 04:51:38 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2016-09-15 14:52:17 +00:00
|
|
|
req.ID = id
|
2016-09-01 04:51:38 +00:00
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2016-12-14 18:11:43 +00:00
|
|
|
func decodeChangePasswordRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
var req changePasswordRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2017-01-06 22:38:39 +00:00
|
|
|
func decodeRequirePasswordResetRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "getting ID from request")
|
|
|
|
}
|
|
|
|
|
|
|
|
var req requirePasswordResetRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
|
|
return nil, errors.Wrap(err, "decoding JSON")
|
|
|
|
}
|
|
|
|
req.ID = id
|
|
|
|
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2017-01-10 04:42:50 +00:00
|
|
|
func decodePerformRequiredPasswordResetRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
var req performRequiredPasswordResetRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
|
|
return nil, errors.Wrap(err, "decoding JSON")
|
|
|
|
}
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2016-09-15 14:52:17 +00:00
|
|
|
func decodeForgotPasswordRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
var req forgotPasswordRequest
|
2016-09-01 04:51:38 +00:00
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2016-09-15 14:52:17 +00:00
|
|
|
func decodeResetPasswordRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
var req resetPasswordRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
2016-08-28 03:59:17 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2016-09-01 04:51:38 +00:00
|
|
|
return req, nil
|
|
|
|
}
|