mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-29 01:33:10 -06:00
Assemble submit URL
This commit is contained in:
parent
5065e77dd7
commit
863b5eba84
|
|
@ -475,6 +475,14 @@ func (t ThreepidSessionType) Name() string {
|
||||||
}[t]
|
}[t]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t ThreepidSessionType) SubmitPath() string {
|
||||||
|
return [...]string{
|
||||||
|
"/_matrix/client/r0/account/password/email/submitToken",
|
||||||
|
"/_matrix/client/r0/account/3pid/email/submitToken",
|
||||||
|
"/_matrix/client/r0/register/email/submitToken",
|
||||||
|
}[t]
|
||||||
|
}
|
||||||
|
|
||||||
func ThreepidSessionTypes() []ThreepidSessionType {
|
func ThreepidSessionTypes() []ThreepidSessionType {
|
||||||
return []ThreepidSessionType{
|
return []ThreepidSessionType{
|
||||||
AccountPassword,
|
AccountPassword,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
|
|
@ -58,11 +59,22 @@ func (a *UserInternalAPI) CreateSession(ctx context.Context, req *api.CreateSess
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.Sid = s.Sid
|
res.Sid = s.Sid
|
||||||
|
query := url.Values{
|
||||||
|
"sid": []string{s.Sid},
|
||||||
|
"client_secret": []string{s.ClientSecret},
|
||||||
|
"token": []string{s.Token},
|
||||||
|
}
|
||||||
|
link := url.URL{
|
||||||
|
Scheme: "https",
|
||||||
|
Host: string(a.ServerName),
|
||||||
|
Path: req.SessionType.SubmitPath(),
|
||||||
|
RawQuery: query.Encode(),
|
||||||
|
}
|
||||||
// TODO - if we fail sending email, send_attempt for next requests must be bumped,
|
// TODO - if we fail sending email, send_attempt for next requests must be bumped,
|
||||||
// otherwise we will just return nil from this function and not sent email
|
// otherwise we will just return nil from this function and not sent email
|
||||||
return a.Mail.Send(&mail.Mail{
|
return a.Mail.Send(&mail.Mail{
|
||||||
To: s.ThreePid,
|
To: s.ThreePid,
|
||||||
Link: s.NextLink,
|
Link: link.String(),
|
||||||
Token: s.Token,
|
Token: s.Token,
|
||||||
Extra: req.Extra,
|
Extra: req.Extra,
|
||||||
}, req.SessionType)
|
}, req.SessionType)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -238,6 +239,14 @@ func mustCreateSession(is *is.I, i *internal.UserInternalAPI) (resp *api.CreateS
|
||||||
sub := <-mailer.c[api.AccountPassword]
|
sub := <-mailer.c[api.AccountPassword]
|
||||||
is.Equal(len(sub.Token), 64)
|
is.Equal(len(sub.Token), 64)
|
||||||
is.Equal(sub.To, testReq.ThreePid)
|
is.Equal(sub.To, testReq.ThreePid)
|
||||||
|
submitUrl, err := url.Parse(sub.Link)
|
||||||
|
is.NoErr(err)
|
||||||
|
is.Equal(submitUrl.Host, "example.com")
|
||||||
|
is.Equal(submitUrl.Path, "/_matrix/client/r0/account/password/email/submitToken")
|
||||||
|
q := submitUrl.Query()
|
||||||
|
is.Equal(len(q["sid"][0]), 43)
|
||||||
|
is.Equal(q["token"][0], sub.Token)
|
||||||
|
is.Equal(q["client_secret"][0], "foobar")
|
||||||
token = sub.Token
|
token = sub.Token
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue