diff options
author | Ruzette Tanyag <ruzette@users.noreply.github.com> | 2017-02-17 10:31:01 -0500 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-02-17 10:31:01 -0500 |
commit | 4e7dbc3bb0e93bafa684594b19c5648dc030ee17 (patch) | |
tree | 618d2b57861650c52ed4a74ddd7730b944991a11 /model | |
parent | 2f96814a8bca991a2acba3b66c38c22cfddef769 (diff) | |
download | chat-4e7dbc3bb0e93bafa684594b19c5648dc030ee17.tar.gz chat-4e7dbc3bb0e93bafa684594b19c5648dc030ee17.tar.bz2 chat-4e7dbc3bb0e93bafa684594b19c5648dc030ee17.zip |
Implement user sessions endpoints for APIv4 (#5449)
* added get session and revoke session endpoints, unittests and drivers
* removed BasicUser2 and added teardown
* added badrequest unit test case for sessions
* added session loop to check if user id and session user id matches
* fixed indentation issues for user_test
* match indentation from spaces to tabs
Diffstat (limited to 'model')
-rw-r--r-- | model/client4.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/model/client4.go b/model/client4.go index ec91460fd..2534203c2 100644 --- a/model/client4.go +++ b/model/client4.go @@ -403,6 +403,27 @@ func (c *Client4) ResetPassword(code, newPassword string) (bool, *Response) { } } +// GetSessions returns a list of sessions based on the provided user id string. +func (c *Client4) GetSessions(userId, etag string) ([]*Session, *Response) { + if r, err := c.DoApiGet(c.GetUserRoute(userId)+"/sessions", etag); err != nil { + return nil, &Response{StatusCode: r.StatusCode, Error: err} + } else { + defer closeBody(r) + return SessionsFromJson(r.Body), BuildResponse(r) + } +} + +// RevokeSession revokes a user session based on the provided user id and session id strings. +func (c *Client4) RevokeSession(userId, sessionId string) (bool, *Response) { + requestBody := map[string]string{"session_id": sessionId} + if r, err := c.DoApiPost(c.GetUserRoute(userId)+"/sessions/revoke", MapToJson(requestBody)); err != nil { + return false, &Response{StatusCode: r.StatusCode, Error: err} + } else { + defer closeBody(r) + return CheckStatusOK(r), BuildResponse(r) + } +} + // Team Section // CreateTeam creates a team in the system based on the provided team struct. |