user

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const PhoneHoldDuration = 10 * 24 * time.Hour

PhoneHoldDuration is how long a deleted account's phone stays unavailable.

Variables

View Source
var (
	// ErrUserAlreadyExists is returned when username or live phone is taken.
	ErrUserAlreadyExists = errors.New("user already exists")
	// ErrPhoneSame is returned when changing to the current phone number.
	ErrPhoneSame = errors.New("phone number is unchanged")
)

Functions

func ClearAccountPicture

func ClearAccountPicture(userID int) error

ClearAccountPicture clears the picture flag (caller deletes MinIO object).

func ConfirmAccountPicture

func ConfirmAccountPicture(userID int) error

ConfirmAccountPicture marks that users/{id}/account.jpg was uploaded.

func DeleteUser

func DeleteUser(userID int) error

func DemoteFromAdmin

func DemoteFromAdmin(userID int) error

func EncryptName

func EncryptName(userID int,
	name string) (encryptedName, nonce string, err error)

func EncryptPhone

func EncryptPhone(userID int,
	phone string) (encryptedPhone, nonce string, err error)

func Exists

func Exists(id int) bool

Exists checks if a user exists and is not deleted (lightweight check without decryption)

func GetIDByShareToken

func GetIDByShareToken(token string) (int, error)

func IsReachable

func IsReachable(userID int) (bool, error)

IsReachable reports whether the user can be contacted via the platform. Users must verify their phone during registration before they can receive messages. TODO: incorporate notification preferences and SMS opt-out.

func IsTestPhoneE64

func IsTestPhoneE64(phoneE64 string) bool

IsTestPhoneE64 reports whether phoneE64 is a seeded test account.

func IsTestUser

func IsTestUser(userID int) (bool, error)

IsTestUser reports whether userID belongs to a seeded test account.

func PromoteToAdmin

func PromoteToAdmin(userID int) error

func SessionAuth

func SessionAuth(id int) (salt string, isAdmin bool, ok bool)

SessionAuth returns password salt and admin flag for an active user without decryption. ok is false if the user does not exist or is deleted.

func SetAccountPictureURL

func SetAccountPictureURL(userID int, pictureURL string) error

SetAccountPictureURL sets or clears the optional click-through URL.

func SetSMSOptOut

func SetSMSOptOut(userID int, optedOut bool) error

func SetSMSOptOutByPhoneE64

func SetSMSOptOutByPhoneE64(phoneE64 string, optedOut bool) error

SetSMSOptOutByPhoneE64 sets sms_opted_out for the active user with this phone.

func ShareToken

func ShareToken(userID int) (string, error)

func UpdatePassword

func UpdatePassword(userID int, hash, salt, algo string) error

func UpdatePhone

func UpdatePhone(userID int, phoneE64 string) error

UpdatePhone changes a live user's phone after availability checks.

func UsernameTaken

func UsernameTaken(username string) (bool, error)

UsernameTaken reports whether username is reserved, including deleted users.

func ValidShareToken

func ValidShareToken(token string) bool

func WriteCSV added in v0.0.20

func WriteCSV(w io.Writer) (int, error)

WriteCSV writes every user, including deleted accounts. Names and phones are decrypted. password_hash is the stored hash.

Types

type PhoneAvailability

type PhoneAvailability struct {
	Status        PhoneStatus
	DaysRemaining int
}

PhoneAvailability is the result of checking whether a phone can be used.

func CheckPhoneAvailability

func CheckPhoneAvailability(phoneE64 string,
	excludeUserID int) (PhoneAvailability, error)

CheckPhoneAvailability reports whether phoneE64 can be claimed. excludeUserID skips that live user (for change-phone on the same account).

type PhoneHoldError

type PhoneHoldError struct {
	DaysRemaining int
}

PhoneHoldError is returned when a phone is within the post-delete hold.

func (*PhoneHoldError) Error

func (e *PhoneHoldError) Error() string

type PhoneStatus

type PhoneStatus int

PhoneStatus describes whether a phone may be claimed.

const (
	PhoneAvailable PhoneStatus = iota
	PhoneActive
	PhoneHeld
)

type User

type User struct {
	ID                int
	Name              string // Decrypted (calculated field)
	EncryptedName     string
	NameNonce         string
	PasswordHash      string
	PasswordSalt      string
	PasswordAlgo      string
	PhoneE64          string // Decrypted (calculated field)
	EncryptedPhone    string
	PhoneNonce        string
	CreatedAt         time.Time
	IsAdmin           bool
	PhoneVerified     bool
	SMSOptedOut       bool
	HasAccountPicture bool
	AccountPictureURL string
	DeletedAt         *time.Time
}

func CreateUser

func CreateUser(username, phoneE64, plainPassword string) (User, error)

CreateUser creates a new user with phone verification in a transaction. Usernames are reserved forever (including deleted). Phones may be reused after the post-delete hold once no live user holds them.

func GetAllUsers

func GetAllUsers(sortBy string, sortOrder string) ([]User, error)

GetAllUsers returns all users (including deleted) with optional sorting. Phones are not decrypted; use GetByName / GetByID when a phone is needed.

func GetByID

func GetByID(id int) (User, error)

func GetByIDIncludingDeleted

func GetByIDIncludingDeleted(id int) (User, error)

GetByIDIncludingDeleted returns a user by ID, including deleted users

func GetByName

func GetByName(name string) (User, error)

func GetByPhoneE64

func GetByPhoneE64(phoneE64 string) (User, error)

type UserStatus

type UserStatus string

UserStatus represents the status of a user

const (
	StatusActive   UserStatus = "active"
	StatusArchived UserStatus = "archived"
)

Jump to

Keyboard shortcuts

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