Documentation
¶
Index ¶
- Variables
- type EmailUnsubscribe
- type EmailVerification
- type RefreshToken
- type User
- type UserOAuthLink
- type UserRepo
- func (r *UserRepo) CheckUserExists(ctx context.Context, name string, role model.Role) (bool, error)
- func (r *UserRepo) CreateEmailUnsubscribe(ctx context.Context, unsubscribe EmailUnsubscribe) error
- func (r *UserRepo) CreateEmailVerification(ctx context.Context, vrf EmailVerification) error
- func (r *UserRepo) CreateRefreshToken(ctx context.Context, refreshToken RefreshToken) error
- func (r *UserRepo) CreateUser(ctx context.Context, user User) error
- func (r *UserRepo) CreateUserOAuthLink(ctx context.Context, link UserOAuthLink) error
- func (r *UserRepo) DeleteExpiredRefreshTokens(ctx context.Context) error
- func (r *UserRepo) DeleteRefreshToken(ctx context.Context, tokenHash string) error
- func (r *UserRepo) DeleteRefreshTokensByUserID(ctx context.Context, userID string) error
- func (r *UserRepo) DeleteUser(ctx context.Context, userID string) error
- func (r *UserRepo) GetEmailVerificationByUserID(ctx context.Context, userID string) (EmailVerification, error)
- func (r *UserRepo) GetRefreshTokenByHash(ctx context.Context, tokenHash string) (RefreshToken, error)
- func (r *UserRepo) GetUserByEmail(ctx context.Context, email string) (User, error)
- func (r *UserRepo) GetUserByID(ctx context.Context, userID string) (user User, err error)
- func (r *UserRepo) GetUserByOAuthLink(ctx context.Context, provider string, oauthID string) (User, error)
- func (r *UserRepo) GetUserByUsername(ctx context.Context, username string) (user User, err error)
- func (r *UserRepo) HasOAuthLink(ctx context.Context, userID string) (bool, error)
- func (r *UserRepo) IsEmailUnsubscribed(ctx context.Context, email string) (bool, error)
- func (r *UserRepo) RunWithTx(ctx context.Context, f func(context.Context) error) error
- func (r *UserRepo) SetEmailVerificationMessageID(ctx context.Context, id string, messageID string) error
- func (r *UserRepo) SetEmailVerificationUsed(ctx context.Context, id string, verified bool) error
- func (r *UserRepo) SetUnsubscribeToken(ctx context.Context, id string, token string) error
- func (r *UserRepo) SetUserEmailVerified(ctx context.Context, userID string) error
- func (r *UserRepo) UpdateUser(ctx context.Context, user User) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is used when a record is not found ErrNotFound = errors.New("not found") // ErrUserExists is used when username/email already exists ErrUserExists = errors.New("user already exists") // ErrOAuthLinkExists is used when a user already has an OAuth link for the same provider ErrOAuthLinkExists = errors.New("oauth link already exists for this provider") )
Functions ¶
This section is empty.
Types ¶
type EmailUnsubscribe ¶
EmailUnsubscribe represents an email unsubscribe record
func NewEmailUnsubscribe ¶
func NewEmailUnsubscribe(email string) EmailUnsubscribe
NewEmailUnsubscribe creates a new email unsubscribe record
type EmailVerification ¶
type EmailVerification struct {
ID string `db:"id"`
UserID string `db:"user_id"`
CodeHash sql.NullString `db:"verification_code"`
MessageID sql.NullString `db:"message_id"`
UnsubscribeToken sql.NullString `db:"unsubscribe_token"`
DateCreated time.Time `db:"date_created"`
}
EmailVerification represents an email verification record
func NewEmailVerification ¶
func NewEmailVerification(userID, codeHash, unsubscribeToken string, createdAt time.Time) EmailVerification
NewEmailVerification creates a new email verification record
func (*EmailVerification) IsExpired ¶
func (ev *EmailVerification) IsExpired() bool
IsExpired checks if the verification code has expired
type RefreshToken ¶
type RefreshToken struct {
ID string `db:"id"`
UserID string `db:"user_id"`
TokenHash string `db:"token_hash"`
ExpiresAt time.Time `db:"expires_at"`
DateCreated time.Time `db:"date_created"`
}
RefreshToken represents a refresh token
func NewRefreshToken ¶
func NewRefreshToken(userID, tokenHash string, expiresAt time.Time) RefreshToken
NewRefreshToken creates a new refresh token
func (*RefreshToken) IsExpired ¶
func (rt *RefreshToken) IsExpired() bool
IsExpired checks if the refresh token has expired
type User ¶
type User struct {
ID string `db:"id"`
Username string `db:"username"`
DisplayName string `db:"name"`
Email sql.NullString `db:"email"`
EmailVerified bool `db:"email_verified"`
PasswordHash []byte `db:"password_hash"`
Role model.Role `db:"role"`
DateCreated time.Time `db:"date_created"`
DateUpdated sql.NullTime `db:"date_updated"`
}
User represents a user
type UserOAuthLink ¶
type UserOAuthLink struct {
UserID string `db:"user_id"`
OAuthProvider string `db:"oauth_provider"`
OAuthID string `db:"oauth_id"`
}
UserOAuthLink represents a link between a user and an OAuth provider
func NewUserOAuthLink ¶
func NewUserOAuthLink(userID, provider, oauthID string) UserOAuthLink
NewUserOAuthLink creates a new user OAuth link
type UserRepo ¶
type UserRepo struct {
// contains filtered or unexported fields
}
UserRepo manages API for user access
func NewUserRepo ¶
NewUserRepo constructs a user Repo
func (*UserRepo) CheckUserExists ¶
CheckUserExists checks whether user with provided name and role exists
func (*UserRepo) CreateEmailUnsubscribe ¶
func (r *UserRepo) CreateEmailUnsubscribe(ctx context.Context, unsubscribe EmailUnsubscribe) error
CreateEmailUnsubscribe creates a new email unsubscribe record
func (*UserRepo) CreateEmailVerification ¶
func (r *UserRepo) CreateEmailVerification(ctx context.Context, vrf EmailVerification) error
CreateEmailVerification creates a new email verification record
func (*UserRepo) CreateRefreshToken ¶
func (r *UserRepo) CreateRefreshToken(ctx context.Context, refreshToken RefreshToken) error
CreateRefreshToken inserts a new refresh token into the database
func (*UserRepo) CreateUser ¶
CreateUser inserts a new user into the database
func (*UserRepo) CreateUserOAuthLink ¶
func (r *UserRepo) CreateUserOAuthLink(ctx context.Context, link UserOAuthLink) error
CreateUserOAuthLink inserts a new user OAuth link, ignoring duplicates for the same provider+oauth_id pair. Returns ErrOAuthLinkExists if the user already has a link for the given provider
func (*UserRepo) DeleteExpiredRefreshTokens ¶
DeleteExpiredRefreshTokens deletes all expired refresh tokens
func (*UserRepo) DeleteRefreshToken ¶
DeleteRefreshToken deletes a refresh token by token hash string
func (*UserRepo) DeleteRefreshTokensByUserID ¶
DeleteRefreshTokensByUserID deletes all refresh tokens for a user
func (*UserRepo) DeleteUser ¶
DeleteUser deletes a user by user id
func (*UserRepo) GetEmailVerificationByUserID ¶
func (r *UserRepo) GetEmailVerificationByUserID(ctx context.Context, userID string) (EmailVerification, error)
GetEmailVerificationByUserID gets email verification by user ID (most recent unused)
func (*UserRepo) GetRefreshTokenByHash ¶
func (r *UserRepo) GetRefreshTokenByHash(ctx context.Context, tokenHash string) (RefreshToken, error)
GetRefreshTokenByHash retrieves a refresh token by token hash string with row-level lock
func (*UserRepo) GetUserByEmail ¶
GetUserByEmail gets user by email address
func (*UserRepo) GetUserByID ¶
GetUserByID returns user by id
func (*UserRepo) GetUserByOAuthLink ¶
func (r *UserRepo) GetUserByOAuthLink(ctx context.Context, provider string, oauthID string) (User, error)
GetUserByOAuthLink returns a user by oauth provider and oauth_id via user_oauth_links table
func (*UserRepo) GetUserByUsername ¶
GetUserByUsername returns user by username
func (*UserRepo) HasOAuthLink ¶
HasOAuthLink checks if a user has any OAuth link
func (*UserRepo) IsEmailUnsubscribed ¶
IsEmailUnsubscribed checks if an email address is unsubscribed
func (*UserRepo) SetEmailVerificationMessageID ¶
func (r *UserRepo) SetEmailVerificationMessageID(ctx context.Context, id string, messageID string) error
SetEmailVerificationMessageID sets the message_id for an email verification record
func (*UserRepo) SetEmailVerificationUsed ¶
SetEmailVerificationUsed sets email verification as used by clearing code hash and optionally setting verified_at
func (*UserRepo) SetUnsubscribeToken ¶
SetUnsubscribeToken sets the unsubscribe token for an email verification record
func (*UserRepo) SetUserEmailVerified ¶
SetUserEmailVerified sets user email as verified