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]
|
||||
}
|
||||
|
||||
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 {
|
||||
return []ThreepidSessionType{
|
||||
AccountPassword,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
|
|
@ -58,11 +59,22 @@ func (a *UserInternalAPI) CreateSession(ctx context.Context, req *api.CreateSess
|
|||
}
|
||||
}
|
||||
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,
|
||||
// otherwise we will just return nil from this function and not sent email
|
||||
return a.Mail.Send(&mail.Mail{
|
||||
To: s.ThreePid,
|
||||
Link: s.NextLink,
|
||||
Link: link.String(),
|
||||
Token: s.Token,
|
||||
Extra: req.Extra,
|
||||
}, req.SessionType)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
|
|
@ -238,6 +239,14 @@ func mustCreateSession(is *is.I, i *internal.UserInternalAPI) (resp *api.CreateS
|
|||
sub := <-mailer.c[api.AccountPassword]
|
||||
is.Equal(len(sub.Token), 64)
|
||||
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
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue