aboutsummaryrefslogtreecommitdiff
path: root/userapi/internal/api.go
diff options
context:
space:
mode:
Diffstat (limited to 'userapi/internal/api.go')
-rw-r--r--userapi/internal/api.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/userapi/internal/api.go b/userapi/internal/api.go
index 6e737b81..1b34dc7b 100644
--- a/userapi/internal/api.go
+++ b/userapi/internal/api.go
@@ -17,6 +17,7 @@ package internal
import (
"context"
"database/sql"
+ "errors"
"fmt"
"github.com/matrix-org/dendrite/appservice/types"
@@ -24,6 +25,7 @@ import (
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
"github.com/matrix-org/dendrite/clientapi/userutil"
"github.com/matrix-org/dendrite/internal/config"
+ "github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
)
@@ -36,6 +38,38 @@ type UserInternalAPI struct {
AppServices []config.ApplicationService
}
+func (a *UserInternalAPI) PerformAccountCreation(ctx context.Context, req *api.PerformAccountCreationRequest, res *api.PerformAccountCreationResponse) error {
+ 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
+ switch req.OnConflict {
+ case api.ConflictUpdate:
+ break
+ case api.ConflictAbort:
+ return &api.ErrorConflict{
+ Message: err.Error(),
+ }
+ }
+ }
+ res.AccountCreated = false
+ res.UserID = fmt.Sprintf("@%s:%s", req.Localpart, a.ServerName)
+ return nil
+ }
+ res.AccountCreated = true
+ res.UserID = acc.UserID
+ return nil
+}
+func (a *UserInternalAPI) PerformDeviceCreation(ctx context.Context, req *api.PerformDeviceCreationRequest, res *api.PerformDeviceCreationResponse) error {
+ dev, err := a.DeviceDB.CreateDevice(ctx, req.Localpart, req.DeviceID, req.AccessToken, req.DeviceDisplayName)
+ if err != nil {
+ return err
+ }
+ res.DeviceCreated = true
+ res.AccessToken = dev.AccessToken
+ res.DeviceID = dev.ID
+ return nil
+}
+
func (a *UserInternalAPI) QueryProfile(ctx context.Context, req *api.QueryProfileRequest, res *api.QueryProfileResponse) error {
local, domain, err := gomatrixserverlib.SplitID('@', req.UserID)
if err != nil {