Add setOnClient

This commit is contained in:
Kegan Dougal 2016-12-05 15:05:03 +00:00
parent c72cc1919a
commit 86e5c414aa
1 changed files with 8 additions and 3 deletions

View File

@ -298,17 +298,18 @@ func (cli *Client) RegisterGuest(req *ReqRegister) (*RespRegister, *RespUserInte
// RegisterDummy performs m.login.dummy registration according to https://matrix.org/docs/spec/client_server/r0.2.0.html#dummy-auth // RegisterDummy performs m.login.dummy registration according to https://matrix.org/docs/spec/client_server/r0.2.0.html#dummy-auth
// //
// Only a username and password need to be provided on the ReqRegister struct. Most local/developer homeservers will allow registration // Only a username and password need to be provided on the ReqRegister struct. Most local/developer homeservers will allow registration
// this way. If the homeserver does not, an error is returned. // this way. If the homeserver does not, an error is returned. If "setOnClient" is true, the access_token and user_id will be set on
// this client instance.
// //
// res, err := cli.RegisterDummy(&gomatrix.ReqRegister{ // res, err := cli.RegisterDummy(&gomatrix.ReqRegister{
// Username: "alice", // Username: "alice",
// Password: "wonderland", // Password: "wonderland",
// }) // }, false)
// if err != nil { // if err != nil {
// panic(err) // panic(err)
// } // }
// token := res.AccessToken // token := res.AccessToken
func (cli *Client) RegisterDummy(req *ReqRegister) (*RespRegister, error) { func (cli *Client) RegisterDummy(req *ReqRegister, setOnClient bool) (*RespRegister, error) {
res, uia, err := cli.Register(req) res, uia, err := cli.Register(req)
if err != nil && uia == nil { if err != nil && uia == nil {
return nil, err return nil, err
@ -326,6 +327,10 @@ func (cli *Client) RegisterDummy(req *ReqRegister) (*RespRegister, error) {
if res == nil { if res == nil {
return nil, fmt.Errorf("registration failed: does this server support m.login.dummy?") return nil, fmt.Errorf("registration failed: does this server support m.login.dummy?")
} }
if setOnClient {
cli.UserID = res.UserID
cli.AccessToken = res.AccessToken
}
return res, nil return res, nil
} }