mirror of https://github.com/matrix-org/gomatrix
Add setOnClient
This commit is contained in:
parent
c72cc1919a
commit
86e5c414aa
11
client.go
11
client.go
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue