diff options
author | Kegsay <kegan@matrix.org> | 2020-06-17 11:22:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-17 11:22:26 +0100 |
commit | a66a3b830c53c223cb939bd010d3769f02f6ccfb (patch) | |
tree | 251b6464d8f8c4fffad106dc18f07203212427fc /userapi/internal/api.go | |
parent | 04c99092a46b2ad0b90645bf6553360b5f1b7da7 (diff) |
Make userapi control account creation entirely (#1139)
This makes a chokepoint with which we can finally fix
'database is locked' errors on sqlite during account creation
Diffstat (limited to 'userapi/internal/api.go')
-rw-r--r-- | userapi/internal/api.go | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/userapi/internal/api.go b/userapi/internal/api.go index 1b34dc7b..3a413166 100644 --- a/userapi/internal/api.go +++ b/userapi/internal/api.go @@ -39,6 +39,15 @@ type UserInternalAPI struct { } func (a *UserInternalAPI) PerformAccountCreation(ctx context.Context, req *api.PerformAccountCreationRequest, res *api.PerformAccountCreationResponse) error { + if req.AccountType == api.AccountTypeGuest { + acc, err := a.AccountDB.CreateGuestAccount(ctx) + if err != nil { + return err + } + res.AccountCreated = true + res.Account = acc + return nil + } acc, err := a.AccountDB.CreateAccount(ctx, req.Localpart, req.Password, req.AppServiceID) if err != nil { if errors.Is(err, sqlutil.ErrUserExists) { // This account already exists @@ -51,12 +60,18 @@ func (a *UserInternalAPI) PerformAccountCreation(ctx context.Context, req *api.P } } } + // account already exists res.AccountCreated = false - res.UserID = fmt.Sprintf("@%s:%s", req.Localpart, a.ServerName) + res.Account = &api.Account{ + AppServiceID: req.AppServiceID, + Localpart: req.Localpart, + ServerName: a.ServerName, + UserID: fmt.Sprintf("@%s:%s", req.Localpart, a.ServerName), + } return nil } res.AccountCreated = true - res.UserID = acc.UserID + res.Account = acc return nil } func (a *UserInternalAPI) PerformDeviceCreation(ctx context.Context, req *api.PerformDeviceCreationRequest, res *api.PerformDeviceCreationResponse) error { @@ -65,8 +80,7 @@ func (a *UserInternalAPI) PerformDeviceCreation(ctx context.Context, req *api.Pe return err } res.DeviceCreated = true - res.AccessToken = dev.AccessToken - res.DeviceID = dev.ID + res.Device = dev return nil } |