func HandleCreateUser(
	u *graylog.User, lgc *logic.Logic,
	w http.ResponseWriter, r *http.Request, _ httprouter.Params,
) (interface{}, int, error) {
	// POST /users Create a new user account.
	if sc, err := lgc.Authorize(u, "users:create"); err != nil {
		return nil, sc, err
	}
	body, sc, err := validateRequestBody(
		r.Body, &validateReqBodyPrms{
			Required: set.NewStrSet("username", "email", "permissions", "full_name", "password"),
			Optional: set.NewStrSet("startpage", "timezone", "session_timeout_ms", "roles"),
		})
	if err != nil {
		return nil, sc, err
	}

	user := &graylog.User{}
	if err := util.MSDecode(body, user); err != nil {
		lgc.Logger().WithFields(log.Fields{
			"body": body, "error": err,
		}).Info("Failed to parse request body as User")
		return nil, 400, err
	}

	sc, err = lgc.AddUser(user)
	if err != nil {
		return nil, sc, err
	}
	if err := lgc.Save(); err != nil {
		return nil, 500, err
	}
	return nil, sc, nil
}
// HandleCreateUser is the handler of Create User API.
HandleCreateUser is the handler of Create User API.
// HandleCreateUser is the handler of Create User API .
func HandleCreateUser(
	u *graylog.User, lgc *logic.Logic,
	w http.ResponseWriter, r *http.Request, _ httprouter.Params,
) (interface{}, int, error) {
	if sc, err := lgc.Authorize(u, "users:create"); err != nil {
		return nil, sc, err
	}
	body, sc, err := validateRequestBody(
		r.Body, &validateReqBodyPrms{
			Required: set.NewStrSet("username", "email", "permissions", "full_name", "password"),
			Optional: set.NewStrSet("startpage", "timezone", "session_timeout_ms", "roles"),
		})
	if err != nil {
		return nil, sc, err
	}
	user := &graylog.User{}
	if err := util.MSDecode(body, user); err != nil {
		lgc.Logger().WithFields(log.Fields{
			"body": body, "error": err,
		}).Info("Failed to parse request body as User")
		return nil, 400, err
	}
	sc, err = lgc.AddUser(user)
	if err != nil {
		return nil, sc, err
	}
	if err := lgc.Save(); err != nil {
		return nil, 500, err
	}
	return nil, sc, nil
}
func HandleCreateUser ( u * graylog . User , lgc * logic . Logic , w http . ResponseWriter , r * http . Request , _ httprouter . Params , ) ( interface { } , int , error ) { if sc , err := lgc . Authorize ( u , " " ) ; err != nil { return nil , sc , err } body , sc , err := validateRequestBody ( r . Body , & validateReqBodyPrms { Required : set . NewStrSet ( " " , " " , " " , " " , " " ) , Optional : set . NewStrSet ( " " , " " , " " , " " ) , } ) if err != nil { return nil , sc , err } user := & graylog . User { } if err := util . MSDecode ( body , user ) ; err != nil { lgc . Logger ( ) . WithFields ( log . Fields { " " : body , " " : err , } ) . Info ( " " ) return nil , 400 , err } sc , err = lgc . AddUser ( user ) if err != nil { return nil , sc , err } if err := lgc . Save ( ) ; err != nil { return nil , 500 , err } return nil , sc , nil }
HandleCreateUser is the handler of Create User API.
HandleCreateUser is the handler of Create User API .
// POST /users Create a new user account.