diff options
author | Collin Guarino <collin.guarino@gmail.com> | 2016-02-27 13:09:20 -0500 |
---|---|---|
committer | Collin Guarino <collin.guarino@gmail.com> | 2016-02-27 13:09:20 -0500 |
commit | 024cad670bbe1cdefaf184395a4acf0a21fe4ccd (patch) | |
tree | 06c50f93bcd0ff81c0a0c625991a00b232d8427f /bridge.go | |
parent | 5effa9fc725fa60c64e34742b2637cdd458544d2 (diff) |
Major fix for Bridge.CreateUser and change to user management design.
Diffstat (limited to 'bridge.go')
-rw-r--r-- | bridge.go | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -221,19 +221,27 @@ func (bridge *Bridge) Login(username string) error { return nil } -// Bridge.CreateUser posts to ./api on the bridge to create a new whitelisted user. -func (bridge *Bridge) CreateUser(deviceType string) error { +// Bridge.CreateUser adds a new user token on the whitelist. +// The token is the first return value in this function which must +// be used with `Bridge.Login`. You cannot use a plaintext username +// like the argument provided in this function. +// This was done by Philips Hue for security reasons. +func (bridge *Bridge) CreateUser(deviceType string) (string, error) { params := map[string]string{"devicetype": deviceType} body, _, err := bridge.Post("/api", params) if err != nil { - log.Fatal("Error: Unable to create user. ", err) - return err + log.Fatal("Error: Failed to create user. ", err) + return "", err } content := string(body) username := content[strings.LastIndex(content, ":\"")+2 : strings.LastIndex(content, "\"")] + userOut := fmt.Sprintf( + "Created user token '%s'. Use Bridge.Login with this token from now on.", + username) + log.Println(userOut) bridge.Username = username - return nil + return username, nil } // Bridge.DeleteUser deletes a user given its USER KEY, not the string name. |