user

package
v3.1.61 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: MIT, MIT Imports: 41 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// SettingsKeyHiddenCommentTypes is the setting key for hidden comment types
	SettingsKeyHiddenCommentTypes = "issue.hidden_comment_types"
	// SettingsKeyDiffWhitespaceBehavior is the setting key for whitespace behavior of diff
	SettingsKeyDiffWhitespaceBehavior = "diff.whitespace_behaviour"
	// SettingsKeyShowOutdatedComments is the setting key whether or not to show outdated comments in PRs
	SettingsKeyShowOutdatedComments = "comment_code.show_outdated"

	// UserActivityPubPrivPem is user's private key
	UserActivityPubPrivPem = "activitypub.priv_pem"
	// UserActivityPubPubPem is user's public key
	UserActivityPubPubPem = "activitypub.pub_pem"
	// SignupIP is the IP address that the user signed up with
	SignupIP = "signup.ip"
	// SignupUserAgent is the user agent that the user signed up with
	SignupUserAgent = "signup.user_agent"

	SettingsKeyCodeViewShowFileTree = "code_view.show_file_tree"

	SettingsKeyEmailNotificationGiteaActions        = "email_notification.gitea_actions"
	SettingEmailNotificationGiteaActionsAll         = "all"
	SettingEmailNotificationGiteaActionsFailureOnly = "failure-only" // Default for actions email preference
	SettingEmailNotificationGiteaActionsDisabled    = "disabled"
)
View Source
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"
)
View Source
const (
	GhostUserID   int64 = -1
	GhostUserName       = "Ghost"
)
View Source
const (
	ActionsUserID    int64 = -2
	ActionsUserName        = "gitea-actions"
	ActionsUserEmail       = "teabot@gitea.io"
)
View Source
const MaxPinnedRepos = 6

MaxPinnedRepos is the maximum number of repos a user can pin

View Source
const SaltByteLength = 16

SaltByteLength 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

View Source
var (
	ErrBlockOrganization = util.NewInvalidArgumentErrorf("cannot block an organization")
	ErrCanNotBlock       = util.NewInvalidArgumentErrorf("cannot block the user")
	ErrCanNotUnblock     = util.NewInvalidArgumentErrorf("cannot unblock the user")
	ErrBlockedUser       = util.NewPermissionDeniedErrorf("user is blocked")
)
View Source
var AdminUserOrderByMap = map[string]map[string]db.SearchOrderBy{
	"asc": {
		"name":    db.SearchOrderByAlphabetically,
		"created": db.SearchOrderByOldest,
		"updated": db.SearchOrderByLeastUpdated,
		"id":      db.SearchOrderByID,
	},
	"desc": {
		"name":    db.SearchOrderByAlphabeticallyReverse,
		"created": db.SearchOrderByNewest,
		"updated": db.SearchOrderByRecentUpdated,
		"id":      db.SearchOrderByIDReverse,
	},
}

AdminUserOrderByMap represents all possible admin user search orders This should only be used for admin API endpoints as we should not expose "updated" ordering which could expose recent user activity including logins.

Functions

func ActivateEmail

func ActivateEmail(ctx context.Context, email *EmailAddress) error

ActivateEmail activates the email address to given user.

func ActivateUserEmail

func ActivateUserEmail(ctx context.Context, userID int64, email string, activate bool) (err error)

ActivateUserEmail will change the activated state of an email address, either primary or secondary (all in the email_address table)

func AddUserBadge

func AddUserBadge(ctx context.Context, u *User, badge *Badge) error

AddUserBadge adds a badge to a user.

func AddUserBadges

func AddUserBadges(ctx context.Context, u *User, badges []*Badge) error

AddUserBadges adds badges to a user.

func AddUserOpenID

func AddUserOpenID(ctx context.Context, openid *UserOpenID) error

AddUserOpenID adds an pre-verified/normalized OpenID URI to given user. NOTE: make sure openid.URI is normalized already

func AdminCreateUser

func AdminCreateUser(ctx context.Context, u *User, meta *Meta, overwriteDefault ...*CreateUserOverwriteOptions) (err error)

AdminCreateUser is used by admins to manually create users

func BuildCanSeeUserCondition

func BuildCanSeeUserCondition(actor *User) builder.Cond

BuildCanSeeUserCondition creates a condition which can be used to restrict results to users/orgs the actor can see

func ChangeInactivePrimaryEmail

func ChangeInactivePrimaryEmail(ctx context.Context, uid int64, oldEmailAddr, newEmailAddr string) error

ChangeInactivePrimaryEmail replaces the inactive primary email of a given user

func CountPinnedRepos

func CountPinnedRepos(ctx context.Context, userID int64) (int64, error)

CountPinnedRepos returns the count of pinned repos for a user

func CountUsers

func CountUsers(ctx context.Context, opts *CountUserFilter) int64

CountUsers returns number of users.

func CountWrongUserType

func CountWrongUserType(ctx context.Context) (int64, error)

CountWrongUserType count OrgUser who have wrong type

func CreateBadge

func CreateBadge(ctx context.Context, badge *Badge) error

CreateBadge creates a new badge.

func CreateUser

func CreateUser(ctx context.Context, u *User, meta *Meta, overwriteDefault ...*CreateUserOverwriteOptions) (err error)

CreateUser creates record of a new user.

func DeleteBadge

func DeleteBadge(ctx context.Context, badge *Badge) error

DeleteBadge deletes a badge.

func DeletePinnedReposByRepoID

func DeletePinnedReposByRepoID(ctx context.Context, repoID int64) error

DeletePinnedReposByRepoID deletes all pins for a repo (when repo is deleted)

func DeleteUserOpenID

func DeleteUserOpenID(ctx context.Context, openid *UserOpenID) (err error)

DeleteUserOpenID deletes an openid address of given user.

func DeleteUserRedirect

func DeleteUserRedirect(ctx context.Context, userName string) error

DeleteUserRedirect delete any redirect from the specified user name to anything else

func DeleteUserSetting

func DeleteUserSetting(ctx context.Context, userID int64, key string) error

DeleteUserSetting deletes a specific setting for a user

func DisabledFeaturesWithLoginType

func DisabledFeaturesWithLoginType(user *User) *container.Set[string]

DisabledFeaturesWithLoginType returns the set of user features disabled, taking into account the login type of the user if applicable

func EnsureLinkExternalToUser

func EnsureLinkExternalToUser(ctx context.Context, external *ExternalLoginUser) error

EnsureLinkExternalToUser link the external user to the user

func ExistsWithAvatarAtStoragePath

func ExistsWithAvatarAtStoragePath(ctx context.Context, storagePath string) (bool, error)

ExistsWithAvatarAtStoragePath returns true if there is a user with this Avatar

func FixWrongUserType

func FixWrongUserType(ctx context.Context) (int64, error)

FixWrongUserType fix OrgUser who have wrong type

func FollowUser

func FollowUser(ctx context.Context, user, follow *User) (err error)

FollowUser marks someone be another's follower.

func GenerateRandomAvatar

func GenerateRandomAvatar(ctx context.Context, u *User) error

GenerateRandomAvatar generates a random avatar for user.

func GenerateUserTimeLimitCode

func GenerateUserTimeLimitCode(opts *TimeLimitCodeOptions, u *User) string

GenerateUserTimeLimitCode generates a time-limit code based on user information and given e-mail. TODO: need to use cache or db to store it to make sure a code can only be consumed once

func GetActivatedEmailAddresses

func GetActivatedEmailAddresses(ctx context.Context, uid int64) ([]string, error)

func GetExternalLogin

func GetExternalLogin(ctx context.Context, externalLoginUser *ExternalLoginUser) (bool, error)

GetExternalLogin checks if a externalID in loginSourceID scope already exists

func GetOrderByName

func GetOrderByName() string

func GetSetting

func GetSetting(ctx context.Context, uid int64, key string) (string, error)

GetSetting returns the setting value via the key

func GetSettings

func GetSettings(ctx context.Context, uid int64, keys []string) (map[string]*Setting, error)

GetSettings returns specific settings from user

func GetUser

func GetUser(ctx context.Context, user *