mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-11-22 14:21:55 -06:00
Move ErrUserExists to accounts package
This commit is contained in:
parent
0325ab56fb
commit
be3d4cdacb
|
@ -30,7 +30,6 @@ import (
|
|||
"github.com/matrix-org/dendrite/appservice/workers"
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/basecomponent"
|
||||
"github.com/matrix-org/dendrite/internal/config"
|
||||
"github.com/matrix-org/dendrite/internal/transactions"
|
||||
|
@ -121,7 +120,7 @@ func generateAppServiceAccount(
|
|||
// Create an account for the application service
|
||||
_, err := accountsDB.CreateAccount(ctx, as.SenderLocalpart, "", as.ID)
|
||||
if err != nil {
|
||||
if errors.Is(err, internal.ErrUserExists) { // This account already exists
|
||||
if errors.Is(err, accounts.ErrUserExists) { // This account already exists
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
|
|
|
@ -55,3 +55,6 @@ type Database interface {
|
|||
// Err3PIDInUse is the error returned when trying to save an association involving
|
||||
// a third-party identifier which is already associated to a local user.
|
||||
var Err3PIDInUse = errors.New("This third-party identifier is already in use")
|
||||
|
||||
// ErrUserExists is returned if a username already exists in the database.
|
||||
var ErrUserExists = errors.New("Username already exists")
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"strconv"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
@ -164,7 +165,7 @@ func (d *Database) createAccount(
|
|||
}
|
||||
if err := d.profiles.insertProfile(ctx, txn, localpart); err != nil {
|
||||
if internal.IsUniqueConstraintViolationErr(err) {
|
||||
return nil, internal.ErrUserExists
|
||||
return nil, accounts.ErrUserExists
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
@ -173,7 +174,7 @@ func (d *Database) createAccount(
|
|||
}
|
||||
if err := d.profiles.insertProfile(ctx, txn, localpart); err != nil {
|
||||
if errors.Is(err, sqlite3.ErrConstraint) {
|
||||
return nil, internal.ErrUserExists
|
||||
return nil, accounts.ErrUserExists
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -830,7 +830,7 @@ func completeRegistration(
|
|||
|
||||
acc, err := accountDB.CreateAccount(ctx, username, password, appserviceID)
|
||||
if err != nil {
|
||||
if errors.Is(err, internal.ErrUserExists) { // user already exists
|
||||
if errors.Is(err, accounts.ErrUserExists) { // user already exists
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusBadRequest,
|
||||
JSON: jsonerror.UserInUse("Desired user ID is already taken."),
|
||||
|
|
|
@ -16,15 +16,11 @@ package internal
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ErrUserExists is returned if a username already exists in the database.
|
||||
var ErrUserExists = errors.New("Username already exists")
|
||||
|
||||
// A Transaction is something that can be committed or rolledback.
|
||||
type Transaction interface {
|
||||
// Commit the transaction
|
||||
|
|
Loading…
Reference in a new issue