1
0

fix: check if usernames contain spaces when creating a new user

This commit is contained in:
kolaente
2023-03-12 15:02:34 +01:00
parent 1f13b5d7b4
commit 672fb35bcb
4 changed files with 69 additions and 19 deletions

View File

@ -479,3 +479,30 @@ func (err *ErrAccountIsNotLocal) HTTPError() web.HTTPError {
Message: "This account is managed by a third-party authentication provider.",
}
}
// ErrUsernameMustNotContainSpaces represents a "UsernameMustNotContainSpaces" kind of error.
type ErrUsernameMustNotContainSpaces struct {
Username string
}
// IsErrUsernameMustNotContainSpaces checks if an error is a ErrUsernameMustNotContainSpaces.
func IsErrUsernameMustNotContainSpaces(err error) bool {
_, ok := err.(*ErrUsernameMustNotContainSpaces)
return ok
}
func (err *ErrUsernameMustNotContainSpaces) Error() string {
return "username must not contain spaces"
}
// ErrCodeUsernameMustNotContainSpaces holds the unique world-error code of this error
const ErrCodeUsernameMustNotContainSpaces = 1022
// HTTPError holds the http error description
func (err *ErrUsernameMustNotContainSpaces) HTTPError() web.HTTPError {
return web.HTTPError{
HTTPCode: http.StatusPreconditionFailed,
Code: ErrCodeUsernameMustNotContainSpaces,
Message: "The username must not contain spaces.",
}
}