user

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserAlreadyJoined        = errors.New("user already joined")
	ErrCannotModifyPersonalTeam = errors.New("personal team cannot be modified")
	ErrTeamWithProjects         = errors.New("target team still has some project")
	ErrTargetUserNotInTheTeam   = errors.New("target user does not exist in the team")
)
View Source
var (
	DefaultPasswordEncoder PasswordEncoder = &BcryptPasswordEncoder{}
	ErrEncodingPassword                    = errors.New("encoding password")
	ErrInvalidPassword                     = errors.New("invalid password")
	ErrPasswordLength                      = errors.New("password at least 8 characters")
	ErrPasswordUpper                       = errors.New("password should have upper case letters")
	ErrPasswordLower                       = errors.New("password should have lower case letters")
	ErrPasswordNumber                      = errors.New("password should have numbers")
)
View Source
var (
	// RoleOwner is a role who can have full controll of project
	RoleOwner = Role("owner")
	// RoleWriter is a role who can read and write project
	RoleWriter = Role("writer")
	// RoleReader is a role who can read project
	RoleReader = Role("reader")

	ErrInvalidRole = errors.New("invalid role")
)
View Source
var (
	ErrInvalidEmail = errors.New("invalid email")
)
View Source
var ErrInvalidID = id.ErrInvalidID
View Source
var GenerateVerificationCode = generateCode
View Source
var IDFrom = id.UserIDFrom
View Source
var IDFromRef = id.UserIDFromRef
View Source
var MustID = id.MustUserID
View Source
var MustTeamID = id.MustTeamID
View Source
var NewID = id.NewUserID
View Source
var NewTeamID = id.NewTeamID
View Source
var Now = time.Now
View Source
var TeamIDFrom = id.TeamIDFrom
View Source
var TeamIDFromRef = id.TeamIDFromRef

Functions

func Init

func Init(p InitParams) (*User, *Team, error)

func MockGenerateVerificationCode added in v0.6.0

func MockGenerateVerificationCode(code string) func()

func MockNow added in v0.6.0

func MockNow(t time.Time) func()

func ValidatePasswordFormat added in v0.6.0

func ValidatePasswordFormat(pass string) error

Types

type Auth

type Auth struct {
	Provider string
	Sub      string
}

func AuthFromAuth0Sub

func AuthFromAuth0Sub(sub string) Auth

func GenReearthSub added in v0.6.0

func GenReearthSub(userID string) *Auth

func (Auth) IsAuth0

func (a Auth) IsAuth0() bool

func (Auth) Ref added in v0.6.0

func (a Auth) Ref() *Auth

type BcryptPasswordEncoder added in v0.6.0

type BcryptPasswordEncoder struct{}

func (BcryptPasswordEncoder) Encode added in v0.6.0

func (BcryptPasswordEncoder) Encode(pass string) ([]byte, error)

func (BcryptPasswordEncoder) Verify added in v0.6.0

func (BcryptPasswordEncoder) Verify(s string, p []byte) (bool, error)

type Builder

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

func New

func New() *Builder

func (*Builder) Auths

func (b *Builder) Auths(auths []Auth) *Builder

func (*Builder) Build

func (b *Builder) Build() (*User, error)

func (*Builder) Email

func (b *Builder) Email(email string) *Builder

func (*Builder) EncodedPassword added in v0.6.0

func (b *Builder) EncodedPassword(p EncodedPassword) *Builder

func (*Builder) ID

func (b *Builder) ID(id ID) *Builder

func (*Builder) Lang

func (b *Builder) Lang(lang language.Tag) *Builder

func (*Builder) LangFrom

func (b *Builder) LangFrom(lang string) *Builder

func (*Builder) MustBuild

func (b *Builder) MustBuild() *User

func (*Builder) Name

func (b *Builder) Name(name string) *Builder

func (*Builder) NewID

func (b *Builder) NewID() *Builder

func (*Builder) PasswordPlainText added in v0.6.0

func (b *Builder) PasswordPlainText(p string) *Builder

func (*Builder) PasswordReset added in v0.6.0

func (b *Builder) PasswordReset(pr *PasswordReset) *Builder

func (*Builder) Team

func (b *Builder) Team(team TeamID) *Builder

func (*Builder) Theme

func (b *Builder) Theme(t Theme) *Builder

func (*Builder) Verification added in v0.6.0

func (b *Builder) Verification(v *Verification) *Builder

type EncodedPassword added in v0.6.0

type EncodedPassword []byte

func MustEncodedPassword added in v0.6.0

func MustEncodedPassword(pass string) EncodedPassword

func NewEncodedPassword added in v0.6.0

func NewEncodedPassword(pass string) (EncodedPassword, error)

func (EncodedPassword) Clone added in v0.6.0

func (p EncodedPassword) Clone() EncodedPassword

func (EncodedPassword) Verify added in v0.6.0

func (p EncodedPassword) Verify(toVerify string) (bool, error)

type ID added in v0.4.0

type ID = id.UserID

type InitParams

type InitParams struct {
	Email    string
	Name     string
	Sub      *Auth
	Password *string
	Lang     *language.Tag
	Theme    *Theme
	UserID   *ID
	TeamID   *TeamID
}

type Members

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

func CopyMembers

func CopyMembers(members *Members) *Members

func NewFixedMembers

func NewFixedMembers(u ID) *Members

func NewMembers

func NewMembers() *Members

func NewMembersWith

func NewMembersWith(members map[ID]Role) *Members

func (*Members) ContainsUser

func (m *Members) ContainsUser(u ID) bool

func (*Members) Count

func (m *Members) Count() int

func (*Members) Fixed added in v0.4.0

func (m *Members) Fixed() bool

func (*Members) GetRole

func (m *Members) GetRole(u ID) Role

func (*Members) IsOnlyOwner

func (m *Members) IsOnlyOwner(u ID) bool

func (*Members) Join

func (m *Members) Join(u ID, role Role) error

func (*Members) Leave

func (m *Members) Leave(u ID) error

func (*Members) Members

func (m *Members) Members() map[ID]Role

func (*Members) UpdateRole

func (m *Members) UpdateRole(u ID, role Role) error

func (*Members) UsersByRole

func (m *Members) UsersByRole(role Role) []ID

type MockPasswordEncoder added in v0.6.0

type MockPasswordEncoder struct{ Mock []byte }

func (MockPasswordEncoder) Encode added in v0.6.0

func (m MockPasswordEncoder) Encode(pass string) ([]byte, error)

func (MockPasswordEncoder) Verify added in v0.6.0

func (m MockPasswordEncoder) Verify(s string, p []byte) (bool, error)

type NoopPasswordEncoder added in v0.6.0

type NoopPasswordEncoder struct{}

func (NoopPasswordEncoder) Encode added in v0.6.0

func (m NoopPasswordEncoder) Encode(pass string) ([]byte, error)

func (NoopPasswordEncoder) Verify added in v0.6.0

func (m NoopPasswordEncoder) Verify(s string, p []byte) (bool, error)

type PasswordEncoder added in v0.6.0

type PasswordEncoder interface {
	Encode(string) ([]byte, error)
	Verify(string, []byte) (bool, error)
}

type PasswordReset added in v0.6.0

type PasswordReset struct {
	Token     string
	CreatedAt time.Time
}

func NewPasswordReset added in v0.6.0

func NewPasswordReset() *PasswordReset

func PasswordResetFrom added in v0.6.0

func PasswordResetFrom(token string, createdAt time.Time) *PasswordReset

func (*PasswordReset) Clone added in v0.6.0

func (pr *PasswordReset) Clone() *PasswordReset

func (*PasswordReset) Validate added in v0.6.0

func (pr *PasswordReset) Validate(token string) bool

type Role

type Role string

func RoleFromString

func RoleFromString(r string) (Role, error)

func (Role) Includes added in v0.6.0

func (r Role) Includes(role Role) bool

type Team

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

func (*Team) ID

func (t *Team) ID() TeamID

func (*Team) IsPersonal

func (t *Team) IsPersonal() bool

func (*Team) Members

func (t *Team) Members() *Members

func (*Team) Name

func (t *Team) Name() string

func (*Team) Rename

func (t *Team) Rename(name string)

type TeamBuilder

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

func NewTeam

func NewTeam() *TeamBuilder

func (*TeamBuilder) Build

func (b *TeamBuilder) Build() (*Team, error)

func (*TeamBuilder) ID

func (b *TeamBuilder) ID(id TeamID) *TeamBuilder

func (*TeamBuilder) Members

func (b *TeamBuilder) Members(members map[ID]Role) *TeamBuilder

func (*TeamBuilder) MustBuild

func (b *TeamBuilder) MustBuild() *Team

func (*TeamBuilder) Name

func (b *TeamBuilder) Name(name string) *TeamBuilder

func (*TeamBuilder) NewID

func (b *TeamBuilder) NewID() *TeamBuilder

func (*TeamBuilder) Personal

func (b *TeamBuilder) Personal(p bool) *TeamBuilder

type TeamID added in v0.4.0

type TeamID = id.TeamID

type TeamIDList added in v0.6.0

type TeamIDList = id.TeamIDList

type TeamList added in v0.6.0

type TeamList []*Team

func (TeamList) FilterByID added in v0.6.0

func (l TeamList) FilterByID(ids ...TeamID) TeamList

func (TeamList) FilterByUserRole added in v0.6.0

func (l TeamList) FilterByUserRole(u ID, r Role) TeamList

func (TeamList) FilterByUserRoleIncluding added in v0.6.0

func (l TeamList) FilterByUserRoleIncluding(u ID, r Role) TeamList

func (TeamList) IDs added in v0.6.0

func (l TeamList) IDs() []TeamID

type Theme

type Theme string
const (
	ThemeDefault Theme = "default"
	ThemeLight   Theme = "light"
	ThemeDark    Theme = "dark"
)

func (Theme) Ref added in v0.6.0

func (t Theme) Ref() *Theme

type User

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

func (*User) AddAuth

func (u *User) AddAuth(a Auth) bool

func (*User) Auths

func (u *User) Auths() []Auth

func (*User) ClearAuths

func (u *User) ClearAuths()

func (*User) ContainAuth

func (u *User) ContainAuth(a Auth) bool

func (*User) Email

func (u *User) Email() string

func (*User) GetAuthByProvider added in v0.6.0

func (u *User) GetAuthByProvider(provider string) *Auth

func (*User) HasAuthProvider added in v0.6.0

func (u *User) HasAuthProvider(p string) bool

func (*User) ID

func (u *User) ID() ID

func (*User) Lang

func (u *User) Lang() language.Tag

func (*User) MatchPassword added in v0.6.0

func (u *User) MatchPassword(pass string) (bool, error)

func (*User) Name

func (u *User) Name() string

func (*User) Password added in v0.6.0

func (u *User) Password() []byte

func (*User) PasswordReset added in v0.6.0

func (u *User) PasswordReset() *PasswordReset

func (*User) RemoveAuth

func (u *User) RemoveAuth(a Auth) bool

func (*User) RemoveAuthByProvider

func (u *User) RemoveAuthByProvider(provider string) bool

func (*User) SetPassword added in v0.6.0

func (u *User) SetPassword(pass string) error

func (*User) SetPasswordReset added in v0.6.0

func (u *User) SetPasswordReset(pr *PasswordReset)

func (*User) SetVerification added in v0.6.0

func (u *User) SetVerification(v *Verification)

func (*User) Team

func (u *User) Team() TeamID

func (*User) Theme

func (u *User) Theme() Theme

func (*User) UpdateEmail

func (u *User) UpdateEmail(email string) error

func (*User) UpdateLang

func (u *User) UpdateLang(lang language.Tag)

func (*User) UpdateName

func (u *User) UpdateName(name string)

func (*User) UpdateTeam

func (u *User) UpdateTeam(team TeamID)

func (*User) UpdateTheme

func (u *User) UpdateTheme(t Theme)

func (*User) Verification added in v0.6.0

func (u *User) Verification() *Verification

type Verification added in v0.6.0

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

func NewVerification added in v0.6.0

func NewVerification() *Verification

func VerificationFrom added in v0.6.0

func VerificationFrom(c string, e time.Time, b bool) *Verification

func (*Verification) Code added in v0.6.0

func (v *Verification) Code() string

func (*Verification) Expiration added in v0.6.0

func (v *Verification) Expiration() time.Time

func (*Verification) IsExpired added in v0.6.0

func (v *Verification) IsExpired() bool

func (*Verification) IsVerified added in v0.6.0

func (v *Verification) IsVerified() bool

func (*Verification) SetVerified added in v0.6.0

func (v *Verification) SetVerified(b bool)

Jump to

Keyboard shortcuts

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