Documentation
¶
Index ¶
- Constants
- Variables
- func ClearAccountPicture(userID int) error
- func ConfirmAccountPicture(userID int) error
- func DeleteUser(userID int) error
- func DemoteFromAdmin(userID int) error
- func EncryptName(userID int, name string) (encryptedName, nonce string, err error)
- func EncryptPhone(userID int, phone string) (encryptedPhone, nonce string, err error)
- func Exists(id int) bool
- func GetIDByShareToken(token string) (int, error)
- func IsReachable(userID int) (bool, error)
- func IsTestPhoneE64(phoneE64 string) bool
- func IsTestUser(userID int) (bool, error)
- func PromoteToAdmin(userID int) error
- func SessionAuth(id int) (salt string, isAdmin bool, ok bool)
- func SetAccountPictureURL(userID int, pictureURL string) error
- func SetSMSOptOut(userID int, optedOut bool) error
- func SetSMSOptOutByPhoneE64(phoneE64 string, optedOut bool) error
- func ShareToken(userID int) (string, error)
- func UpdatePassword(userID int, hash, salt, algo string) error
- func UpdatePhone(userID int, phoneE64 string) error
- func UsernameTaken(username string) (bool, error)
- func ValidShareToken(token string) bool
- func WriteCSV(w io.Writer) (int, error)
- type PhoneAvailability
- type PhoneHoldError
- type PhoneStatus
- type User
- func CreateUser(username, phoneE64, plainPassword string) (User, error)
- func GetAllUsers(sortBy string, sortOrder string) ([]User, error)
- func GetByID(id int) (User, error)
- func GetByIDIncludingDeleted(id int) (User, error)
- func GetByName(name string) (User, error)
- func GetByPhoneE64(phoneE64 string) (User, error)
- type UserStatus
Constants ¶
const PhoneHoldDuration = 10 * 24 * time.Hour
PhoneHoldDuration is how long a deleted account's phone stays unavailable.
Variables ¶
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 ¶
ClearAccountPicture clears the picture flag (caller deletes MinIO object).
func ConfirmAccountPicture ¶
ConfirmAccountPicture marks that users/{id}/account.jpg was uploaded.
func DeleteUser ¶
func DemoteFromAdmin ¶
func EncryptName ¶
func EncryptPhone ¶
func Exists ¶
Exists checks if a user exists and is not deleted (lightweight check without decryption)
func GetIDByShareToken ¶
func IsReachable ¶
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 ¶
IsTestPhoneE64 reports whether phoneE64 is a seeded test account.
func IsTestUser ¶
IsTestUser reports whether userID belongs to a seeded test account.
func PromoteToAdmin ¶
func SessionAuth ¶
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 ¶
SetAccountPictureURL sets or clears the optional click-through URL.
func SetSMSOptOut ¶
func SetSMSOptOutByPhoneE64 ¶
SetSMSOptOutByPhoneE64 sets sms_opted_out for the active user with this phone.
func ShareToken ¶
func UpdatePassword ¶
func UpdatePhone ¶
UpdatePhone changes a live user's phone after availability checks.
func UsernameTaken ¶
UsernameTaken reports whether username is reserved, including deleted users.
func ValidShareToken ¶
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 ¶
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 ¶
GetAllUsers returns all users (including deleted) with optional sorting. Phones are not decrypted; use GetByName / GetByID when a phone is needed.
func GetByIDIncludingDeleted ¶
GetByIDIncludingDeleted returns a user by ID, including deleted users
func GetByPhoneE64 ¶
type UserStatus ¶
type UserStatus string
UserStatus represents the status of a user
const ( StatusActive UserStatus = "active" StatusArchived UserStatus = "archived" )