2020-12-29 01:04:20 +00:00
// Vikunja is a to-do list application to facilitate your life.
2023-09-01 06:32:28 +00:00
// Copyright 2018-present Vikunja and contributors. All rights reserved.
2020-01-26 17:08:06 +00:00
//
2020-12-29 01:04:20 +00:00
// This program is free software: you can redistribute it and/or modify
2020-12-23 15:41:52 +00:00
// it under the terms of the GNU Affero General Public Licensee as published by
2020-01-26 17:08:06 +00:00
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
2020-12-29 01:04:20 +00:00
// This program is distributed in the hope that it will be useful,
2020-01-26 17:08:06 +00:00
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2020-12-23 15:41:52 +00:00
// GNU Affero General Public Licensee for more details.
2020-01-26 17:08:06 +00:00
//
2020-12-23 15:41:52 +00:00
// You should have received a copy of the GNU Affero General Public Licensee
2020-12-29 01:04:20 +00:00
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2020-01-26 17:08:06 +00:00
package user
import (
"fmt"
"net/http"
2020-10-11 20:10:03 +00:00
"code.vikunja.io/web"
2020-01-26 17:08:06 +00:00
)
// =====================
// User Operation Errors
// =====================
// ErrUsernameExists represents a "UsernameAlreadyExists" kind of error.
type ErrUsernameExists struct {
UserID int64
Username string
}
// IsErrUsernameExists checks if an error is a ErrUsernameExists.
func IsErrUsernameExists ( err error ) bool {
_ , ok := err . ( ErrUsernameExists )
return ok
}
func ( err ErrUsernameExists ) Error ( ) string {
return fmt . Sprintf ( "User with that username already exists [user id: %d, username: %s]" , err . UserID , err . Username )
}
// ErrorCodeUsernameExists holds the unique world-error code of this error
const ErrorCodeUsernameExists = 1001
// HTTPError holds the http error description
func ( err ErrUsernameExists ) HTTPError ( ) web . HTTPError {
return web . HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrorCodeUsernameExists , Message : "A user with this username already exists." }
}
// ErrUserEmailExists represents a "UserEmailExists" kind of error.
type ErrUserEmailExists struct {
UserID int64
Email string
}
// IsErrUserEmailExists checks if an error is a ErrUserEmailExists.
func IsErrUserEmailExists ( err error ) bool {
_ , ok := err . ( ErrUserEmailExists )
return ok
}
func ( err ErrUserEmailExists ) Error ( ) string {
return fmt . Sprintf ( "User with that email already exists [user id: %d, email: %s]" , err . UserID , err . Email )
}
// ErrorCodeUserEmailExists holds the unique world-error code of this error
const ErrorCodeUserEmailExists = 1002
// HTTPError holds the http error description
func ( err ErrUserEmailExists ) HTTPError ( ) web . HTTPError {
return web . HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrorCodeUserEmailExists , Message : "A user with this email address already exists." }
}
// ErrNoUsernamePassword represents a "NoUsernamePassword" kind of error.
type ErrNoUsernamePassword struct { }
// IsErrNoUsernamePassword checks if an error is a ErrNoUsernamePassword.
func IsErrNoUsernamePassword ( err error ) bool {
_ , ok := err . ( ErrNoUsernamePassword )
return ok
}
func ( err ErrNoUsernamePassword ) Error ( ) string {
2020-05-29 20:15:21 +00:00
return "No username and password provided"
2020-01-26 17:08:06 +00:00
}
// ErrCodeNoUsernamePassword holds the unique world-error code of this error
const ErrCodeNoUsernamePassword = 1004
// HTTPError holds the http error description
func ( err ErrNoUsernamePassword ) HTTPError ( ) web . HTTPError {
return web . HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrCodeNoUsernamePassword , Message : "Please specify a username and a password." }
}
// ErrUserDoesNotExist represents a "UserDoesNotExist" kind of error.
type ErrUserDoesNotExist struct {
UserID int64
}
// IsErrUserDoesNotExist checks if an error is a ErrUserDoesNotExist.
func IsErrUserDoesNotExist ( err error ) bool {
_ , ok := err . ( ErrUserDoesNotExist )
return ok
}
func ( err ErrUserDoesNotExist ) Error ( ) string {
return fmt . Sprintf ( "User does not exist [user id: %d]" , err . UserID )
}
// ErrCodeUserDoesNotExist holds the unique world-error code of this error
const ErrCodeUserDoesNotExist = 1005
// HTTPError holds the http error description
func ( err ErrUserDoesNotExist ) HTTPError ( ) web . HTTPError {
return web . HTTPError { HTTPCode : http . StatusNotFound , Code : ErrCodeUserDoesNotExist , Message : "The user does not exist." }
}
2020-04-13 21:27:55 +00:00
// ErrCouldNotGetUserID represents a "ErrCouldNotGetuser_id" kind of error.
2020-01-26 17:08:06 +00:00
type ErrCouldNotGetUserID struct { }
// IsErrCouldNotGetUserID checks if an error is a ErrCouldNotGetUserID.
func IsErrCouldNotGetUserID ( err error ) bool {
_ , ok := err . ( ErrCouldNotGetUserID )
return ok
}
func ( err ErrCouldNotGetUserID ) Error ( ) string {
2020-05-29 20:15:21 +00:00
return "Could not get user ID"
2020-01-26 17:08:06 +00:00
}
// ErrCodeCouldNotGetUserID holds the unique world-error code of this error
const ErrCodeCouldNotGetUserID = 1006
// HTTPError holds the http error description
func ( err ErrCouldNotGetUserID ) HTTPError ( ) web . HTTPError {
return web . HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrCodeCouldNotGetUserID , Message : "Could not get user id." }
}
// ErrNoPasswordResetToken represents an error where no password reset token exists for that user
type ErrNoPasswordResetToken struct {
UserID int64
}
func ( err ErrNoPasswordResetToken ) Error ( ) string {
2023-12-03 14:12:43 +00:00
return fmt . Sprintf ( "No token to reset a password [ID: %d]" , err . UserID )
2020-01-26 17:08:06 +00:00
}
// ErrCodeNoPasswordResetToken holds the unique world-error code of this error
const ErrCodeNoPasswordResetToken = 1008
// HTTPError holds the http error description
func ( err ErrNoPasswordResetToken ) HTTPError ( ) web . HTTPError {
return web . HTTPError { HTTPCode : http . StatusPreconditionFailed , Code : ErrCodeNoPasswordResetToken , Message : "No token to reset a user's password provided." }
}
2020-12-30 20:43:14 +00:00
// IsErrNoPasswordResetToken checks if an error is ErrNoPasswordResetToken
func IsErrNoPasswordResetToken ( err error ) bool {
_ , ok := err . ( ErrNoPasswordResetToken )
return ok
}
2020-01-26 17:08:06 +00:00
// ErrInvalidPasswordResetToken is an error where the password reset token is invalid
type ErrInvalidPasswordResetToken struct {
Token string
}
func ( err ErrInvalidPasswordResetToken ) Error ( ) string {
return fmt . Sprintf ( "Invalid token to reset a password [Token: %s]" , err . Token )
}
// ErrCodeInvalidPasswordResetToken holds the unique world-error code of this error
const ErrCodeInvalidPasswordResetToken = 1009
// HTTPError holds the http error description
func ( err ErrInvalidPasswordResetToken ) HTTPError ( ) web . HTTPError {
return web . HTTPError { HTTPCode : http . StatusPreconditionFailed , Code : ErrCodeInvalidPasswordResetToken , Message : "Invalid token to reset a user's password." }
}
// IsErrInvalidPasswordResetToken checks if an error is a ErrInvalidPasswordResetToken.
func IsErrInvalidPasswordResetToken ( err error ) bool {
_ , ok := err . ( ErrInvalidPasswordResetToken )
return ok
}
// ErrInvalidEmailConfirmToken is an error where the email confirm token is invalid
type ErrInvalidEmailConfirmToken struct {
Token string
}
func ( err ErrInvalidEmailConfirmToken ) Error ( ) string {
return fmt . Sprintf ( "Invalid email confirm token [Token: %s]" , err . Token )
}
// ErrCodeInvalidEmailConfirmToken holds the unique world-error code of this error
const ErrCodeInvalidEmailConfirmToken = 1010
// HTTPError holds the http error description
func ( err ErrInvalidEmailConfirmToken ) HTTPError ( ) web . HTTPError {
return web . HTTPError { HTTPCode : http . StatusPreconditionFailed , Code : ErrCodeInvalidEmailConfirmToken , Message : "Invalid email confirm token." }
}
// IsErrInvalidEmailConfirmToken checks if an error is a ErrInvalidEmailConfirmToken.
func IsErrInvalidEmailConfirmToken ( err error ) bool {
_ , ok := err . ( ErrInvalidEmailConfirmToken )
return ok
}
// ErrWrongUsernameOrPassword is an error where the email was not confirmed
type ErrWrongUsernameOrPassword struct {
}
func ( err ErrWrongUsernameOrPassword ) Error ( ) string {
2020-05-29 20:15:21 +00:00
return "Wrong username or password"
2020-01-26 17:08:06 +00:00
}
// ErrCodeWrongUsernameOrPassword holds the unique world-error code of this error
const ErrCodeWrongUsernameOrPassword = 1011
// HTTPError holds the http error description
func ( err ErrWrongUsernameOrPassword ) HTTPError ( ) web . HTTPError {
return web . HTTPError { HTTPCode : http . StatusPreconditionFailed , Code : ErrCodeWrongUsernameOrPassword , Message : "Wrong username or password." }
}
// IsErrWrongUsernameOrPassword checks if an error is a IsErrEmailNotConfirmed.
func IsErrWrongUsernameOrPassword ( err error ) bool {
_ , ok := err . ( ErrWrongUsernameOrPassword )
return ok
}
// ErrEmailNotConfirmed is an error where the email was not confirmed
type ErrEmailNotConfirmed struct {
UserID int64
}
func ( err ErrEmailNotConfirmed ) Error ( ) string {
2023-12-03 14:12:43 +00:00
return fmt . Sprintf ( "Email is not confirmed [ID: %d]" , err . UserID )
2020-01-26 17:08:06 +00:00
}
// ErrCodeEmailNotConfirmed holds the unique world-error code of this error
const ErrCodeEmailNotConfirmed = 1012
// HTTPError holds the http error description
func ( err ErrEmailNotConfirmed ) HTTPError ( ) web . HTTPError {
return web . HTTPError { HTTPCode : http . StatusPreconditionFailed , Code : ErrCodeEmailNotConfirmed , Message : "Please confirm your email address." }
}
// IsErrEmailNotConfirmed checks if an error is a IsErrEmailNotConfirmed.
func IsErrEmailNotConfirmed ( err error ) bool {
_ , ok := err . ( ErrEmailNotConfirmed )
return ok
}
// ErrEmptyNewPassword represents a "EmptyNewPassword" kind of error.
type ErrEmptyNewPassword struct { }
// IsErrEmptyNewPassword checks if an error is a ErrEmptyNewPassword.
func IsErrEmptyNewPassword ( err error ) bool {
_ , ok := err . ( ErrEmptyNewPassword )
return ok
}
func ( err ErrEmptyNewPassword ) Error ( ) string {
2020-05-29 20:15:21 +00:00
return "New password is empty"
2020-01-26 17:08:06 +00:00
}
// ErrCodeEmptyNewPassword holds the unique world-error code of this error
const ErrCodeEmptyNewPassword = 1013
// HTTPError holds the http error description
func ( err ErrEmptyNewPassword ) HTTPError ( ) web . HTTPError {
return web . HTTPError { HTTPCode : http . StatusPreconditionFailed , Code : ErrCodeEmptyNewPassword , Message : "Please specify new password." }
}
// ErrEmptyOldPassword represents a "EmptyOldPassword" kind of error.
type ErrEmptyOldPassword struct { }
// IsErrEmptyOldPassword checks if an error is a ErrEmptyOldPassword.
func IsErrEmptyOldPassword ( err error ) bool {
_ , ok := err . ( ErrEmptyOldPassword )
return ok
}
func ( err ErrEmptyOldPassword ) Error ( ) string {
2020-05-29 20:15:21 +00:00
return "Old password is empty"
2020-01-26 17:08:06 +00:00
}
// ErrCodeEmptyOldPassword holds the unique world-error code of this error
const ErrCodeEmptyOldPassword = 1014
// HTTPError holds the http error description
func ( err ErrEmptyOldPassword ) HTTPError ( ) web . HTTPError {
return web . HTTPError { HTTPCode : http . StatusPreconditionFailed , Code : ErrCodeEmptyOldPassword , Message : "Please specify old password." }
}
2020-04-17 19:25:35 +00:00
// ErrTOTPAlreadyEnabled represents a "TOTPAlreadyEnabled" kind of error.
type ErrTOTPAlreadyEnabled struct { }
// IsErrTOTPAlreadyEnabled checks if an error is a ErrTOTPAlreadyEnabled.
func IsErrTOTPAlreadyEnabled ( err error ) bool {
_ , ok := err . ( ErrTOTPAlreadyEnabled )
return ok
}
func ( err ErrTOTPAlreadyEnabled ) Error ( ) string {
2020-05-29 20:15:21 +00:00
return "Totp is already enabled for this user"
2020-04-17 19:25:35 +00:00
}
// ErrCodeTOTPAlreadyEnabled holds the unique world-error code of this error
const ErrCodeTOTPAlreadyEnabled = 1015
// HTTPError holds the http error description
func ( err ErrTOTPAlreadyEnabled ) HTTPError ( ) web . HTTPError {
return web . HTTPError {
HTTPCode : http . StatusPreconditionFailed ,
Code : ErrCodeTOTPAlreadyEnabled ,
Message : "Totp is already enabled for this user, but not activated." ,
}
}
// ErrTOTPNotEnabled represents a "TOTPNotEnabled" kind of error.
type ErrTOTPNotEnabled struct { }
// IsErrTOTPNotEnabled checks if an error is a ErrTOTPNotEnabled.
func IsErrTOTPNotEnabled ( err error ) bool {
_ , ok := err . ( ErrTOTPNotEnabled )
return ok
}
func ( err ErrTOTPNotEnabled ) Error ( ) string {
2020-05-29 20:15:21 +00:00
return "Totp is not enabled for this user"
2020-04-17 19:25:35 +00:00
}
// ErrCodeTOTPNotEnabled holds the unique world-error code of this error
const ErrCodeTOTPNotEnabled = 1016
// HTTPError holds the http error description
func ( err ErrTOTPNotEnabled ) HTTPError ( ) web . HTTPError {
return web . HTTPError {
HTTPCode : http . StatusPreconditionFailed ,
Code : ErrCodeTOTPNotEnabled ,
Message : "Totp is not enabled for this user." ,
}
}
// ErrInvalidTOTPPasscode represents a "InvalidTOTPPasscode" kind of error.
type ErrInvalidTOTPPasscode struct {
Passcode string
}
// IsErrInvalidTOTPPasscode checks if an error is a ErrInvalidTOTPPasscode.
func IsErrInvalidTOTPPasscode ( err error ) bool {
_ , ok := err . ( ErrInvalidTOTPPasscode )
return ok
}
func ( err ErrInvalidTOTPPasscode ) Error ( ) string {
2020-05-29 20:15:21 +00:00
return "Invalid totp passcode"
2020-04-17 19:25:35 +00:00
}
// ErrCodeInvalidTOTPPasscode holds the unique world-error code of this error
const ErrCodeInvalidTOTPPasscode = 1017
// HTTPError holds the http error description
func ( err ErrInvalidTOTPPasscode ) HTTPError ( ) web . HTTPError {
return web . HTTPError {
HTTPCode : http . StatusPreconditionFailed ,
Code : ErrCodeInvalidTOTPPasscode ,
Message : "Invalid totp passcode." ,
}
}
2020-08-02 17:16:58 +00:00
// ErrInvalidAvatarProvider represents a "InvalidAvatarProvider" kind of error.
type ErrInvalidAvatarProvider struct {
AvatarProvider string
}
// IsErrInvalidAvatarProvider checks if an error is a ErrInvalidAvatarProvider.
func IsErrInvalidAvatarProvider ( err error ) bool {
_ , ok := err . ( ErrInvalidAvatarProvider )
return ok
}
func ( err ErrInvalidAvatarProvider ) Error ( ) string {
return "Invalid avatar provider"
}
// ErrCodeInvalidAvatarProvider holds the unique world-error code of this error
const ErrCodeInvalidAvatarProvider = 1018
// HTTPError holds the http error description
func ( err ErrInvalidAvatarProvider ) HTTPError ( ) web . HTTPError {
return web . HTTPError {
HTTPCode : http . StatusPreconditionFailed ,
Code : ErrCodeInvalidAvatarProvider ,
Message : "Invalid avatar provider setting. See docs for valid types." ,
}
}
2021-05-16 11:23:10 +00:00
// ErrNoOpenIDEmailProvided represents a "NoEmailProvided" kind of error.
type ErrNoOpenIDEmailProvided struct {
}
// IsErrNoEmailProvided checks if an error is a ErrNoOpenIDEmailProvided.
func IsErrNoEmailProvided ( err error ) bool {
_ , ok := err . ( * ErrNoOpenIDEmailProvided )
return ok
}
func ( err * ErrNoOpenIDEmailProvided ) Error ( ) string {
return "No email provided"
}
// ErrCodeNoOpenIDEmailProvided holds the unique world-error code of this error
const ErrCodeNoOpenIDEmailProvided = 1019
// HTTPError holds the http error description
func ( err * ErrNoOpenIDEmailProvided ) HTTPError ( ) web . HTTPError {
return web . HTTPError {
HTTPCode : http . StatusPreconditionFailed ,
Code : ErrCodeNoOpenIDEmailProvided ,
Message : "No email address available. Please make sure the openid provider publicly provides an email address for your account." ,
}
}
2021-07-29 16:45:22 +00:00
2024-03-02 08:47:10 +00:00
// ErrNoOpenIDEmailProvided represents a "NoEmailProvided" kind of error.
type ErrOpenIDCustomScopeMalformed struct {
}
// IsErrNoEmailProvided checks if an error is a ErrNoOpenIDEmailProvided.
func IsErrOpenIDCustomScopeMalformed ( err error ) bool {
_ , ok := err . ( * ErrOpenIDCustomScopeMalformed )
return ok
}
func ( err * ErrOpenIDCustomScopeMalformed ) Error ( ) string {
return "Custom Scope malformed"
}
// ErrCodeNoOpenIDEmailProvided holds the unique world-error code of this error
const ErrCodeOpenIDCustomScopeMalformed = 1022
// HTTPError holds the http error description
func ( err * ErrOpenIDCustomScopeMalformed ) HTTPError ( ) web . HTTPError {
return web . HTTPError {
HTTPCode : http . StatusPreconditionFailed ,
Code : ErrCodeOpenIDCustomScopeMalformed ,
Message : "The custom scope set by the OIDC provider is malformed. Please make sure the openid provider sets the data correctly for your scope. Check especially to have set an oidcID" ,
}
}
2021-07-29 16:45:22 +00:00
// ErrAccountDisabled represents a "AccountDisabled" kind of error.
type ErrAccountDisabled struct {
UserID int64
}
// IsErrAccountDisabled checks if an error is a ErrAccountDisabled.
func IsErrAccountDisabled ( err error ) bool {
_ , ok := err . ( * ErrAccountDisabled )
return ok
}
func ( err * ErrAccountDisabled ) Error ( ) string {
return "Account is disabled"
}
// ErrCodeAccountDisabled holds the unique world-error code of this error
const ErrCodeAccountDisabled = 1020
// HTTPError holds the http error description
func ( err * ErrAccountDisabled ) HTTPError ( ) web . HTTPError {
return web . HTTPError {
HTTPCode : http . StatusPreconditionFailed ,
Code : ErrCodeAccountDisabled ,
Message : "This account is disabled. Check your emails or ask your administrator." ,
}
}
2022-07-04 16:08:41 +00:00
// ErrAccountIsNotLocal represents a "AccountIsNotLocal" kind of error.
type ErrAccountIsNotLocal struct {
UserID int64
}
// IsErrAccountIsNotLocal checks if an error is a ErrAccountIsNotLocal.
func IsErrAccountIsNotLocal ( err error ) bool {
_ , ok := err . ( * ErrAccountIsNotLocal )
return ok
}
func ( err * ErrAccountIsNotLocal ) Error ( ) string {
return "Account is not local"
}
// ErrCodeAccountIsNotLocal holds the unique world-error code of this error
const ErrCodeAccountIsNotLocal = 1021
// HTTPError holds the http error description
func ( err * ErrAccountIsNotLocal ) HTTPError ( ) web . HTTPError {
return web . HTTPError {
HTTPCode : http . StatusPreconditionFailed ,
Code : ErrCodeAccountIsNotLocal ,
Message : "This account is managed by a third-party authentication provider." ,
}
}
2023-03-12 14:02:34 +00:00
// 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." ,
}
}