mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 09:23:09 -06:00
User registration return M_USER_IN_USE when username is already taken
This commit is contained in:
parent
c3cb6f8767
commit
1fb3950e6b
|
|
@ -103,6 +103,12 @@ func InvalidUsername(msg string) *MatrixError {
|
|||
return &MatrixError{"M_INVALID_USERNAME", msg}
|
||||
}
|
||||
|
||||
// InvalidUsername is an error returned when the client tries to register an
|
||||
// username that already exists
|
||||
func UserInUse(msg string) *MatrixError {
|
||||
return &MatrixError{"M_USER_IN_USE", msg}
|
||||
}
|
||||
|
||||
// GuestAccessForbidden is an error which is returned when the client is
|
||||
// forbidden from accessing a resource as a guest.
|
||||
func GuestAccessForbidden(msg string) *MatrixError {
|
||||
|
|
|
|||
|
|
@ -457,6 +457,19 @@ func completeRegistration(
|
|||
}
|
||||
}
|
||||
|
||||
avail, err := accountDB.CheckAccountAvailability(ctx, username)
|
||||
if err == nil && avail == false {
|
||||
return util.JSONResponse{
|
||||
Code: 400,
|
||||
JSON: jsonerror.UserInUse("Desired user ID is already taken."),
|
||||
}
|
||||
} else if err != nil {
|
||||
return util.JSONResponse{
|
||||
Code: 500,
|
||||
JSON: jsonerror.Unknown("Failed to check account availability: " + err.Error()),
|
||||
}
|
||||
}
|
||||
|
||||
acc, err := accountDB.CreateAccount(ctx, username, password)
|
||||
if err != nil {
|
||||
return util.JSONResponse{
|
||||
|
|
|
|||
Loading…
Reference in a new issue