Documentation ¶
Index ¶
- Constants
- func AddUser(ctx context.Context, u *User) (err error)
- func CountUsers(ctx context.Context, opts *CountUserFilter) int64
- func CountWrongUserType(ctx context.Context) (int64, error)
- func CreateUser(ctx context.Context, u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err error)
- func DeleteUserRedirect(ctx context.Context, userName string) error
- func DeleteUserSetting(ctx context.Context, userID int64, key string) error
- func FixWrongUserType(ctx context.Context) (int64, error)
- func GetOrderByName() string
- func GetSetting(ctx context.Context, uid int64, key string) (string, error)
- func GetSettings(ctx context.Context, uid int64, keys []string) (map[string]*Setting, error)
- func GetUser(ctx context.Context, user *User) (bool, error)
- func GetUserAllSettings(ctx context.Context, uid int64) (map[string]*Setting, error)
- func GetUserEmailsByNames(ctx context.Context, names []string) []string
- func GetUserNameByID(ctx context.Context, id int64) (string, error)
- func GetUserNamesByIDs(ctx context.Context, ids []int64) ([]string, error)
- func GetUserSalt() (string, error)
- func GetUserSetting(ctx context.Context, userID int64, key string, def ...string) (string, error)
- func IsErrUserNotExist(err error) bool
- func IsErrUserRedirectNotExist(err error) bool
- func IsErrUserSettingIsNotExist(err error) bool
- func IsUsableUsername(name string) error
- func IsUserExist(ctx context.Context, uid int64, name string) (bool, error)
- func LookupUserRedirect(ctx context.Context, userName string) (int64, error)
- func NewUserRedirect(ctx context.Context, ID int64, oldUserName, newUserName string) error
- func SetEmailNotifications(ctx context.Context, u *User, set string) error
- func SetUserSetting(ctx context.Context, userID int64, key, value string) error
- func UpdateUserCols(ctx context.Context, u *User, cols ...string) error
- func UpdateUserDiffViewStyle(ctx context.Context, u *User, style string) error
- func UpdateUserSetting(ctx context.Context, u *User) (err error)
- func UpdateUserTheme(ctx context.Context, u *User, themeName string) error
- func UserPath(userName string) string
- func ValidateUser(u *User, cols ...string) error
- type CountUserFilter
- type CreateUserOverwriteOptions
- type ErrUserNotExist
- type ErrUserRedirectNotExist
- type ErrUserSettingIsNotExist
- type Redirect
- type SearchOrganizationsOptions
- type Setting
- type User
- func GetAllUsers(ctx context.Context) ([]*User, error)
- func GetInactiveUsers(ctx context.Context, olderThan time.Duration) ([]*User, error)
- func GetMaileableUsersByIDs(ctx context.Context, ids []int64, isMention bool) ([]*User, error)
- func GetPossibleUserByID(ctx context.Context, id int64) (*User, error)
- func GetUserByID(ctx context.Context, id int64) (*User, error)
- func GetUserByIDs(ctx context.Context, ids []int64) ([]*User, error)
- func GetUserByName(ctx context.Context, name string) (*User, error)
- func GetUserFollowers(ctx context.Context, u, viewer *User, listOptions db.ListOptions) ([]*User, int64, error)
- func GetUserFollowing(ctx context.Context, u, viewer *User, listOptions db.ListOptions) ([]*User, int64, error)
- func GetUsersBySource(ctx context.Context, s *auth.Source) ([]*User, error)
- func GetVerifyUser(ctx context.Context, code string) (user *User)
- func NewActionsUser() *User
- func NewGhostUser() *User
- func NewReplaceUser(name string) *User
- func VerifyUserActiveCode(ctx context.Context, code string) (user *User)
- func (u *User) AfterLoad()
- func (u *User) BeforeUpdate()
- func (u *User) CanCreateOrganization() bool
- func (u *User) CanCreateRepo() bool
- func (u *User) CanEditGitHook() bool
- func (u *User) CanForkRepo() bool
- func (u *User) CanImportLocal() bool
- func (u *User) DashboardLink() string
- func (u *User) DisplayName() string
- func (u *User) EmailNotifications() string
- func (u *User) GenerateEmailActivateCode(email string) string
- func (u *User) GetDisplayName() string
- func (u *User) GetEmail() string
- func (u *User) GetPlaceholderEmail() string
- func (u *User) GitName() string
- func (u *User) HTMLURL() string
- func (u *User) HomeLink() string
- func (u *User) IsActions() bool
- func (u *User) IsBot() bool
- func (u *User) IsGhost() bool
- func (u *User) IsIndividual() bool
- func (u *User) IsLocal() bool
- func (u *User) IsMailable() bool
- func (u *User) IsOAuth2() bool
- func (u *User) IsOrganization() bool
- func (u *User) IsPasswordSet() bool
- func (u *User) LogString() string
- func (u *User) MaxCreationLimit() int
- func (u *User) OrganisationLink() string
- func (u *User) SetLastLogin()
- func (u *User) SetPassword(passwd string) (err error)
- func (u *User) ShortName(length int) string
- func (u *User) ValidatePassword(passwd string) bool
- type UserType
Constants ¶
const ( // EmailNotificationsEnabled indicates that the user would like to receive all email notifications except your own EmailNotificationsEnabled = "enabled" // EmailNotificationsOnMention indicates that the user would like to be notified via email when mentioned. EmailNotificationsOnMention = "onmention" // EmailNotificationsDisabled indicates that the user would not like to be notified via email. EmailNotificationsDisabled = "disabled" // EmailNotificationsAndYourOwn indicates that the user would like to receive all email notifications and your own EmailNotificationsAndYourOwn = "andyourown" )
const ( ActionsUserID = -2 ActionsUserName = "gitea-actions" ActionsFullName = "Gitea Actions" ActionsEmail = "teabot@gitea.io" )
const SaltByteLength = 16
Note: As of the beginning of 2022, it is recommended to use at least 64 bits of salt, but NIST is already recommending to use to 128 bits. (16 bytes = 16 * 8 = 128 bits)
Variables ¶
This section is empty.
Functions ¶
func CountUsers ¶
func CountUsers(ctx context.Context, opts *CountUserFilter) int64
CountUsers returns number of users.
func CountWrongUserType ¶
CountWrongUserType count OrgUser who have wrong type
func CreateUser ¶
func CreateUser(ctx context.Context, u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err error)
CreateUser creates record of a new user.
func DeleteUserRedirect ¶
DeleteUserRedirect delete any redirect from the specified user name to anything else
func DeleteUserSetting ¶
DeleteUserSetting deletes a specific setting for a user
func FixWrongUserType ¶
FixWrongUserType fix OrgUser who have wrong type
func GetOrderByName ¶
func GetOrderByName() string
func GetSetting ¶
GetSetting returns the setting value via the key
func GetSettings ¶
GetSettings returns specific settings from user
func GetUserAllSettings ¶
GetUserAllSettings returns all settings from user
func GetUserEmailsByNames ¶
GetUserEmailsByNames returns a list of e-mails corresponds to names of users that have their email notifications set to enabled or onmention.
func GetUserNameByID ¶
GetUserNameByID returns username for the id
func GetUserNamesByIDs ¶
GetUserNamesByIDs returns usernames for all resolved users from a list of Ids.
func GetUserSetting ¶
// GetUserSetting gets a specific setting for a user
func LoginAuth(ctx context.Context, userName string, password string) (string, error) { if err := validateUserSettingKey(key); err != nil { return "", err } setting := &Setting{UserID: userID, SettingKey: key} has, err := db.GetEngine(ctx).Get(setting) if err != nil { return "", err } if !has { if len(def) == 1 { return def[0], nil } return "", nil } return setting.SettingValue, nil }
func IsErrUserNotExist ¶
IsErrUserNotExist checks if an error is a ErrUserNotExist.
func IsErrUserRedirectNotExist ¶
IsErrUserRedirectNotExist check if an error is an ErrUserRedirectNotExist.
func IsErrUserSettingIsNotExist ¶
IsErrUserSettingIsNotExist return true if err is ErrSettingIsNotExist
func IsUsableUsername ¶
IsUsableUsername returns an error when a username is reserved
func IsUserExist ¶
IsUserExist checks if given user name exist, the user name should be noncased unique. If uid is presented, then check will rule out that one, it is used when update a user name in settings page.
func LookupUserRedirect ¶
LookupUserRedirect look up userID if a user has a redirect name
func NewUserRedirect ¶
NewUserRedirect create a new user redirect
func SetEmailNotifications ¶
SetEmailNotifications sets the user's email notification preference
func SetUserSetting ¶
SetUserSetting updates a users' setting for a specific key
func UpdateUserCols ¶
UpdateUserCols update user according special columns
func UpdateUserDiffViewStyle ¶
UpdateUserDiffViewStyle updates the users diff view style
func UpdateUserSetting ¶
UpdateUserSetting updates user's settings.
func UpdateUserTheme ¶
UpdateUserTheme updates a users' theme irrespective of the site wide theme
func ValidateUser ¶
// GetUserSalt returns a random user salt token.
func GetUserSalt() (string, error) { rBytes, err := util.CryptoRandomBytes(SaltByteLength) if err != nil { return "", err } // Returns a 32 bytes long string. return hex.EncodeToString(rBytes), nil }
ValidateUser check if user is valid to insert / update into database
Types ¶
type CountUserFilter ¶
type CountUserFilter struct {
LastLoginSince *int64
}
CountUserFilter represent optional filters for CountUsers
type CreateUserOverwriteOptions ¶
type CreateUserOverwriteOptions struct { KeepEmailPrivate util.OptionalBool Visibility *structs.VisibleType AllowCreateOrganization util.OptionalBool EmailNotificationsPreference *string MaxRepoCreation *int Theme *string IsRestricted util.OptionalBool IsActive util.OptionalBool }
CreateUserOverwriteOptions are an optional options who overwrite system defaults on user creation
type ErrUserNotExist ¶
func (ErrUserNotExist) Error ¶
func (err ErrUserNotExist) Error() string
func (ErrUserNotExist) Unwrap ¶
func (err ErrUserNotExist) Unwrap() error
Unwrap unwraps this error as a ErrNotExist error
type ErrUserRedirectNotExist ¶
type ErrUserRedirectNotExist struct {
Name string
}
ErrUserRedirectNotExist represents a "UserRedirectNotExist" kind of error.
func (ErrUserRedirectNotExist) Error ¶
func (err ErrUserRedirectNotExist) Error() string
func (ErrUserRedirectNotExist) Unwrap ¶
func (err ErrUserRedirectNotExist) Unwrap() error
type ErrUserSettingIsNotExist ¶
type ErrUserSettingIsNotExist struct {
Key string
}
ErrUserSettingIsNotExist represents an error that a setting is not exist with special key
func (ErrUserSettingIsNotExist) Error ¶
func (err ErrUserSettingIsNotExist) Error() string
Error implements error
func (ErrUserSettingIsNotExist) Unwrap ¶
func (err ErrUserSettingIsNotExist) Unwrap() error
type Redirect ¶
type Redirect struct { ID int64 `xorm:"pk autoincr"` LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"` RedirectUserID int64 // userID to redirect to }
Redirect represents that a user name should be redirected to another
type SearchOrganizationsOptions ¶
type SearchOrganizationsOptions struct { db.ListOptions All bool }
SearchOrganizationsOptions options to filter organizations
type Setting ¶
type Setting struct { ID int64 `xorm:"pk autoincr"` UserID int64 `xorm:"index unique(key_userid)"` // to load all of someone's settings SettingKey string `xorm:"varchar(255) index unique(key_userid)"` // ensure key is always lowercase SettingValue string `xorm:"text"` }
Setting is a key value store of user settings
func GetSettingNoCache ¶
GetSettingNoCache returns specific setting without using the cache
type User ¶
type User struct { ID int64 `xorm:"pk autoincr"` LowerName string `xorm:"UNIQUE NOT NULL"` Name string `xorm:"UNIQUE NOT NULL"` FullName string // Email is the primary email address (to be used for communication) Email string `xorm:"NOT NULL"` KeepEmailPrivate bool EmailNotificationsPreference string `xorm:"VARCHAR(20) NOT NULL DEFAULT 'enabled'"` Passwd string `xorm:"NOT NULL"` PasswdHashAlgo string `xorm:"NOT NULL DEFAULT 'argon2'"` // MustChangePassword is an attribute that determines if a user // is to change their password after registration. MustChangePassword bool `xorm:"NOT NULL DEFAULT false"` LoginType auth.Type LoginSource int64 `xorm:"NOT NULL DEFAULT 0"` LoginName string Type UserType Location string Website string Rands string `xorm:"VARCHAR(32)"` Salt string `xorm:"VARCHAR(32)"` Language string `xorm:"VARCHAR(5)"` Description string CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` LastLoginUnix timeutil.TimeStamp `xorm:"INDEX"` // Remember visibility choice for convenience, true for private LastRepoVisibility bool // Maximum repository creation limit, -1 means use global default MaxRepoCreation int `xorm:"NOT NULL DEFAULT -1"` // IsActive true: primary email is activated, user can access Web UI and Git SSH. // false: an inactive user can only log in Web UI for account operations (ex: activate the account by email), no other access. IsActive bool `xorm:"INDEX"` // the user is a Gitea admin, who can access all repositories and the admin pages. IsAdmin bool // true: the user is only allowed to see organizations/repositories that they has explicit rights to. // (ex: in private Gitea instances user won't be allowed to see even organizations/repositories that are set as public) IsRestricted bool `xorm:"NOT NULL DEFAULT false"` AllowGitHook bool AllowImportLocal bool // Allow migrate repository by local path AllowCreateOrganization bool `xorm:"DEFAULT true"` // true: the user is not allowed to log in Web UI. Git/SSH access could still be allowed (please refer to Git/SSH access related code/documents) ProhibitLogin bool `xorm:"NOT NULL DEFAULT false"` // Avatar Avatar string `xorm:"VARCHAR(2048) NOT NULL"` AvatarEmail string `xorm:"NOT NULL"` UseCustomAvatar bool // Counters NumFollowers int NumFollowing int `xorm:"NOT NULL DEFAULT 0"` NumStars int NumRepos int // For organization NumTeams int NumMembers int Visibility structs.VisibleType `xorm:"NOT NULL DEFAULT 0"` RepoAdminChangeTeamAccess bool `xorm:"NOT NULL DEFAULT false"` // Preferences DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"` Theme string `xorm:"NOT NULL DEFAULT ''"` KeepActivityPrivate bool `xorm:"NOT NULL DEFAULT false"` }
User represents the object of individual and member of organization.
func GetAllUsers ¶
GetAllUsers returns a slice of all individual users found in DB.
func GetInactiveUsers ¶
GetInactiveUsers gets all inactive users
func GetMaileableUsersByIDs ¶
GetMaileableUsersByIDs gets users from ids, but only if they can receive mails
func GetPossibleUserByID ¶
GetPossibleUserByID returns the user if id > 0 or return system usrs if id < 0
func GetUserByID ¶
GetUserByID returns the user object by given ID if exists.
func GetUserByIDs ¶
GetUserByIDs returns the user objects by given IDs if exists.
func GetUserByName ¶
GetUserByNameCtx returns user by given name.
func GetUserFollowers ¶
func GetUserFollowers(ctx context.Context, u, viewer *User, listOptions db.ListOptions) ([]*User, int64, error)
GetUserFollowers returns range of user's followers.
func GetUserFollowing ¶
func GetUserFollowing(ctx context.Context, u, viewer *User, listOptions db.ListOptions) ([]*User, int64, error)
GetUserFollowing returns range of user's following.
func GetUsersBySource ¶
GetUsersBySource returns a list of Users for a login source
func GetVerifyUser ¶
GetVerifyUser get user by verify code
func NewActionsUser ¶
func NewActionsUser() *User
NewActionsUser creates and returns a fake user for running the actions.
func NewGhostUser ¶
func NewGhostUser() *User
NewGhostUser creates and returns a fake user for someone has deleted their account.
func NewReplaceUser ¶
NewReplaceUser creates and returns a fake user for external user
func VerifyUserActiveCode ¶
VerifyUserActiveCode verifies active code when active account
func (*User) AfterLoad ¶
func (u *User) AfterLoad()
AfterLoad is invoked from XORM after filling all the fields of this object.
func (*User) BeforeUpdate ¶
func (u *User) BeforeUpdate()
BeforeUpdate is invoked from XORM before updating this object.
func (*User) CanCreateOrganization ¶
CanCreateOrganization returns true if user can create organisation.
func (*User) CanCreateRepo ¶
CanCreateRepo returns if user login can create a repository NOTE: functions calling this assume a failure due to repository count limit; if new checks are added, those functions should be revised
func (*User) CanEditGitHook ¶
CanEditGitHook returns true if user can edit Git hooks.
func (*User) CanForkRepo ¶
CanForkRepo returns if user login can fork a repository It checks especially that the user can create repos, and potentially more
func (*User) CanImportLocal ¶
CanImportLocal returns true if user can migrate repository by local path.
func (*User) DashboardLink ¶
DashboardLink returns the user dashboard page link.
func (*User) DisplayName ¶
DisplayName returns full name if it's not empty, returns username otherwise.
func (*User) EmailNotifications ¶
EmailNotifications returns the User's email notification preference
func (*User) GenerateEmailActivateCode ¶
GenerateEmailActivateCode generates an activate code based on user information and given e-mail.
func (*User) GetDisplayName ¶
GetDisplayName returns full name if it's not empty and DEFAULT_SHOW_FULL_NAME is set, returns username otherwise.
func (*User) GetEmail ¶
GetEmail returns an noreply email, if the user has set to keep his email address private, otherwise the primary email address.
func (*User) GetPlaceholderEmail ¶
GetPlaceholderEmail returns an noreply email
func (*User) IsIndividual ¶
IsIndividual returns true if user is actually a individual user.
func (*User) IsMailable ¶
IsMailable checks if a user is eligible to receive emails.
func (*User) IsOrganization ¶
IsOrganization returns true if user is actually a organization.
func (*User) IsPasswordSet ¶
IsPasswordSet checks if the password is set or left empty
func (*User) MaxCreationLimit ¶
MaxCreationLimit returns the number of repositories a user is allowed to create
func (*User) OrganisationLink ¶
OrganisationLink returns the organization sub page link.
func (*User) SetPassword ¶
SetPassword hashes a password using the algorithm defined in the config value of PASSWORD_HASH_ALGO change passwd, salt and passwd_hash_algo fields
func (*User) ValidatePassword ¶
ValidatePassword checks if the given password matches the one belonging to the user.
type UserType ¶
type UserType int //revive:disable-line:exported
UserType defines the user type
const ( // UserTypeIndividual defines an individual user UserTypeIndividual UserType = iota // Historic reason to make it starts at 0. // UserTypeOrganization defines an organization UserTypeOrganization // UserTypeReserved reserves a (non-existing) user, i.e. to prevent a spam user from re-registering after being deleted, or to reserve the name until the user is actually created later on UserTypeUserReserved // UserTypeOrganizationReserved reserves a (non-existing) organization, to be used in combination with UserTypeUserReserved UserTypeOrganizationReserved // UserTypeBot defines a bot user UserTypeBot // UserTypeRemoteUser defines a remote user for federated users UserTypeRemoteUser )