// NewUser create a new user using the given name, password and email.
//
// The last parameter is a flag that indicates if the user should be enabled or
// not.
//
// Besides creating the user, this method will also create a new role for the
// user using the given tenant and role. For example, if you have a "member"
// role with ID `834452bcb9f94178aaa4167cff1034df`, and a tenant with ID
// `2cc6842387314f868c9be75684c64530`, the following call will create a user
// called "gopher" and add it as a member of the tenant:
//
//     var role string = "834452bcb9f94178aaa4167cff1034df"
//     var tenant string = "2cc6842387314f868c9be75684c64530"
//     client.NewUser("gopher", "secret", "gopher@golang.org", tenant, role, true)
NewUser create a new user using the given name, password and email.

The last parameter is a flag that indicates if the user should be enabled or
not.

Besides creating the user, this method will also create a new role for the
user using the given tenant and role.


// NewUser create a new user using the given name password and email . // // The last parameter is a flag that indicates if the user should be enabled or // not . // // Besides creating the user this method will also create a new role for the // user using the given tenant and role . For example if you have a " member " // role with ID ` 834452bcb9f94178aaa4167cff1034df ` and a tenant with ID // ` 2cc6842387314f868c9be75684c64530 ` the following call will create a user // called " gopher " and add it as a member of the tenant : // // var role string = " 834452bcb9f94178aaa4167cff1034df " // var tenant string = " 2cc6842387314f868c9be75684c64530 " // client . NewUser ( " gopher " " secret " " gopher@golang . org " tenant role true )
func (c *Client) NewUser(name, password, email, tenantId, roleId string, enabled bool) (*User, error) {
	b := bytes.NewBufferString(fmt.Sprintf(`{"user": {"name": "%s", "password": "%s", "tenantId": "%s", "email": "%s", "enabled": %t}}`, name, password, tenantId, email, enabled))
	response, err := c.do("POST", c.authUrl+"/users", b)
	if err != nil {
		return nil, err
	}
	defer response.Body.Close()
	result, _ := ioutil.ReadAll(response.Body)
	var data map[string]map[string]interface{}
	_ = json.Unmarshal(result, &data)
	user := User{
		Id:    data["user"]["id"].(string),
		Name:  data["user"]["name"].(string),
		Email: data["user"]["email"].(string),
	}
	err = c.AddRoleToUser(tenantId, user.Id, roleId)
	if err != nil {
		panic(err)
	}
	return &user, nil
}
func ( c * Client ) NewUser ( name , password , email , tenantId , roleId string , enabled bool ) ( * User , error ) { b := bytes . NewBufferString ( fmt . Sprintf ( `{"user": {"name": "%s", "password": "%s", "tenantId": "%s", "email": "%s", "enabled": %t}}` , name , password , tenantId , email , enabled ) ) response , err := c . do ( " " , c . authUrl + " " , b ) if err != nil { return nil , err } defer response . Body . Close ( ) result , _ := ioutil . ReadAll ( response . Body ) var data map [ string ] map [ string ] interface { } _ = json . Unmarshal ( result , & data ) user := User { Id : data [ " " ] [ " " ] . ( string ) , Name : data [ " " ] [ " " ] . ( string ) , Email : data [ " " ] [ " " ] . ( string ) , } err = c . AddRoleToUser ( tenantId , user . Id , roleId ) if err != nil { panic ( err ) } return & user , nil }
NewUser create a new user using the given name, password and email.
NewUser create a new user using the given name password and email .