account

package
v0.0.0-...-4ffef1b Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxFreeSignInAttempts  = 3
	MaxSignInThrottleDelay = app.SignInThrottleTTL / 2
)
View Source
const (
	SignInMethodNone      = ""
	SignInMethodPassword  = "account.user.sign_in_method.password"
	SignInMethodMagicLink = "account.user.sign_in_method.magic_link"
	SignInMethodGoogle    = "account.user.sign_in_method.google"
	SignInMethodFacebook  = "account.user.sign_in_method.facebook"
)
View Source
const (
	SignUpMethodNone        = ""
	SignUpMethodSystemSetup = "account.user.sign_up_method.system_setup"
	SignUpMethodWebForm     = "account.user.sign_up_method.web_form"
	SignUpMethodMagicLink   = "account.user.sign_up_method.magic_link"
	SignUpMethodGoogle      = "account.user.sign_up_method.google"
	SignUpMethodFacebook    = "account.user.sign_up_method.facebook"
	SignUpMethodInvite      = "account.user.sign_up_method.invite"
)

Variables

View Source
var (
	ErrNotVerified      = i18n.M("account.user.error.not_verified")
	ErrAlreadyVerified  = i18n.M("account.user.error.already_verified")
	ErrNotActivated     = i18n.M("account.user.error.not_activated")
	ErrAlreadyActivated = i18n.M("account.user.error.already_activated")
	ErrSuspended        = i18n.M("account.user.error.is_suspended")
	ErrInvalidPassword  = i18n.M("account.user.error.invalid_password")
)
View Source
var ErrAuth = errors.New("auth")
View Source
var ErrFacebookSignUpDisabled = errors.New("Facebook sign up disabled")
View Source
var ErrGoogleSignUpDisabled = errors.New("Google sign up disabled")
View Source
var ErrMagicLinkSignUpDisabled = errors.New("magic link sign up disabled")
View Source
var ErrSignInThrottled = errors.New("sign in throttled")

Functions

func TestRepo

func TestRepo(ctx context.Context, t *testing.T, newRepo func() ReadWriter)

Types

type ActivateTOTPData

type ActivateTOTPData struct {
	UserID int
}

type ActivateTOTPGuard

type ActivateTOTPGuard interface {
	CanActivateTOTP(userID int) bool
}

type ActivateUserData

type ActivateUserData struct {
	UserID int
}

type ActivateUsersGuard

type ActivateUsersGuard interface {
	CanActivateUsers() bool
}

type Activated

type Activated struct {
	Email       string
	System      string
	Method      string
	HasPassword bool
}

type AlreadySignedUp

type AlreadySignedUp struct {
	Email       string
	System      string
	Method      string
	HasPassword bool
}

type ApproveTOTPResetRequestData

type ApproveTOTPResetRequestData struct {
	UserID int
}

type ChangePasswordData

type ChangePasswordData struct {
	UserID           int
	OldPassword      Password
	NewPassword      Password
	NewPasswordCheck Password
}

type ChangePasswordGuard

type ChangePasswordGuard interface {
	CanChangePassword(userID int) bool
}

type ChangePasswordInput

type ChangePasswordInput struct {
	UserID           int
	OldPassword      string
	NewPassword      string
	NewPasswordCheck string
}

type ChangeRolesData

type ChangeRolesData struct {
	UserID  int
	RoleIDs []int
	Grants  []Permission
	Denials []Permission
}

type ChangeRolesGuard

type ChangeRolesGuard interface {
	CanChangeRoles(userID int) bool
}

type ChangeRolesInput

type ChangeRolesInput struct {
	UserID  int
	RoleIDs []int
	Grants  []string
	Denials []string
}

type ChangeTOTPTelData

type ChangeTOTPTelData struct {
	UserID int
	NewTel Tel
}

type ChangeTOTPTelGuard

type ChangeTOTPTelGuard interface {
	CanChangeTOTPTel(userID int) bool
}

type ChoosePasswordData

type ChoosePasswordData struct {
	UserID           int
	NewPassword      Password
	NewPasswordCheck Password
}

type ChoosePasswordGuard

type ChoosePasswordGuard interface {
	CanChoosePassword(userID int) bool
}

type ChoosePasswordInput

type ChoosePasswordInput struct {
	UserID           int
	NewPassword      string
	NewPasswordCheck string
}

type CreateRoleData

type CreateRoleData struct {
	Name        RoleName
	Description RoleDesc
	Permissions []Permission
}

type CreateRoleGuard

type CreateRoleGuard interface {
	CanCreateRoles() bool
}

type CreateRoleInput

type CreateRoleInput struct {
	Name        string
	Description string
	Permissions []string
}

type DeleteRoleData

type DeleteRoleData struct {
	RoleID int
}

type DeleteRoleGuard

type DeleteRoleGuard interface {
	CanDeleteRoles() bool
}

type DenyTOTPResetRequestData

type DenyTOTPResetRequestData struct {
	UserID int
}

type DisableTOTPData

type DisableTOTPData struct {
	UserID   int
	Password Password
}

type DisableTOTPGuard

type DisableTOTPGuard interface {
	CanDisableTOTP(userID int) bool
}

type Email

type Email string

func NewEmail

func NewEmail(email string) (Email, error)

func (Email) String

func (e Email) String() string

type FacebookSignInBehavior

type FacebookSignInBehavior byte
const (
	FacebookSignInOnly FacebookSignInBehavior = iota
	FacebookAllowSignUp
	FacebookAllowSignUpActivate
)

type GoogleSignInBehavior

type GoogleSignInBehavior byte
const (
	GoogleSignInOnly GoogleSignInBehavior = iota
	GoogleAllowSignUp
	GoogleAllowSignUpActivate
)

type Hasher

type Hasher interface {
	EncodedPasswordHash(password []byte) ([]byte, error)
	CheckPasswordHash(password, encodedHash []byte) (ok, rehash bool, err error)
	CheckDummyPasswordHash() error
}

type InitialUserSignedUp

type InitialUserSignedUp struct {
	Email  string
	System string
	Method string
}

type InviteUserData

type InviteUserData struct {
	Email Email
}

type InviteUserGuard

type InviteUserGuard interface {
	CanInviteUsers() bool
}

type Invited

type Invited struct {
	Email  string
	System string
	Method string
}

type MagicLinkSignInBehavior

type MagicLinkSignInBehavior byte
const (
	MagicLinkSignInOnly MagicLinkSignInBehavior = iota
	MagicLinkAllowSignUp
	MagicLinkAllowSignUpActivate
)

type Password

type Password struct {
	// contains filtered or unexported fields
}

func NewPassword

func NewPassword(password string) (zero Password, _ error)

func (Password) Equal

func (p Password) Equal(rhs Password) bool

func (Password) String

func (p Password) String() string

type PasswordChanged

type PasswordChanged struct {
	Email string
}

type PasswordChosen

type PasswordChosen struct {
	Email string
}

type PasswordReset

type PasswordReset struct {
	Email string
}

type Permission

type Permission string

func NewPermission

func NewPermission(name string) (Permission, error)

func (Permission) String

func (n Permission) String() string

type ReadWriter

type ReadWriter interface {
	Reader
	Writer
}

type Reader

type Reader interface {
	FindRoleByID(ctx context.Context, id int) (*Role, error)

	CountUsers(ctx context.Context) (int, error)
	FindUserByID(ctx context.Context, id int) (*User, error)
	FindUserByEmail(ctx context.Context, email string) (*User, error)

	FindSignInAttemptLogByEmail(ctx context.Context, email string) (*SignInAttemptLog, error)
}

type RecoveryCode

type RecoveryCode string

func NewRandomRecoveryCode

func NewRandomRecoveryCode() (RecoveryCode, error)

func NewRecoveryCode

func NewRecoveryCode(code string) (RecoveryCode, error)

func (RecoveryCode) EqualHash

func (c RecoveryCode) EqualHash(rhs []byte) bool

func (RecoveryCode) String

func (c RecoveryCode) String() string

type RecoveryCodesRegenerated

type RecoveryCodesRegenerated struct {
	Email string
}

type RegenerateRecoveryCodesData

type RegenerateRecoveryCodesData struct {
	UserID int
	TOTP   TOTP
}

type RegenerateRecoveryCodesGuard

type RegenerateRecoveryCodesGuard interface {
	CanRegenerateRecoveryCodes(userID int) bool
}

type RequestTOTPResetData

type RequestTOTPResetData struct {
	Email Email
}

type ResetPasswordData

type ResetPasswordData struct {
	UserID           int
	NewPassword      Password
	NewPasswordCheck Password
}

type ResetPasswordGuard

type ResetPasswordGuard interface {
	CanResetPassword(userID int) bool
}

type ResetPasswordInput

type ResetPasswordInput struct {
	UserID           int
	NewPassword      string
	NewPasswordCheck string
}

type ResetTOTPData

type ResetTOTPData struct {
	UserID   int
	Password Password
}

type ResetTOTPGuard

type ResetTOTPGuard interface {
	CanResetTOTP(userID int) bool
}

type Role

type Role struct {
	aggregate.Root

	ID          int
	Name        string
	Description string
	Permissions []string
}

func NewRole

func NewRole(name RoleName, description RoleDesc, permissions []Permission) *Role

func (*Role) ChangeDescription

func (r *Role) ChangeDescription(description RoleDesc)

func (*Role) ChangeName

func (r *Role) ChangeName(name RoleName)

func (*Role) ChangePermissions

func (r *Role) ChangePermissions(permissions []Permission)

type RoleDesc

type RoleDesc string

func NewRoleDesc

func NewRoleDesc(desc string) (RoleDesc, error)

func (RoleDesc) String

func (d RoleDesc) String() string

type RoleFilter

type RoleFilter struct {
	ID     *int
	UserID *int
	Name   *string
	Search *string

	SortTopID int
	Sorts     []string

	Limit  int
	Offset int
}

type RoleName

type RoleName string

func NewRoleName

func NewRoleName(name string) (RoleName, error)

func (RoleName) String

func (n RoleName) String() string

type RolesChanged

type RolesChanged struct {
	Email string
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(broker event.Broker, repo ReadWriter, hasher Hasher, system string) (*Service, error)

func (*Service) ActivateTOTP

func (s *Service) ActivateTOTP(ctx context.Context, guard ActivateTOTPGuard, userID int) (*User, error)

func (*Service) ActivateTOTPValidate

func (s *Service) ActivateTOTPValidate(guard ActivateTOTPGuard, userID int) (ActivateTOTPData, error)

func (*Service) ActivateUser

func (s *Service) ActivateUser(ctx context.Context, guard ActivateUsersGuard, userID int) (*User, error)

func (*Service) ActivateUserValidate

func (s *Service) ActivateUserValidate(guard ActivateUsersGuard, userID int) (ActivateUserData, error)

func (*Service) ApproveTOTPResetRequest

func (s *Service) ApproveTOTPResetRequest(ctx context.Context, userID int) (*User, error)

func (*Service) ApproveTOTPResetRequestValidate

func (s *Service) ApproveTOTPResetRequestValidate(userID int) (ApproveTOTPResetRequestData, error)

func (*Service) ChangePassword

func (s *Service) ChangePassword(ctx context.Context, guard ChangePasswordGuard, input ChangePasswordInput) (*User, error)

func (*Service) ChangePasswordValidate

func (s *Service) ChangePasswordValidate(guard ChangePasswordGuard, input ChangePasswordInput) (ChangePasswordData, error)

func (*Service) ChangeRoles

func (s *Service) ChangeRoles(ctx context.Context, guard ChangeRolesGuard, input ChangeRolesInput) (*User, error)

func (*Service) ChangeRolesValidate

func (s *Service) ChangeRolesValidate(guard ChangeRolesGuard, input ChangeRolesInput) (ChangeRolesData, error)

func (*Service) ChangeTOTPTel

func (s *Service) ChangeTOTPTel(ctx context.Context, guard ChangeTOTPTelGuard, userID int, newTel string) (*User, error)

func (*Service) ChangeTOTPTelValidate

func (s *Service) ChangeTOTPTelValidate(guard ChangeTOTPTelGuard, userID int, newTel string) (ChangeTOTPTelData, error)

func (*Service) CheckSignInThrottle

func (s *Service) CheckSignInThrottle(attempts int, lastAttemptAt time.Time) error

func (*Service) ChoosePassword

func (s *Service) ChoosePassword(ctx context.Context, guard ChoosePasswordGuard, input ChoosePasswordInput) (*User, error)

func (*Service) ChoosePasswordValidate

func (s *Service) ChoosePasswordValidate(guard ChoosePasswordGuard, input ChoosePasswordInput) (ChoosePasswordData, error)

func (*Service) CreateRole

func (s *Service) CreateRole(ctx context.Context, guard CreateRoleGuard, input CreateRoleInput) (*Role, error)

func (*Service) CreateRoleValidate

func (s *Service) CreateRoleValidate(guard CreateRoleGuard, input CreateRoleInput) (CreateRoleData, error)

func (*Service) DeleteRole

func (s *Service) DeleteRole(ctx context.Context, guard DeleteRoleGuard, roleID int) (*Role, error)

func (*Service) DeleteRoleValidate

func (s *Service) DeleteRoleValidate(guard DeleteRoleGuard, roleID int) (DeleteRoleData, error)

func (*Service) DenyTOTPResetRequest

func (s *Service) DenyTOTPResetRequest(ctx context.Context, userID int) (*User, error)

func (*Service) DenyTOTPResetRequestValidate

func (s *Service) DenyTOTPResetRequestValidate(userID int) (DenyTOTPResetRequestData, error)

func (*Service) DisableTOTP

func (s *Service) DisableTOTP(ctx context.Context, guard DisableTOTPGuard, userID int, password string) (*User, error)

func (*Service) DisableTOTPValidate

func (s *Service) DisableTOTPValidate(guard DisableTOTPGuard, userID int, password string) (DisableTOTPData, error)

func (*Service) InviteUser

func (s *Service) InviteUser(ctx context.Context, guard InviteUserGuard, email string) (*User, error)

func (*Service) InviteUserValidate

func (s *Service) InviteUserValidate(guard InviteUserGuard, email string) (InviteUserData, error)

func (*Service) RegenerateRecoveryCodes

func (s *Service) RegenerateRecoveryCodes(ctx context.Context, guard RegenerateRecoveryCodesGuard, userID int, totp string) (*User, []string, error)

func (*Service) RegenerateRecoveryCodesValidate

func (s *Service) RegenerateRecoveryCodesValidate(guard RegenerateRecoveryCodesGuard, userID int, totp string) (RegenerateRecoveryCodesData, error)

func (*Service) RequestTOTPReset

func (s *Service) RequestTOTPReset(ctx context.Context, email string) (*User, error)

func (*Service) RequestTOTPResetValidate

func (s *Service) RequestTOTPResetValidate(email string) (RequestTOTPResetData, error)

func (*Service) ResetPassword

func (s *Service) ResetPassword(ctx context.Context, guard ResetPasswordGuard, input ResetPasswordInput) (*User, error)

func (*Service) ResetPasswordValidate

func (s *Service) ResetPasswordValidate(guard ResetPasswordGuard, input ResetPasswordInput) (ResetPasswordData, error)

func (*Service) ResetTOTP

func (s *Service) ResetTOTP(ctx context.Context, guard ResetTOTPGuard, userID int, password string) (*User, error)

func (*Service) ResetTOTPValidate

func (s *Service) ResetTOTPValidate(guard ResetTOTPGuard, userID int, password string) (ResetTOTPData, error)

func (*Service) SetupTOTP

func (s *Service) SetupTOTP(ctx context.Context, guard SetupTOTPGuard, userID int) (*User, error)

func (*Service) SetupTOTPValidate

func (s *Service) SetupTOTPValidate(guard SetupTOTPGuard, userID int) (SetupTOTPData, error)

func (*Service) SignInWithFacebook

func (s *Service) SignInWithFacebook(ctx context.Context, email string, behavior FacebookSignInBehavior) (*User, bool, error)

func (*Service) SignInWithFacebookValidate

func (s *Service) SignInWithFacebookValidate(email string) (SignInWithFacebookData, error)

func (*Service) SignInWithGoogle

func (s *Service) SignInWithGoogle(ctx context.Context, email string, behavior GoogleSignInBehavior) (*User, bool, error)

func (*Service) SignInWithGoogleValidate

func (s *Service) SignInWithGoogleValidate(email string) (SignInWithGoogleData, error)
func (s *Service) SignInWithMagicLink(ctx context.Context, email string, behavior MagicLinkSignInBehavior) (*User, bool, error)

func (*Service) SignInWithMagicLinkValidate

func (s *Service) SignInWithMagicLinkValidate(email string) (SignInWithMagicLinkData, error)

func (*Service) SignInWithPassword

func (s *Service) SignInWithPassword(ctx context.Context, email, password string) (*User, error)

func (*Service) SignInWithPasswordValidate

func (s *Service) SignInWithPasswordValidate(email, password string) (SignInWithPasswordData, error)

func (*Service) SignInWithRecoveryCode

func (s *Service) SignInWithRecoveryCode(ctx context.Context, userID int, recoveryCode string) (*User, error)

func (*Service) SignInWithRecoveryCodeValidate

func (s *Service) SignInWithRecoveryCodeValidate(userID int, recoveryCode string) (SignInWithRecoveryCodeData, error)

func (*Service) SignInWithTOTP

func (s *Service) SignInWithTOTP(ctx context.Context, userID int, totp string) (*User, error)

func (*Service) SignInWithTOTPValidate

func (s *Service) SignInWithTOTPValidate(userID int, totp string) (SignInWithTOTPData, error)

func (*Service) SignUp

func (s *Service) SignUp(ctx context.Context, email string) (*User, error)

func (*Service) SignUpInitialUser

func (s *Service) SignUpInitialUser(ctx context.Context, email, password, passwordCheck string, roleIDs []int) (*User, error)

func (*Service) SignUpInitialUserValidate

func (s *Service) SignUpInitialUserValidate(email, password, passwordCheck string, roleIDs []int) (SignUpInitialUserData, error)

func (*Service) SignUpValidate

func (s *Service) SignUpValidate(email string) (SignUpData, error)

func (*Service) SuspendUser

func (s *Service) SuspendUser(ctx context.Context, guard SuspendUsersGuard, userID int, suspendedReason string) (*User, error)

func (*Service) SuspendUserValidate

func (s *Service) SuspendUserValidate(guard SuspendUsersGuard, userID int, suspendedReason string) (SuspendUserData, error)

func (*Service) UnsuspendUser

func (s *Service) UnsuspendUser(ctx context.Context, guard UnsuspendUsersGuard, userID int) (*User, error)

func (*Service) UnsuspendUserValidate

func (s *Service) UnsuspendUserValidate(guard UnsuspendUsersGuard, userID int) (UnsuspendUserData, error)

func (*Service) UpdateRole

func (s *Service) UpdateRole(ctx context.Context, guard UpdateRoleGuard, input UpdateRoleInput) (*Role, error)

func (*Service) UpdateRoleValidate

func (s *Service) UpdateRoleValidate(guard UpdateRoleGuard, input UpdateRoleInput) (UpdateRoleData, error)

func (*Service) VerifyTOTP

func (s *Service) VerifyTOTP(ctx context.Context, guard VerifyTOTPGuard, input VerifyTOTPInput) (*User, []string, error)

func (*Service) VerifyTOTPValidate

func (s *Service) VerifyTOTPValidate(guard VerifyTOTPGuard, input VerifyTOTPInput) (VerifyTOTPData, error)

func (*Service) VerifyUser

func (s *Service) VerifyUser(ctx context.Context, input VerifyUserInput) (*User, error)

func (*Service) VerifyUserValidate

func (s *Service) VerifyUserValidate(input VerifyUserInput) (VerifyUserData, error)

type SetupTOTPData

type SetupTOTPData struct {
	UserID int
}

type SetupTOTPGuard

type SetupTOTPGuard interface {
	CanSetupTOTP(userID int) bool
}

type SignInAttemptLog

type SignInAttemptLog struct {
	aggregate.Root

	Email         string
	Attempts      int
	LastAttemptAt time.Time
}

type SignInThrottleError

type SignInThrottleError struct {
	InLast   time.Duration
	Delay    time.Duration
	UnlockAt time.Time
	UnlockIn time.Duration
}

func (SignInThrottleError) Error

func (t SignInThrottleError) Error() string

type SignInWithFacebookData

type SignInWithFacebookData struct {
	Email Email
}

type SignInWithGoogleData

type SignInWithGoogleData struct {
	Email Email
}

type SignInWithMagicLinkData

type SignInWithMagicLinkData struct {
	Email Email
}

type SignInWithPasswordData

type SignInWithPasswordData struct {
	Email    Email
	Password Password
}

type SignInWithRecoveryCodeData

type SignInWithRecoveryCodeData struct {
	UserID       int
	RecoveryCode RecoveryCode
}

type SignInWithTOTPData

type SignInWithTOTPData struct {
	UserID int
	TOTP   TOTP
}

type SignUpData

type SignUpData struct {
	Email Email
}

type SignUpInitialUserData

type SignUpInitialUserData struct {
	Email         Email
	Password      Password
	PasswordCheck Password
	RoleIDs       []int
}

type SignedIn

type SignedIn struct {
	Email  string
	System string
	Method string
}

type SignedUp

type SignedUp struct {
	Email      string
	System     string
	Method     string
	IsVerified bool
}

type SuspendUserData

type SuspendUserData struct {
	UserID          int
	SuspendedReason SuspendedReason
}

type SuspendUsersGuard

type SuspendUsersGuard interface {
	CanSuspendUsers() bool
}

type Suspended

type Suspended struct {
	Email  string
	Reason string
}

type SuspendedReason

type SuspendedReason string

func NewSuspendedReason

func NewSuspendedReason(reason string) (SuspendedReason, error)

func (SuspendedReason) String

func (s SuspendedReason) String() string

type SuspendedReasonChanged

type SuspendedReasonChanged struct {
	Email  string
	Reason string
}

type TOTP

type TOTP string

func NewTOTP

func NewTOTP(totp string) (TOTP, error)

func (TOTP) String

func (t TOTP) String() string

type TOTPDisabled

type TOTPDisabled struct {
	Email string
}

type TOTPKey

type TOTPKey struct {
	// contains filtered or unexported fields
}

func NewTOTPKey

func NewTOTPKey(algorithm otp.Algorithm) (zero TOTPKey, _ error)

type TOTPMethod

type TOTPMethod string
const (
	TOTPMethodNone TOTPMethod = ""
	TOTPMethodApp  TOTPMethod = "app"
	TOTPMethodSMS  TOTPMethod = "sms"
)

func NewTOTPMethod

func NewTOTPMethod(method string) (TOTPMethod, error)

func (TOTPMethod) String

func (t TOTPMethod) String() string

type TOTPReset

type TOTPReset struct {
	Email string
}

type TOTPResetRequestApproved

type TOTPResetRequestApproved struct {
	Email string
}

type TOTPResetRequestDenied

type TOTPResetRequestDenied struct {
	Email string
}

type TOTPResetRequested

type TOTPResetRequested struct {
	Email string
}

type TOTPTelChanged

type TOTPTelChanged struct {
	Email  string
	OldTel string
	NewTel string
}

type Tel

type Tel string

func NewTel

func NewTel(tel string) (Tel, error)

func (Tel) String

func (t Tel) String() string

type UnsuspendUserData

type UnsuspendUserData struct {
	UserID int
}

type UnsuspendUsersGuard

type UnsuspendUsersGuard interface {
	CanUnsuspendUsers() bool
}

type Unsuspended

type Unsuspended struct {
	Email string
}

type UpdateRoleData

type UpdateRoleData struct {
	RoleID      int
	Name        RoleName
	Description RoleDesc
	Permissions []Permission
}

type UpdateRoleGuard

type UpdateRoleGuard interface {
	CanUpdateRoles() bool
}

type UpdateRoleInput

type UpdateRoleInput struct {
	RoleID      int
	Name        string
	Description string
	Permissions []string
}

type User

type User struct {
	aggregate.Root

	ID                      int
	Email                   string
	HashedPassword          []byte
	TOTPMethod              string
	TOTPTel                 string
	TOTPKey                 []byte
	TOTPAlgorithm           string
	TOTPDigits              int
	TOTPPeriod              time.Duration
	TOTPVerifiedAt          time.Time
	TOTPActivatedAt         time.Time
	TOTPResetRequestedAt    time.Time
	TOTPResetApprovedAt     time.Time
	InvitedAt               time.Time
	SignedUpAt              time.Time
	SignedUpSystem          string
	SignedUpMethod          string
	VerifiedAt              time.Time
	ActivatedAt             time.Time
	LastSignInAttemptAt     time.Time
	LastSignInAttemptSystem string
	LastSignInAttemptMethod string
	LastSignedInAt          time.Time
	LastSignedInSystem      string
	LastSignedInMethod      string
	SuspendedAt             time.Time
	SuspendedReason         string
	HashedRecoveryCodes     [][]byte
	Roles                   []*Role
	Grants                  []string
	Denials                 []string
}

func NewUser

func NewUser(email Email) *User

func (*User) Activate

func (u *User) Activate() error

func (*User) ActivateTOTP

func (u *User) ActivateTOTP() error

func (*User) ApproveTOTPResetRequest

func (u *User) ApproveTOTPResetRequest() error

func (*User) ChangePassword

func (u *User) ChangePassword(oldPassword, newPassword Password, hasher Hasher) error

func (*User) ChangeRoles

func (u *User) ChangeRoles(roles []*Role, grants, denials []Permission)

func (*User) ChangeTOTPTel

func (u *User) ChangeTOTPTel(newTel Tel) error

func (*User) ChoosePassword

func (u *User) ChoosePassword(newPassword Password, hasher Hasher) error

func (*User) DenyTOTPResetRequest

func (u *User) DenyTOTPResetRequest() error

func (*User) DisableTOTP

func (u *User) DisableTOTP(password Password, hasher Hasher) error

func (*User) GenerateTOTP

func (u *User) GenerateTOTP() (string, error)

func (*User) HasActivatedTOTP

func (u *User) HasActivatedTOTP() bool

func (*User) HasSetupTOTP

func (u *User) HasSetupTOTP() bool

func (*User) HasSignedIn

func (u *User) HasSignedIn() bool

func (*User) HasVerifiedTOTP

func (u *User) HasVerifiedTOTP() bool

func (*User) Invite

func (u *User) Invite(system string) error

func (*User) IsActivated

func (u *User) IsActivated() bool

func (*User) IsSuspended

func (u *User) IsSuspended() bool

func (*User) IsVerified

func (u *User) IsVerified() bool

func (*User) Permissions

func (u *User) Permissions() []string

func (*User) RegenerateRecoveryCodes

func (u *User) RegenerateRecoveryCodes(totp TOTP) ([]string, error)

func (*User) RequestTOTPReset

func (u *User) RequestTOTPReset() error

func (*User) ResetPassword

func (u *User) ResetPassword(newPassword Password, hasher Hasher) error

func (*User) ResetTOTP

func (u *User) ResetTOTP(password Password, hasher Hasher) error

func (*User) SetupTOTP

func (u *User) SetupTOTP() error

func (*User) SignInWithFacebook

func (u *User) SignInWithFacebook(system string) error

func (*User) SignInWithGoogle

func (u *User) SignInWithGoogle(system string) error
func (u *User) SignInWithMagicLink(system string) error

func (*User) SignInWithPassword

func (u *User) SignInWithPassword(system string, password Password, hasher Hasher) (bool, error)

func (*User) SignInWithRecoveryCode

func (u *User) SignInWithRecoveryCode(system string, code RecoveryCode) error

func (*User) SignInWithTOTP

func (u *User) SignInWithTOTP(system string, totp TOTP) error

func (*User) SignUp

func (u *User) SignUp(system string)

func (*User) SignUpAsInitialUser

func (u *User) SignUpAsInitialUser(system string, roles []*Role, password Password, hasher Hasher) error

func (*User) SignUpWithFacebook

func (u *User) SignUpWithFacebook(system string)

func (*User) SignUpWithGoogle

func (u *User) SignUpWithGoogle(system string)
func (u *User) SignUpWithMagicLink(system string)

func (*User) Suspend

func (u *User) Suspend(reason SuspendedReason)

func (*User) Unsuspend

func (u *User) Unsuspend()

func (*User) Verify

func (u *User) Verify(password Password, hasher Hasher) error

func (*User) VerifyTOTP

func (u *User) VerifyTOTP(totp TOTP, method TOTPMethod) ([]string, error)

type UserFilter

type UserFilter struct {
	ID     *int
	Email  *string
	Search *string
	RoleID *int

	SortTopID int
	Sorts     []string

	Limit  int
	Offset int
}

type Verified

type Verified struct {
	Email string
}

type VerifyTOTPData

type VerifyTOTPData struct {
	UserID     int
	TOTP       TOTP
	TOTPMethod TOTPMethod
}

type VerifyTOTPGuard

type VerifyTOTPGuard interface {
	CanVerifyTOTP(userID int) bool
}

type VerifyTOTPInput

type VerifyTOTPInput struct {
	UserID     int
	TOTP       string
	TOTPMethod string
}

type VerifyUserBehavior

type VerifyUserBehavior byte
const (
	VerifyUserOnly VerifyUserBehavior = iota
	VerifyUserActivate
)

type VerifyUserData

type VerifyUserData struct {
	Email         Email
	Password      Password
	PasswordCheck Password
	Behavior      VerifyUserBehavior
}

type VerifyUserInput

type VerifyUserInput struct {
	Email         string
	Password      string
	PasswordCheck string
	Behavior      VerifyUserBehavior
}

type Writer

type Writer interface {
	AddRole(ctx context.Context, role *Role) error
	SaveRole(ctx context.Context, role *Role) error
	RemoveRole(ctx context.Context, roleID int) error

	AddUser(ctx context.Context, user *User) error
	SaveUser(ctx context.Context, user *User) error

	SaveSignInAttemptLog(ctx context.Context, log *SignInAttemptLog) error
}

Jump to

Keyboard shortcuts

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