user

package
v0.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2024 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const ErrCodeAccountDisabled = 1020

ErrCodeAccountDisabled holds the unique world-error code of this error

View Source
const ErrCodeAccountIsNotLocal = 1021

ErrCodeAccountIsNotLocal holds the unique world-error code of this error

View Source
const ErrCodeCouldNotGetUserID = 1006

ErrCodeCouldNotGetUserID holds the unique world-error code of this error

View Source
const ErrCodeEmailNotConfirmed = 1012

ErrCodeEmailNotConfirmed holds the unique world-error code of this error

View Source
const ErrCodeEmptyNewPassword = 1013

ErrCodeEmptyNewPassword holds the unique world-error code of this error

View Source
const ErrCodeEmptyOldPassword = 1014

ErrCodeEmptyOldPassword holds the unique world-error code of this error

View Source
const ErrCodeInvalidAvatarProvider = 1018

ErrCodeInvalidAvatarProvider holds the unique world-error code of this error

View Source
const ErrCodeInvalidEmailConfirmToken = 1010

ErrCodeInvalidEmailConfirmToken holds the unique world-error code of this error

View Source
const ErrCodeInvalidPasswordResetToken = 1009

ErrCodeInvalidPasswordResetToken holds the unique world-error code of this error

View Source
const ErrCodeInvalidTOTPPasscode = 1017

ErrCodeInvalidTOTPPasscode holds the unique world-error code of this error

View Source
const ErrCodeNoOpenIDEmailProvided = 1019

ErrCodeNoOpenIDEmailProvided holds the unique world-error code of this error

View Source
const ErrCodeNoPasswordResetToken = 1008

ErrCodeNoPasswordResetToken holds the unique world-error code of this error

View Source
const ErrCodeNoUsernamePassword = 1004

ErrCodeNoUsernamePassword holds the unique world-error code of this error

View Source
const ErrCodeTOTPAlreadyEnabled = 1015

ErrCodeTOTPAlreadyEnabled holds the unique world-error code of this error

View Source
const ErrCodeTOTPNotEnabled = 1016

ErrCodeTOTPNotEnabled holds the unique world-error code of this error

View Source
const ErrCodeUserDoesNotExist = 1005

ErrCodeUserDoesNotExist holds the unique world-error code of this error

View Source
const ErrCodeUsernameMustNotContainSpaces = 1022

ErrCodeUsernameMustNotContainSpaces holds the unique world-error code of this error

View Source
const ErrCodeWrongUsernameOrPassword = 1011

ErrCodeWrongUsernameOrPassword holds the unique world-error code of this error

View Source
const ErrorCodeUserEmailExists = 1002

ErrorCodeUserEmailExists holds the unique world-error code of this error

View Source
const ErrorCodeUsernameExists = 1001

ErrorCodeUsernameExists holds the unique world-error code of this error

View Source
const IssuerLocal = `local`

Variables

This section is empty.

Functions

func CancelDeletion added in v0.18.0

func CancelDeletion(s *xorm.Session, user *User) (err error)

CancelDeletion cancels the deletion of a user

func CheckUserPassword

func CheckUserPassword(user *User, password string) error

CheckUserPassword checks and verifies a user's password. The user object needs to contain the hashed password from the database.

func ConfirmDeletion added in v0.18.0

func ConfirmDeletion(s *xorm.Session, user *User, token string) (err error)

ConfirmDeletion ConformDeletion checks a token and schedules the user for deletion

func ConfirmEmail

func ConfirmEmail(s *xorm.Session, c *EmailConfirm) (err error)

ConfirmEmail handles the confirmation of an email address

func DeleteCaldavTokenByID added in v0.19.0

func DeleteCaldavTokenByID(u *User, id int64) error

func DisableTOTP

func DisableTOTP(s *xorm.Session, user *User) (err error)

DisableTOTP removes all totp settings for a user.

func EnableTOTP

func EnableTOTP(s *xorm.Session, passcode *TOTPPasscode) (err error)

EnableTOTP enables totp for a user. The provided passcode is used to verify the user has a working totp setup.

func GetTOTPQrCodeForUser

func GetTOTPQrCodeForUser(s *xorm.Session, user *User) (qrcode image.Image, err error)

GetTOTPQrCodeForUser returns a qrcode for a user's totp setting

func GetTables

func GetTables() []interface{}

GetTables returns all structs which are also a table.

func GetUsersByIDs added in v0.16.0

func GetUsersByIDs(s *xorm.Session, userIDs []int64) (users map[int64]*User, err error)

GetUsersByIDs returns a map of users from a slice of user ids

func GetUsersByUsername added in v0.18.0

func GetUsersByUsername(s *xorm.Session, usernames []string, withEmails bool) (users map[int64]*User, err error)

GetUsersByUsername returns a slice of users with the provided usernames

func HandleFailedTOTPAuth added in v0.18.0

func HandleFailedTOTPAuth(s *xorm.Session, user *User)

HandleFailedTOTPAuth handles informing the user of failed TOTP attempts and blocking the account after 10 attempts

func HashPassword added in v0.17.0

func HashPassword(password string) (string, error)

HashPassword hashes a password

func InitTests

func InitTests()

InitTests handles the actual bootstrapping of the test env

func IsErrAccountDisabled added in v0.18.0

func IsErrAccountDisabled(err error) bool

IsErrAccountDisabled checks if an error is a ErrAccountDisabled.

func IsErrAccountIsNotLocal added in v0.19.0

func IsErrAccountIsNotLocal(err error) bool

IsErrAccountIsNotLocal checks if an error is a ErrAccountIsNotLocal.

func IsErrCouldNotGetUserID

func IsErrCouldNotGetUserID(err error) bool

IsErrCouldNotGetUserID checks if an error is a ErrCouldNotGetUserID.

func IsErrEmailNotConfirmed

func IsErrEmailNotConfirmed(err error) bool

IsErrEmailNotConfirmed checks if an error is a IsErrEmailNotConfirmed.

func IsErrEmptyNewPassword

func IsErrEmptyNewPassword(err error) bool

IsErrEmptyNewPassword checks if an error is a ErrEmptyNewPassword.

func IsErrEmptyOldPassword

func IsErrEmptyOldPassword(err error) bool

IsErrEmptyOldPassword checks if an error is a ErrEmptyOldPassword.

func IsErrInvalidAvatarProvider added in v0.15.0

func IsErrInvalidAvatarProvider(err error) bool

IsErrInvalidAvatarProvider checks if an error is a ErrInvalidAvatarProvider.

func IsErrInvalidEmailConfirmToken

func IsErrInvalidEmailConfirmToken(err error) bool

IsErrInvalidEmailConfirmToken checks if an error is a ErrInvalidEmailConfirmToken.

func IsErrInvalidPasswordResetToken

func IsErrInvalidPasswordResetToken(err error) bool

IsErrInvalidPasswordResetToken checks if an error is a ErrInvalidPasswordResetToken.

func IsErrInvalidTOTPPasscode

func IsErrInvalidTOTPPasscode(err error) bool

IsErrInvalidTOTPPasscode checks if an error is a ErrInvalidTOTPPasscode.

func IsErrNoEmailProvided added in v0.18.0

func IsErrNoEmailProvided(err error) bool

IsErrNoEmailProvided checks if an error is a ErrNoOpenIDEmailProvided.

func IsErrNoPasswordResetToken added in v0.16.0

func IsErrNoPasswordResetToken(err error) bool

IsErrNoPasswordResetToken checks if an error is ErrNoPasswordResetToken

func IsErrNoUsernamePassword

func IsErrNoUsernamePassword(err error) bool

IsErrNoUsernamePassword checks if an error is a ErrNoUsernamePassword.

func IsErrTOTPAlreadyEnabled

func IsErrTOTPAlreadyEnabled(err error) bool

IsErrTOTPAlreadyEnabled checks if an error is a ErrTOTPAlreadyEnabled.

func IsErrTOTPNotEnabled

func IsErrTOTPNotEnabled(err error) bool

IsErrTOTPNotEnabled checks if an error is a ErrTOTPNotEnabled.

func IsErrUserDoesNotExist

func IsErrUserDoesNotExist(err error) bool

IsErrUserDoesNotExist checks if an error is a ErrUserDoesNotExist.

func IsErrUserEmailExists

func IsErrUserEmailExists(err error) bool

IsErrUserEmailExists checks if an error is a ErrUserEmailExists.

func IsErrUsernameExists

func IsErrUsernameExists(err error) bool

IsErrUsernameExists checks if an error is a ErrUsernameExists.

func IsErrUsernameMustNotContainSpaces added in v0.21.0

func IsErrUsernameMustNotContainSpaces(err error) bool

IsErrUsernameMustNotContainSpaces checks if an error is a ErrUsernameMustNotContainSpaces.

func IsErrWrongUsernameOrPassword

func IsErrWrongUsernameOrPassword(err error) bool

IsErrWrongUsernameOrPassword checks if an error is a IsErrEmailNotConfirmed.

func RegisterDeletionNotificationCron added in v0.18.0

func RegisterDeletionNotificationCron()

func RegisterListeners added in v0.17.0

func RegisterListeners()

func RegisterTokenCleanupCron added in v0.18.0

func RegisterTokenCleanupCron()

RegisterTokenCleanupCron registers a cron function to clean up all password reset tokens older than 24 hours

func RequestDeletion added in v0.18.0

func RequestDeletion(s *xorm.Session, user *User) (err error)

RequestDeletion creates a user deletion confirm token and sends a notification to the user

func RequestUserPasswordResetToken

func RequestUserPasswordResetToken(s *xorm.Session, user *User) (err error)

RequestUserPasswordResetToken sends a user a password reset email.

func RequestUserPasswordResetTokenByEmail added in v0.15.0

func RequestUserPasswordResetTokenByEmail(s *xorm.Session, tr *PasswordTokenRequest) (err error)

RequestUserPasswordResetTokenByEmail inserts a random token to reset a users password into the databsse

func ResetPassword

func ResetPassword(s *xorm.Session, reset *PasswordReset) (err error)

ResetPassword resets a users password

func SetUserStatus added in v0.22.1

func SetUserStatus(s *xorm.Session, user *User, status Status) (err error)

func TOTPEnabledForUser

func TOTPEnabledForUser(s *xorm.Session, user *User) (bool, error)

TOTPEnabledForUser checks if totp is enabled for a user - not if it is activated, use GetTOTPForUser to check that.

func UpdateEmail

func UpdateEmail(s *xorm.Session, update *EmailUpdate) (err error)

UpdateEmail lets a user update their email address

func UpdateUserPassword

func UpdateUserPassword(s *xorm.Session, user *User, newPassword string) (err error)

UpdateUserPassword updates the password of a user

Types

type APIUserPassword

type APIUserPassword struct {
	// The unique, numeric id of this user.
	ID int64 `json:"id"`
	// The user's username. Cannot contain anything that looks like an url or whitespaces.
	Username string `json:"username" valid:"length(3|250),username" minLength:"3" maxLength:"250"`
	// The user's password in clear text. Only used when registering the user.
	Password string `json:"password" valid:"length(8|250)" minLength:"8" maxLength:"250"`
	// The user's email address
	Email string `json:"email" valid:"email,length(0|250)" maxLength:"250"`
}

APIUserPassword represents a user object without timestamps and a json password field.

func (*APIUserPassword) APIFormat

func (apiUser *APIUserPassword) APIFormat() *User

APIFormat formats an API User into a normal user struct

type AccountDeletedNotification added in v0.18.0

type AccountDeletedNotification struct {
	User *User
}

AccountDeletedNotification represents a AccountDeletedNotification notification

func (*AccountDeletedNotification) Name added in v0.18.0

Name returns the name of the notification

func (*AccountDeletedNotification) ToDB added in v0.18.0

func (n *AccountDeletedNotification) ToDB() interface{}

ToDB returns the AccountDeletedNotification notification in a format which can be saved in the db

func (*AccountDeletedNotification) ToMail added in v0.18.0

ToMail returns the mail notification for AccountDeletedNotification

type AccountDeletionConfirmNotification added in v0.18.0

type AccountDeletionConfirmNotification struct {
	User         *User
	ConfirmToken string
}

AccountDeletionConfirmNotification represents a AccountDeletionConfirmNotification notification

func (*AccountDeletionConfirmNotification) Name added in v0.18.0

Name returns the name of the notification

func (*AccountDeletionConfirmNotification) ToDB added in v0.18.0

func (n *AccountDeletionConfirmNotification) ToDB() interface{}

ToDB returns the AccountDeletionConfirmNotification notification in a format which can be saved in the db

func (*AccountDeletionConfirmNotification) ToMail added in v0.18.0

ToMail returns the mail notification for AccountDeletionConfirmNotification

type AccountDeletionNotification added in v0.18.0

type AccountDeletionNotification struct {
	User               *User
	NotificationNumber int
}

AccountDeletionNotification represents a AccountDeletionNotification notification

func (*AccountDeletionNotification) Name added in v0.18.0

Name returns the name of the notification

func (*AccountDeletionNotification) ToDB added in v0.18.0

func (n *AccountDeletionNotification) ToDB() interface{}

ToDB returns the AccountDeletionNotification notification in a format which can be saved in the db

func (*AccountDeletionNotification) ToMail added in v0.18.0

ToMail returns the mail notification for AccountDeletionNotification

type CreatedEvent added in v0.17.0

type CreatedEvent struct {
	User *User
}

CreatedEvent represents a CreatedEvent event

func (*CreatedEvent) Name added in v0.17.0

func (t *CreatedEvent) Name() string

Name defines the name for CreatedEvent

type EmailConfirm

type EmailConfirm struct {
	// The email confirm token sent via email.
	Token string `json:"token"`
}

EmailConfirm holds the token to confirm a mail address

type EmailConfirmNotification added in v0.17.0

type EmailConfirmNotification struct {
	User         *User
	IsNew        bool
	ConfirmToken string
}

EmailConfirmNotification represents a EmailConfirmNotification notification

func (*EmailConfirmNotification) Name added in v0.17.0

func (n *EmailConfirmNotification) Name() string

Name returns the name of the notification

func (*EmailConfirmNotification) ToDB added in v0.17.0

func (n *EmailConfirmNotification) ToDB() interface{}

ToDB returns the EmailConfirmNotification notification in a format which can be saved in the db

func (*EmailConfirmNotification) ToMail added in v0.17.0

ToMail returns the mail notification for EmailConfirmNotification

type EmailUpdate

type EmailUpdate struct {
	User *User `json:"-"`
	// The new email address. Needs to be a valid email address.
	NewEmail string `json:"new_email" valid:"email,length(0|250),required"`
	// The password of the user for confirmation.
	Password string `json:"password"`
}

EmailUpdate is the data structure to update a user's email address

type ErrAccountDisabled added in v0.18.0

type ErrAccountDisabled struct {
	UserID int64
}

ErrAccountDisabled represents a "AccountDisabled" kind of error.

func (*ErrAccountDisabled) Error added in v0.18.0

func (err *ErrAccountDisabled) Error() string

func (*ErrAccountDisabled) HTTPError added in v0.18.0

func (err *ErrAccountDisabled) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrAccountIsNotLocal added in v0.19.0

type ErrAccountIsNotLocal struct {
	UserID int64
}

ErrAccountIsNotLocal represents a "AccountIsNotLocal" kind of error.

func (*ErrAccountIsNotLocal) Error added in v0.19.0

func (err *ErrAccountIsNotLocal) Error() string

func (*ErrAccountIsNotLocal) HTTPError added in v0.19.0

func (err *ErrAccountIsNotLocal) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrCouldNotGetUserID

type ErrCouldNotGetUserID struct{}

ErrCouldNotGetUserID represents a "ErrCouldNotGetuser_id" kind of error.

func (ErrCouldNotGetUserID) Error

func (err ErrCouldNotGetUserID) Error() string

func (ErrCouldNotGetUserID) HTTPError

func (err ErrCouldNotGetUserID) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrEmailNotConfirmed

type ErrEmailNotConfirmed struct {
	UserID int64
}

ErrEmailNotConfirmed is an error where the email was not confirmed

func (ErrEmailNotConfirmed) Error

func (err ErrEmailNotConfirmed) Error() string

func (ErrEmailNotConfirmed) HTTPError

func (err ErrEmailNotConfirmed) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrEmptyNewPassword

type ErrEmptyNewPassword struct{}

ErrEmptyNewPassword represents a "EmptyNewPassword" kind of error.

func (ErrEmptyNewPassword) Error

func (err ErrEmptyNewPassword) Error() string

func (ErrEmptyNewPassword) HTTPError

func (err ErrEmptyNewPassword) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrEmptyOldPassword

type ErrEmptyOldPassword struct{}

ErrEmptyOldPassword represents a "EmptyOldPassword" kind of error.

func (ErrEmptyOldPassword) Error

func (err ErrEmptyOldPassword) Error() string

func (ErrEmptyOldPassword) HTTPError

func (err ErrEmptyOldPassword) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrInvalidAvatarProvider added in v0.15.0

type ErrInvalidAvatarProvider struct {
	AvatarProvider string
}

ErrInvalidAvatarProvider represents a "InvalidAvatarProvider" kind of error.

func (ErrInvalidAvatarProvider) Error added in v0.15.0

func (err ErrInvalidAvatarProvider) Error() string

func (ErrInvalidAvatarProvider) HTTPError added in v0.15.0

func (err ErrInvalidAvatarProvider) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrInvalidEmailConfirmToken

type ErrInvalidEmailConfirmToken struct {
	Token string
}

ErrInvalidEmailConfirmToken is an error where the email confirm token is invalid

func (ErrInvalidEmailConfirmToken) Error

func (err ErrInvalidEmailConfirmToken) Error() string

func (ErrInvalidEmailConfirmToken) HTTPError

func (err ErrInvalidEmailConfirmToken) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrInvalidPasswordResetToken

type ErrInvalidPasswordResetToken struct {
	Token string
}

ErrInvalidPasswordResetToken is an error where the password reset token is invalid

func (ErrInvalidPasswordResetToken) Error

func (ErrInvalidPasswordResetToken) HTTPError

func (err ErrInvalidPasswordResetToken) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrInvalidTOTPPasscode

type ErrInvalidTOTPPasscode struct {
	Passcode string
}

ErrInvalidTOTPPasscode represents a "InvalidTOTPPasscode" kind of error.

func (ErrInvalidTOTPPasscode) Error

func (err ErrInvalidTOTPPasscode) Error() string

func (ErrInvalidTOTPPasscode) HTTPError

func (err ErrInvalidTOTPPasscode) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrNoOpenIDEmailProvided added in v0.18.0

type ErrNoOpenIDEmailProvided struct {
}

ErrNoOpenIDEmailProvided represents a "NoEmailProvided" kind of error.

func (*ErrNoOpenIDEmailProvided) Error added in v0.18.0

func (err *ErrNoOpenIDEmailProvided) Error() string

func (*ErrNoOpenIDEmailProvided) HTTPError added in v0.18.0

func (err *ErrNoOpenIDEmailProvided) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrNoPasswordResetToken

type ErrNoPasswordResetToken struct {
	UserID int64
}

ErrNoPasswordResetToken represents an error where no password reset token exists for that user

func (ErrNoPasswordResetToken) Error

func (err ErrNoPasswordResetToken) Error() string

func (ErrNoPasswordResetToken) HTTPError

func (err ErrNoPasswordResetToken) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrNoUsernamePassword

type ErrNoUsernamePassword struct{}

ErrNoUsernamePassword represents a "NoUsernamePassword" kind of error.

func (ErrNoUsernamePassword) Error

func (err ErrNoUsernamePassword) Error() string

func (ErrNoUsernamePassword) HTTPError

func (err ErrNoUsernamePassword) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrTOTPAlreadyEnabled

type ErrTOTPAlreadyEnabled struct{}

ErrTOTPAlreadyEnabled represents a "TOTPAlreadyEnabled" kind of error.

func (ErrTOTPAlreadyEnabled) Error

func (err ErrTOTPAlreadyEnabled) Error() string

func (ErrTOTPAlreadyEnabled) HTTPError

func (err ErrTOTPAlreadyEnabled) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrTOTPNotEnabled

type ErrTOTPNotEnabled struct{}

ErrTOTPNotEnabled represents a "TOTPNotEnabled" kind of error.

func (ErrTOTPNotEnabled) Error

func (err ErrTOTPNotEnabled) Error() string

func (ErrTOTPNotEnabled) HTTPError

func (err ErrTOTPNotEnabled) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrUserDoesNotExist

type ErrUserDoesNotExist struct {
	UserID int64
}

ErrUserDoesNotExist represents a "UserDoesNotExist" kind of error.

func (ErrUserDoesNotExist) Error

func (err ErrUserDoesNotExist) Error() string

func (ErrUserDoesNotExist) HTTPError

func (err ErrUserDoesNotExist) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrUserEmailExists

type ErrUserEmailExists struct {
	UserID int64
	Email  string
}

ErrUserEmailExists represents a "UserEmailExists" kind of error.

func (ErrUserEmailExists) Error

func (err ErrUserEmailExists) Error() string

func (ErrUserEmailExists) HTTPError

func (err ErrUserEmailExists) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrUsernameExists

type ErrUsernameExists struct {
	UserID   int64
	Username string
}

ErrUsernameExists represents a "UsernameAlreadyExists" kind of error.

func (ErrUsernameExists) Error

func (err ErrUsernameExists) Error() string

func (ErrUsernameExists) HTTPError

func (err ErrUsernameExists) HTTPError() web.HTTPError

HTTPError holds the http error description

type ErrUsernameMustNotContainSpaces added in v0.21.0

type ErrUsernameMustNotContainSpaces struct {
	Username string
}

ErrUsernameMustNotContainSpaces represents a "UsernameMustNotContainSpaces" kind of error.

func (*ErrUsernameMustNotContainSpaces) Error added in v0.21.0

func (*ErrUsernameMustNotContainSpaces) HTTPError added in v0.21.0

HTTPError holds the http error description

type ErrWrongUsernameOrPassword

type ErrWrongUsernameOrPassword struct {
}

ErrWrongUsernameOrPassword is an error where the email was not confirmed

func (ErrWrongUsernameOrPassword) Error

func (err ErrWrongUsernameOrPassword) Error() string

func (ErrWrongUsernameOrPassword) HTTPError

func (err ErrWrongUsernameOrPassword) HTTPError() web.HTTPError

HTTPError holds the http error description

type FailedLoginAttemptNotification added in v0.18.0

type FailedLoginAttemptNotification struct {
	User *User
}

FailedLoginAttemptNotification represents a FailedLoginAttemptNotification notification

func (*FailedLoginAttemptNotification) Name added in v0.18.0

Name returns the name of the notification

func (*FailedLoginAttemptNotification) ToDB added in v0.18.0

func (n *FailedLoginAttemptNotification) ToDB() interface{}

ToDB returns the FailedLoginAttemptNotification notification in a format which can be saved in the db

func (*FailedLoginAttemptNotification) ToMail added in v0.18.0

ToMail returns the mail notification for FailedLoginAttemptNotification

type IncreaseUserCounter added in v0.17.0

type IncreaseUserCounter struct {
}

IncreaseUserCounter represents a listener

func (*IncreaseUserCounter) Handle added in v0.17.0

func (s *IncreaseUserCounter) Handle(_ *message.Message) (err error)

Handle is executed when the event IncreaseUserCounter listens on is fired

func (*IncreaseUserCounter) Name added in v0.17.0

func (s *IncreaseUserCounter) Name() string

Name defines the name for the IncreaseUserCounter listener

type InvalidTOTPNotification added in v0.18.0

type InvalidTOTPNotification struct {
	User *User
}

InvalidTOTPNotification represents a InvalidTOTPNotification notification

func (*InvalidTOTPNotification) Name added in v0.18.0

func (n *InvalidTOTPNotification) Name() string

Name returns the name of the notification

func (*InvalidTOTPNotification) ToDB added in v0.18.0

func (n *InvalidTOTPNotification) ToDB() interface{}

ToDB returns the InvalidTOTPNotification notification in a format which can be saved in the db

func (*InvalidTOTPNotification) ToMail added in v0.18.0

ToMail returns the mail notification for InvalidTOTPNotification

type Login

type Login struct {
	// The username used to log in.
	Username string `json:"username"`
	// The password for the user.
	Password string `json:"password"`
	// The totp passcode of a user. Only needs to be provided when enabled.
	TOTPPasscode string `json:"totp_passcode"`
	// If true, the token returned will be valid a lot longer than default. Useful for "remember me" style logins.
	LongToken bool `json:"long_token"`
}

Login Object to recive user credentials in JSON format

type PasswordAccountLockedAfterInvalidTOTOPNotification added in v0.18.0

type PasswordAccountLockedAfterInvalidTOTOPNotification struct {
	User *User
}

PasswordAccountLockedAfterInvalidTOTOPNotification represents a PasswordAccountLockedAfterInvalidTOTOPNotification notification

func (*PasswordAccountLockedAfterInvalidTOTOPNotification) Name added in v0.18.0

Name returns the name of the notification

func (*PasswordAccountLockedAfterInvalidTOTOPNotification) ToDB added in v0.18.0

ToDB returns the PasswordAccountLockedAfterInvalidTOTOPNotification notification in a format which can be saved in the db

func (*PasswordAccountLockedAfterInvalidTOTOPNotification) ToMail added in v0.18.0

ToMail returns the mail notification for PasswordAccountLockedAfterInvalidTOTOPNotification

type PasswordChangedNotification added in v0.17.0

type PasswordChangedNotification struct {
	User *User
}

PasswordChangedNotification represents a PasswordChangedNotification notification

func (*PasswordChangedNotification) Name added in v0.17.0

Name returns the name of the notification

func (*PasswordChangedNotification) ToDB added in v0.17.0

func (n *PasswordChangedNotification) ToDB() interface{}

ToDB returns the PasswordChangedNotification notification in a format which can be saved in the db

func (*PasswordChangedNotification) ToMail added in v0.17.0

ToMail returns the mail notification for PasswordChangedNotification

type PasswordReset

type PasswordReset struct {
	// The previously issued reset token.
	Token string `json:"token"`
	// The new password for this user.
	NewPassword string `json:"new_password"`
}

PasswordReset holds the data to reset a password

type PasswordTokenRequest

type PasswordTokenRequest struct {
	Email string `json:"email" valid:"email,length(0|250)" maxLength:"250"`
}

PasswordTokenRequest defines the request format for password reset resqest

type ProjectUserOpts added in v0.21.0

type ProjectUserOpts struct {
	AdditionalCond              builder.Cond
	ReturnAllIfNoSearchProvided bool
	MatchFuzzily                bool
}

type ResetPasswordNotification added in v0.17.0

type ResetPasswordNotification struct {
	User  *User
	Token *Token
}

ResetPasswordNotification represents a ResetPasswordNotification notification

func (*ResetPasswordNotification) Name added in v0.17.0

Name returns the name of the notification

func (*ResetPasswordNotification) ToDB added in v0.17.0

func (n *ResetPasswordNotification) ToDB() interface{}

ToDB returns the ResetPasswordNotification notification in a format which can be saved in the db

func (*ResetPasswordNotification) ToMail added in v0.17.0

ToMail returns the mail notification for ResetPasswordNotification

type Status added in v0.18.0

type Status int
const (
	StatusActive Status = iota
	StatusEmailConfirmationRequired
	StatusDisabled
)

func (Status) String added in v0.18.0

func (s Status) String() string

type TOTP

type TOTP struct {
	ID     int64  `xorm:"bigint autoincr not null unique pk" json:"-"`
	UserID int64  `xorm:"bigint not null" json:"-"`
	Secret string `xorm:"text not null" json:"secret"`
	// The totp entry will only be enabled after the user verified they have a working totp setup.
	Enabled bool `xorm:"null" json:"enabled"`
	// The totp url used to be able to enroll the user later
	URL string `xorm:"text null" json:"url"`
}

TOTP holds a user's totp setting in the database.

func EnrollTOTP

func EnrollTOTP(s *xorm.Session, user *User) (t *TOTP, err error)

EnrollTOTP creates a new TOTP entry for the user - it does not enable it yet.

func GetTOTPForUser

func GetTOTPForUser(s *xorm.Session, user *User) (t *TOTP, err error)

GetTOTPForUser returns the current state of totp settings for the user.

func ValidateTOTPPasscode

func ValidateTOTPPasscode(s *xorm.Session, passcode *TOTPPasscode) (t *TOTP, err error)

ValidateTOTPPasscode validated totp codes of users.

func (*TOTP) TableName

func (t *TOTP) TableName() string

TableName holds the table name for totp secrets

type TOTPPasscode

type TOTPPasscode struct {
	User     *User  `json:"-"`
	Passcode string `json:"passcode"`
}

TOTPPasscode is used to validate a users totp passcode

type Token added in v0.18.0

type Token struct {
	ID             int64     `xorm:"bigint autoincr not null unique pk" json:"id"`
	UserID         int64     `xorm:"not null" json:"-"`
	Token          string    `xorm:"varchar(450) not null index" json:"-"`
	ClearTextToken string    `xorm:"-" json:"token"`
	Kind           TokenKind `xorm:"not null" json:"-"`
	Created        time.Time `xorm:"created not null" json:"created"`
}

Token is a token a user can use to do things like verify their email or resetting their password

func GenerateNewCaldavToken added in v0.19.0

func GenerateNewCaldavToken(u *User) (token *Token, err error)

func GetCaldavTokens added in v0.19.0

func GetCaldavTokens(u *User) (tokens []*Token, err error)

func (*Token) TableName added in v0.18.0

func (t *Token) TableName() string

TableName returns the real table name for user tokens

type TokenKind added in v0.18.0

type TokenKind int

TokenKind represents a user token kind

const (
	TokenUnknown TokenKind = iota
	TokenPasswordReset
	TokenEmailConfirm
	TokenAccountDeletion
	TokenCaldavAuth
)

type User

type User struct {
	// The unique, numeric id of this user.
	ID int64 `xorm:"bigint autoincr not null unique pk" json:"id"`
	// The full name of the user.
	Name string `xorm:"text null" json:"name"`
	// The username of the user. Is always unique.
	Username string `xorm:"varchar(250) not null unique" json:"username" valid:"length(1|250)" minLength:"1" maxLength:"250"`
	Password string `xorm:"varchar(250) null" json:"-"`
	// The user's email address.
	Email string `xorm:"varchar(250) null" json:"email,omitempty" valid:"email,length(0|250)" maxLength:"250"`

	Status Status `xorm:"default 0" json:"-"`

	AvatarProvider string `xorm:"varchar(255) null" json:"-"`
	AvatarFileID   int64  `xorm:"null" json:"-"`

	// Issuer and Subject contain the issuer and subject from the source the user authenticated with.
	Issuer  string `xorm:"text null" json:"-"`
	Subject string `xorm:"text null" json:"-"`

	EmailRemindersEnabled        bool   `xorm:"bool default true" json:"-"`
	DiscoverableByName           bool   `xorm:"bool default false index" json:"-"`
	DiscoverableByEmail          bool   `xorm:"bool default false index" json:"-"`
	OverdueTasksRemindersEnabled bool   `xorm:"bool default true index" json:"-"`
	OverdueTasksRemindersTime    string `xorm:"varchar(5) not null default '09:00'" json:"-"`
	DefaultProjectID             int64  `xorm:"bigint null index" json:"-"`
	WeekStart                    int    `xorm:"null" json:"-"`
	Language                     string `xorm:"varchar(50) null" json:"-"`
	Timezone                     string `xorm:"varchar(255) null" json:"-"`

	DeletionScheduledAt      time.Time `xorm:"datetime null" json:"-"`
	DeletionLastReminderSent time.Time `xorm:"datetime null" json:"-"`

	FrontendSettings interface{} `xorm:"json null" json:"-"`

	ExportFileID int64 `xorm:"bigint null" json:"-"`

	// A timestamp when this task was created. You cannot change this value.
	Created time.Time `xorm:"created not null" json:"created"`
	// A timestamp when this task was last updated. You cannot change this value.
	Updated time.Time `xorm:"updated not null" json:"updated"`

	web.Auth `xorm:"-" json:"-"`
}

User holds information about an user

func CheckUserCredentials

func CheckUserCredentials(s *xorm.Session, u *Login) (*User, error)

CheckUserCredentials checks user credentials

func CreateUser

func CreateUser(s *xorm.Session, user *User) (newUser *User, err error)

CreateUser creates a new user and inserts it into the database

func GetCurrentUser

func GetCurrentUser(c echo.Context) (user *User, err error)

GetCurrentUser returns the current user based on its jwt token

func GetCurrentUserFromDB added in v0.18.0

func GetCurrentUserFromDB(s *xorm.Session, c echo.Context) (user *User, err error)

GetCurrentUserFromDB gets a user from jwt claims and returns the full user from the db.

func GetFromAuth

func GetFromAuth(a web.Auth) (*User, error)

GetFromAuth returns a user object from a web.Auth object and returns an error if the underlying type is not a user object

func GetUserByID

func GetUserByID(s *xorm.Session, id int64) (user *User, err error)

GetUserByID gets informations about a user by its ID

func GetUserByUsername

func GetUserByUsername(s *xorm.Session, username string) (user *User, err error)

GetUserByUsername gets a user from its user name. This is an extra function to be able to add an extra error check.

func GetUserFromClaims

func GetUserFromClaims(claims jwt.MapClaims) (user *User, err error)

GetUserFromClaims Returns a new user from jwt claims

func GetUserWithEmail

func GetUserWithEmail(s *xorm.Session, user *User) (userOut *User, err error)

GetUserWithEmail returns a user object with email

func ListAllUsers added in v0.17.0

func ListAllUsers(s *xorm.Session) (users []*User, err error)

ListAllUsers returns all users

func ListUsers

func ListUsers(s *xorm.Session, search string, opts *ProjectUserOpts) (users []*User, err error)

ListUsers returns a list with all users, filtered by an optional search string

func UpdateUser

func UpdateUser(s *xorm.Session, user *User, forceOverride bool) (updatedUser *User, err error)

UpdateUser updates a user

func (*User) GetFailedPasswordAttemptsKey added in v0.18.0

func (u *User) GetFailedPasswordAttemptsKey() string

func (*User) GetFailedTOTPAttemptsKey added in v0.18.0

func (u *User) GetFailedTOTPAttemptsKey() string

func (*User) GetID

func (u *User) GetID() int64

GetID implements the Auth interface

func (*User) GetName added in v0.17.0

func (u *User) GetName() string

GetName returns the name if the user has one and the username otherwise.

func (*User) GetNameAndFromEmail added in v0.17.0

func (u *User) GetNameAndFromEmail() string

GetNameAndFromEmail returns the name and email address for a user. Useful to use in notifications.

func (*User) IsLocalUser added in v0.22.0

func (u *User) IsLocalUser() bool

func (*User) RouteForDB added in v0.17.0

func (u *User) RouteForDB() int64

RouteForDB routes all notifications for a user to their id

func (*User) RouteForMail added in v0.17.0

func (u *User) RouteForMail() (string, error)

RouteForMail routes all notifications for a user to its email address

func (*User) SetStatus added in v0.18.0

func (u *User) SetStatus(s *xorm.Session, status Status) (err error)

SetStatus sets a users status in the database

func (*User) ShouldNotify added in v0.22.0

func (u *User) ShouldNotify() (bool, error)

func (*User) TableName

func (*User) TableName() string

TableName returns the table name for users

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL